Added instance ID

This commit is contained in:
Thulinma 2017-05-08 15:16:07 +02:00
parent 8c3fb6b88d
commit 04e0dfeab0
4 changed files with 11 additions and 0 deletions

View file

@ -286,6 +286,14 @@ int main_loop(int argc, char ** argv){
Controller::Log("CONF", "Controller started");
Controller::conf.activate();//activate early, so threads aren't killed.
//Generate instanceId once per boot.
if (Controller::instanceId == ""){
srand(time(NULL));
do{
Controller::instanceId += (char)(64 + rand() % 62);
}while(Controller::instanceId.size() < 16);
}
//start stats thread
tthread::thread statsThread(Controller::SharedMemStats, &Controller::conf);

View file

@ -351,6 +351,7 @@ void Controller::handleAPICommands(JSON::Value & Request, JSON::Value & Response
//sent current configuration, if not minimal or was changed/requested
if (!Request.isMember("minimal") || Request.isMember("config")){
Response["config"] = Controller::Storage["config"];
Response["config"]["iid"] = instanceId;
Response["config"]["version"] = PACKAGE_VERSION;
//add required data to the current unix time to the config, for syncing reasons
Response["config"]["time"] = Util::epoch();

View file

@ -10,6 +10,7 @@
///\brief Holds everything unique to the controller.
namespace Controller {
std::string instanceId; /// instanceId (previously uniqId) is set in controller.cpp
Util::Config conf;
JSON::Value Storage; ///< Global storage of data.

View file

@ -4,6 +4,7 @@
#include <mist/tinythread.h>
namespace Controller {
extern std::string instanceId; ///<global storage of instanceId (previously uniqID) is set in controller.cpp
extern Util::Config conf;///< Global storage of configuration.
extern JSON::Value Storage; ///< Global storage of data.
extern tthread::mutex logMutex;///< Mutex for log thread.