|
|
|
@ -9,7 +9,11 @@ int Session::SendData(UNIX *u, string data) {
|
|
|
|
|
return 0;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Session::Session(int rid) {
|
|
|
|
|
mtxchanges = { 0 };
|
|
|
|
|
mtxchanges = PTHREAD_MUTEX_INITIALIZER;
|
|
|
|
|
|
|
|
|
|
sessionID = random();
|
|
|
|
|
randomID = rid;
|
|
|
|
|
changes.clear();
|
|
|
|
@ -186,7 +190,9 @@ int Session::ProcessData(JSONParse *jin, JSONParse *jout) {
|
|
|
|
|
// add chenges which need to be send to the clients
|
|
|
|
|
//
|
|
|
|
|
void Session::ChangeListPush(string chng) {
|
|
|
|
|
LockChanges();
|
|
|
|
|
changes.push_back(chng);
|
|
|
|
|
UnLockChanges();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -203,13 +209,14 @@ JSONElement Session::ChangeListGet() {
|
|
|
|
|
je.name = "changes";
|
|
|
|
|
je.value = "[";
|
|
|
|
|
|
|
|
|
|
LockChanges();
|
|
|
|
|
for (iter = changes.begin(); iter != changes.end(); iter++) {
|
|
|
|
|
if (iter != changes.begin()) je.value += ",\n ";
|
|
|
|
|
else je.value += "\n ";
|
|
|
|
|
je.value += (*iter);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
changes.clear();
|
|
|
|
|
UnLockChanges();
|
|
|
|
|
|
|
|
|
|
je.value += "]";
|
|
|
|
|
|
|
|
|
@ -241,7 +248,7 @@ void Session::AddJSONRailway(JSONParse *jp) {
|
|
|
|
|
server->RailwayChange(&r);
|
|
|
|
|
jout.Clear();
|
|
|
|
|
jout.AddObject("railway", server->RailwayGetJSONRailway(r.x, r.y));
|
|
|
|
|
if (network) network->_ChangeListPushToAll(jout.ToString());
|
|
|
|
|
if (network) network->ChangeListPushToAll(jout.ToString());
|
|
|
|
|
}
|
|
|
|
|
server->UnLockThread();
|
|
|
|
|
}
|
|
|
|
@ -268,7 +275,7 @@ void Session::DelJSONRailway(JSONParse *jp) {
|
|
|
|
|
server->RailwayChange(&r);
|
|
|
|
|
jout.Clear();
|
|
|
|
|
jout.AddObject("railway", server->RailwayGetJSONRailway(r.x, r.y));
|
|
|
|
|
if (network) network->_ChangeListPushToAll(jout.ToString());
|
|
|
|
|
if (network) network->ChangeListPushToAll(jout.ToString());
|
|
|
|
|
}
|
|
|
|
|
server->UnLockThread();
|
|
|
|
|
}
|
|
|
|
@ -292,7 +299,7 @@ void Session::AddJSONInterface(JSONParse *jp) {
|
|
|
|
|
server->InterfaceChange(&iface);
|
|
|
|
|
jout.Clear();
|
|
|
|
|
jout.AddObject("interface", server->InterfaceGetJSON(iface.name));
|
|
|
|
|
if (network) network->_ChangeListPushToAll(jout.ToString());
|
|
|
|
|
if (network) network->ChangeListPushToAll(jout.ToString());
|
|
|
|
|
}
|
|
|
|
|
server->UnLockThread();
|
|
|
|
|
};
|
|
|
|
@ -318,7 +325,7 @@ void Session::DelJSONInterface(JSONParse *jp) {
|
|
|
|
|
jout.Clear();
|
|
|
|
|
s = iface.name;
|
|
|
|
|
jout.AddObject("interfacedelete", s);
|
|
|
|
|
if (network) network->_ChangeListPushToAll(jout.ToString());
|
|
|
|
|
if (network) network->ChangeListPushToAll(jout.ToString());
|
|
|
|
|
}
|
|
|
|
|
server->UnLockThread();
|
|
|
|
|
};
|
|
|
|
@ -342,7 +349,7 @@ void Session::AddJSONSensor(JSONParse *jp) {
|
|
|
|
|
server->SensorChange(&se);
|
|
|
|
|
jout.Clear();
|
|
|
|
|
jout.AddObject("sensor", server->SensorGetJSON(se.name));
|
|
|
|
|
if (network) network->_ChangeListPushToAll(jout.ToString());
|
|
|
|
|
if (network) network->ChangeListPushToAll(jout.ToString());
|
|
|
|
|
}
|
|
|
|
|
server->UnLockThread();
|
|
|
|
|
};
|
|
|
|
@ -368,7 +375,7 @@ void Session::DelJSONSensor(JSONParse *jp) {
|
|
|
|
|
jout.Clear();
|
|
|
|
|
s = se.name;
|
|
|
|
|
jout.AddObject("sensordelete", s);
|
|
|
|
|
if (network) network->_ChangeListPushToAll(jout.ToString());
|
|
|
|
|
if (network) network->ChangeListPushToAll(jout.ToString());
|
|
|
|
|
}
|
|
|
|
|
server->UnLockThread();
|
|
|
|
|
};
|
|
|
|
@ -392,7 +399,7 @@ void Session::AddJSONLocomotive(JSONParse *jp) {
|
|
|
|
|
server->LocomotiveChange(&loco);
|
|
|
|
|
jout.Clear();
|
|
|
|
|
jout.AddObject("locomotive", server->LocomotiveGetJSON(loco.name));
|
|
|
|
|
if (network) network->_ChangeListPushToAll(jout.ToString());
|
|
|
|
|
if (network) network->ChangeListPushToAll(jout.ToString());
|
|
|
|
|
}
|
|
|
|
|
server->UnLockThread();
|
|
|
|
|
};
|
|
|
|
@ -434,7 +441,7 @@ void Session::SetJSONLocomotive(JSONParse *jp) {
|
|
|
|
|
}
|
|
|
|
|
jout.Clear();
|
|
|
|
|
jout.AddObject("locomotive", server->LocomotiveGetJSON(loconame));
|
|
|
|
|
if (network) network->_ChangeListPushToAll(jout.ToString());
|
|
|
|
|
if (network) network->ChangeListPushToAll(jout.ToString());
|
|
|
|
|
}
|
|
|
|
|
server->UnLockThread();
|
|
|
|
|
};
|
|
|
|
@ -459,7 +466,7 @@ void Session::DelJSONLocomotive(JSONParse *jp) {
|
|
|
|
|
jout.Clear();
|
|
|
|
|
s = loco.name;
|
|
|
|
|
jout.AddObject("locomotivedelete", s);
|
|
|
|
|
if (network) network->_ChangeListPushToAll(jout.ToString());
|
|
|
|
|
if (network) network->ChangeListPushToAll(jout.ToString());
|
|
|
|
|
}
|
|
|
|
|
server->UnLockThread();
|
|
|
|
|
};
|
|
|
|
@ -479,7 +486,7 @@ void Session::SetJSONLocoDest(JSONParse *jp) {
|
|
|
|
|
server->LocomotiveSetDest(loco, block, reverse);
|
|
|
|
|
jout.Clear();
|
|
|
|
|
jout.AddObject("locomotive", server->LocomotiveGetJSON(loco));
|
|
|
|
|
if (network) network->_ChangeListPushToAll(jout.ToString());
|
|
|
|
|
if (network) network->ChangeListPushToAll(jout.ToString());
|
|
|
|
|
server->UnLockThread();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -498,7 +505,7 @@ void Session::SetJSONLocoAssign(JSONParse *jp) {
|
|
|
|
|
server->LocomotiveSetAssign(loco, block, reverse);
|
|
|
|
|
jout.Clear();
|
|
|
|
|
jout.AddObject("locomotive", server->LocomotiveGetJSON(loco));
|
|
|
|
|
if (network) network->_ChangeListPushToAll(jout.ToString());
|
|
|
|
|
if (network) network->ChangeListPushToAll(jout.ToString());
|
|
|
|
|
server->UnLockThread();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -514,7 +521,7 @@ void Session::SetJSONLocoReset(JSONParse *jp) {
|
|
|
|
|
server->LocomotiveReset(loco);
|
|
|
|
|
jout.Clear();
|
|
|
|
|
jout.AddObject("locomotive", server->LocomotiveGetJSON(loco));
|
|
|
|
|
if (network) network->_ChangeListPushToAll(jout.ToString());
|
|
|
|
|
if (network) network->ChangeListPushToAll(jout.ToString());
|
|
|
|
|
server->UnLockThread();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -528,7 +535,7 @@ void Session::SetJSONLocoMan(JSONParse *jp) {
|
|
|
|
|
server->LocomotiveSetMan(loco);
|
|
|
|
|
jout.Clear();
|
|
|
|
|
jout.AddObject("locomotive", server->LocomotiveGetJSON(loco));
|
|
|
|
|
if (network) network->_ChangeListPushToAll(jout.ToString());
|
|
|
|
|
if (network) network->ChangeListPushToAll(jout.ToString());
|
|
|
|
|
server->UnLockThread();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -542,7 +549,7 @@ void Session::SetJSONLocoAutoMan(JSONParse *jp) {
|
|
|
|
|
server->LocomotiveSetAutoMan(loco);
|
|
|
|
|
jout.Clear();
|
|
|
|
|
jout.AddObject("locomotive", server->LocomotiveGetJSON(loco));
|
|
|
|
|
if (network) network->_ChangeListPushToAll(jout.ToString());
|
|
|
|
|
if (network) network->ChangeListPushToAll(jout.ToString());
|
|
|
|
|
server->UnLockThread();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -556,7 +563,7 @@ void Session::SetJSONLocoAuto(JSONParse *jp) {
|
|
|
|
|
server->LocomotiveSetAuto(loco);
|
|
|
|
|
jout.Clear();
|
|
|
|
|
jout.AddObject("locomotive", server->LocomotiveGetJSON(loco));
|
|
|
|
|
if (network) network->_ChangeListPushToAll(jout.ToString());
|
|
|
|
|
if (network) network->ChangeListPushToAll(jout.ToString());
|
|
|
|
|
server->UnLockThread();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -570,7 +577,7 @@ void Session::SetJSONLocoAutoRand(JSONParse *jp) {
|
|
|
|
|
server->LocomotiveSetAutoRand(loco);
|
|
|
|
|
jout.Clear();
|
|
|
|
|
jout.AddObject("locomotive", server->LocomotiveGetJSON(loco));
|
|
|
|
|
if (network) network->_ChangeListPushToAll(jout.ToString());
|
|
|
|
|
if (network) network->ChangeListPushToAll(jout.ToString());
|
|
|
|
|
server->UnLockThread();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
@ -594,7 +601,7 @@ void Session::AddJSONTurnout(JSONParse *jp) {
|
|
|
|
|
server->TurnoutChange(&to);
|
|
|
|
|
jout.Clear();
|
|
|
|
|
jout.AddObject("turnout", server->TurnoutGetJSON(to.name));
|
|
|
|
|
if (network) network->_ChangeListPushToAll(jout.ToString());
|
|
|
|
|
if (network) network->ChangeListPushToAll(jout.ToString());
|
|
|
|
|
}
|
|
|
|
|
server->UnLockThread();
|
|
|
|
|
};
|
|
|
|
@ -620,7 +627,7 @@ void Session::DelJSONTurnout(JSONParse *jp) {
|
|
|
|
|
jout.Clear();
|
|
|
|
|
s = to.name;
|
|
|
|
|
jout.AddObject("turnoutdelete", s);
|
|
|
|
|
if (network) network->_ChangeListPushToAll(jout.ToString());
|
|
|
|
|
if (network) network->ChangeListPushToAll(jout.ToString());
|
|
|
|
|
}
|
|
|
|
|
server->UnLockThread();
|
|
|
|
|
};
|
|
|
|
@ -646,7 +653,7 @@ void Session::SetJSONTurnout(JSONParse *jp) {
|
|
|
|
|
server->TurnoutSet(name, active);
|
|
|
|
|
jout.Clear();
|
|
|
|
|
jout.AddObject("turnout", server->TurnoutGetJSON(name));
|
|
|
|
|
if (network) network->_ChangeListPushToAll(jout.ToString());
|
|
|
|
|
if (network) network->ChangeListPushToAll(jout.ToString());
|
|
|
|
|
}
|
|
|
|
|
server->UnLockThread();
|
|
|
|
|
};
|
|
|
|
@ -670,7 +677,7 @@ void Session::AddJSONBlock(JSONParse *jp) {
|
|
|
|
|
server->BlockChange(&bl);
|
|
|
|
|
jout.Clear();
|
|
|
|
|
jout.AddObject("block", server->BlockGetJSON(bl.name));
|
|
|
|
|
if (network) network->_ChangeListPushToAll(jout.ToString());
|
|
|
|
|
if (network) network->ChangeListPushToAll(jout.ToString());
|
|
|
|
|
}
|
|
|
|
|
server->UnLockThread();
|
|
|
|
|
};
|
|
|
|
@ -696,7 +703,7 @@ void Session::DelJSONBlock(JSONParse *jp) {
|
|
|
|
|
jout.Clear();
|
|
|
|
|
s = bl.name;
|
|
|
|
|
jout.AddObject("blockdelete", s);
|
|
|
|
|
if (network) network->_ChangeListPushToAll(jout.ToString());
|
|
|
|
|
if (network) network->ChangeListPushToAll(jout.ToString());
|
|
|
|
|
}
|
|
|
|
|
server->UnLockThread();
|
|
|
|
|
};
|
|
|
|
@ -712,7 +719,7 @@ void Session::BlockJSONOff(JSONParse *jp) {
|
|
|
|
|
|
|
|
|
|
jout.Clear();
|
|
|
|
|
jout.AddObject("block", server->BlockGetJSON(name));
|
|
|
|
|
if (network) network->_ChangeListPushToAll(jout.ToString());
|
|
|
|
|
if (network) network->ChangeListPushToAll(jout.ToString());
|
|
|
|
|
|
|
|
|
|
server->UnLockThread();
|
|
|
|
|
};
|
|
|
|
@ -727,7 +734,7 @@ void Session::BlockJSONClear(JSONParse *jp) {
|
|
|
|
|
|
|
|
|
|
jout.Clear();
|
|
|
|
|
jout.AddObject("block", server->BlockGetJSON(name));
|
|
|
|
|
if (network) network->_ChangeListPushToAll(jout.ToString());
|
|
|
|
|
if (network) network->ChangeListPushToAll(jout.ToString());
|
|
|
|
|
|
|
|
|
|
server->UnLockThread();
|
|
|
|
|
};
|
|
|
|
|