Merge branch 'development' into LTS_development

# Conflicts:
#	CMakeLists.txt
#	src/controller/controller_connectors.cpp
This commit is contained in:
Thulinma 2017-01-02 12:14:16 +01:00
commit bd6034828f
8 changed files with 579 additions and 4 deletions

View file

@ -105,6 +105,7 @@ void statusMonitor(void * np){
unsigned long updatechecker = Util::epoch(); /*LTS*/
#endif
IPC::semaphore configLock(SEM_CONF, O_CREAT | O_RDWR, ACCESSPERMS, 1);
Controller::loadActiveConnectors();
while (Controller::conf.is_active){
/*LTS-START*/
#ifdef UPDATER
@ -136,7 +137,12 @@ void statusMonitor(void * np){
Controller::configChanged = false;
}
}
Util::wait(5000);//wait at least 5 seconds
Util::sleep(5000);//wait at least 5 seconds
}
if (Controller::restarting){
Controller::prepareActiveConnectorsForReload();
}else{
Controller::prepareActiveConnectorsForShutdown();
}
configLock.unlink();
}

View file

@ -11,6 +11,8 @@
#include "controller_storage.h"
#include "controller_connectors.h"
#include <mist/triggers.h>
#include <mist/shared_memory.h>
#include <mist/util.h>
#include <iostream>
#include <unistd.h>
@ -21,6 +23,61 @@ namespace Controller {
static std::map<std::string, pid_t> currentConnectors; ///<The currently running connectors.
/// Updates the shared memory page with active connectors
void saveActiveConnectors(){
IPC::sharedPage f("MstCnns", 4096, true, false);
if (!f.mapped){
FAIL_MSG("Could not store connector data!");
return;
}
memset(f.mapped, 0, 32);
Util::RelAccX A(f.mapped, false);
A.addField("cmd", RAX_128STRING);
A.addField("pid", RAX_64UINT);
A.setReady();
uint32_t count = 0;
std::map<std::string, pid_t>::iterator it;
for (it = currentConnectors.begin(); it != currentConnectors.end(); ++it){
A.setString("cmd", it->first, count);
A.setInt("pid", it->second, count);
++count;
}
A.setRCount(count);
f.master = false;//Keep the shm page around, don't kill it
}
/// Reads active connectors from the shared memory pages
void loadActiveConnectors(){
IPC::sharedPage f("MstCnns", 4096, false, false);
const Util::RelAccX A(f.mapped, false);
if (A.isReady()){
for (uint32_t i = 0; i < A.getRCount(); ++i){
char * p = A.getPointer("cmd", i);
if (p != 0 && p[0] != 0){
currentConnectors[p] = A.getInt("pid", i);
Util::Procs::remember(A.getInt("pid", i));
}
}
}
}
/// Deletes the shared memory page with connector information
/// in preparation of shutdown.
void prepareActiveConnectorsForShutdown(){
IPC::sharedPage f("MstCnns", 4096, true, false);
}
/// Forgets all active connectors, preventing them from being killed,
/// in preparation of reload.
void prepareActiveConnectorsForReload(){
saveActiveConnectors();
std::map<std::string, pid_t>::iterator it;
for (it = currentConnectors.begin(); it != currentConnectors.end(); ++it){
Util::Procs::forget(it->second);
}
currentConnectors.clear();
}
///\brief Checks if the binary mentioned in the protocol argument is currently active, if so, restarts it.
///\param protocol The protocol to check.
void UpdateProtocol(std::string protocol){
@ -184,6 +241,7 @@ namespace Controller {
}
runningConns.erase(runningConns.begin());
}
if (action){saveActiveConnectors();}
return action;
}

View file

@ -8,4 +8,20 @@ namespace Controller {
/// Checks current protocol configuration, updates state of enabled connectors if neccesary.
bool CheckProtocols(JSON::Value & p, const JSON::Value & capabilities);
/// Updates the shared memory page with active connectors
void saveActiveConnectors();
/// Reads active connectors from the shared memory pages
void loadActiveConnectors();
/// Deletes the shared memory page with connector information
/// in preparation of shutdown.
void prepareActiveConnectorsForShutdown();
/// Forgets all active connectors, preventing them from being killed,
/// in preparation of reload.
void prepareActiveConnectorsForReload();
}