Line data Source code
1 : /* 2 : * Copyright (c) 2013 Juniper Networks, Inc. All rights reserved. 3 : * Copyright Contributors to the OpenSDN project 4 : */ 5 : 6 : #ifndef ctrlplane_misc_utils_h 7 : #define ctrlplane_misc_utils_h 8 : 9 : #include <sandesh/sandesh_trace.h> 10 : #include <sandesh/common/vns_types.h> 11 : #include <sandesh/common/vns_constants.h> 12 : #include <string> 13 : #include <vector> 14 : #include <map> 15 : #include <ctime> 16 : 17 : #define VERSION_TRACE_BUF "VersionTrace" 18 : 19 : extern SandeshTraceBufferPtr VersionTraceBuf; 20 : 21 : #define VERSION_TRACE(obj, ...) do { \ 22 : obj::TraceMsg(VersionTraceBuf, __FILE__, __LINE__, ##__VA_ARGS__); \ 23 : } while (false) 24 : 25 : #define VERSION_LOG(obj, categ, ...)\ 26 : do {\ 27 : obj::Send(g_vns_constants.CategoryNames.find(categ)->second,\ 28 : SandeshLevel::SYS_INFO, __FILE__, __LINE__, ##__VA_ARGS__);\ 29 : } while (false) 30 : 31 : #if (__cplusplus < 201103L) 32 : #define ARRAYBYTES_FILL(obj, val) (obj).assign((val)); 33 : #define GENERIC_RAW_ARRAY(obj) obj.c_array() 34 : #else 35 : #define ARRAYBYTES_FILL(obj, val) (obj).fill((val)); 36 : #define GENERIC_RAW_ARRAY(obj) obj.data() 37 : #endif 38 : 39 : 40 : class MiscUtils { 41 : public: 42 : enum BuildModule { 43 : Agent, 44 : Analytics, 45 : ControlNode, 46 : Dns, 47 : MaxModules 48 : }; 49 216 : static std::map<BuildModule, std::string> MapInit() { 50 216 : std::map<BuildModule, std::string> m; 51 216 : m[Agent] = "contrail-vrouter-agent "; 52 216 : m[Analytics] = "contrail-analytics "; 53 216 : m[ControlNode] = "contrail-control "; 54 216 : m[Dns] = "contrail-dns "; 55 216 : return m; 56 0 : } 57 : static const std::map<BuildModule, std::string> BuildModuleNames; 58 : typedef std::multimap<std::time_t, std::string> FileMMap; 59 : static const std::string ContrailVersionCmd; 60 : static const std::string CoreFileDir; 61 : static const int MaxCoreFiles; 62 : 63 : static void GetHostIp(const std::string name, std::vector<std::string> &ip_list); 64 : static void LogVersionInfo(const std::string str, Category::type categ); 65 : static time_t GetUpTimeSeconds(); 66 : static time_t set_startup_time_secs(); 67 : 68 : private: 69 : static std::string BaseName(std::string filename); 70 : static time_t startup_time_secs_; 71 : }; 72 : 73 : #endif // ctrlplane_misc_utils_h