// Gets Called in a thread void ServerManager::threadNewConnection(int clientID) { string initMsgBuff; string cmdName; Command* tempCmd; Client * newClient = cm->findClientByID(clientID); bool success = false; cout << " and new connection thread found " << newClient->getSocketID() << endl; while (!mtx.try_lock()) { // Keep Trying! } // Mutex is Locked // Receive Login or NewAccount initMsgBuff = newClient->getSocket().Receive(); // initMsgBuff = "Login Todd Password 127.0.0.1"; // Build Command for either if (initMsgBuff.find("Login") != std::string::npos) { tempCmd = (*cmdMap)["Login"]->Clone(); } //else if (initMsgBuff.find("NewAccount") != std::string::npos) { // tempCmd = (*cmdMap)["NewAccount"]->Clone(); //} else { tempCmd = (*cmdMap)["NewAccount"]->Clone(); } tempCmd->Initialize(initMsgBuff); success = tempCmd->Execute(); // Send Result? Or have the Command return the result delete tempCmd; // LoginCheck::Execute() will find initMsgType from initMsgBuff tempCmd = (*cmdMap)["LoginCheck"]->Clone(); tempCmd->GetClient(newClient); if (success) { tempCmd->Initialize(initMsgBuff + " 1"); // Acquire the Client acquireClient(*newClient); } else { tempCmd->Initialize(initMsgBuff + " 0"); } tempCmd->Execute(); // Unlock ServerManager Data cout << "Finished handling new Connection!" << endl; mtx.unlock(); }
void ServerManager::checkInSet(HaxorSocket * thisSocket) { #ifdef __linux__ Command * myCommand; string inMsg; string commandName; int sockID;//thisSocket->GetID(); Client * thisClient; //cm->findClientByID(sockID); if (thisSocket->IsSet()) { sockID = thisSocket->GetID(); thisClient = cm->findClientByID(sockID); if (FD_ISSET(sockID, &inSet)) { inMsg = GetMsgFromSocket(*thisSocket); commandName = inMsg.at(0); auto search = cmdMap->find(commandName); if (search != cmdMap->end()) { myCommand = (*cmdMap)[commandName]->Clone(); myCommand->GetClient(thisClient); myCommand->Initialize(inMsg); inBox.push_back(myCommand); } } } #endif }
int main(int argc, char* argv[]) { cout << argc << endl; for (int h = 0; h<argc; h++) cout << argv[h] << endl; cout << endl; Recorder* rec = Recorder::GetInstance(); //One of each device TestDevice* dev = new TestDevice("dev"); Relay* rel = new Relay(); SpeedController* ctrl = new SpeedController(); Servo* serv = new Servo(); DoubleSolenoid* ds = new DoubleSolenoid(); Solenoid* sol = new Solenoid(); //Add all devices to recorder rec->AddDevice("Relay",rel); rec->AddDevice("Speed Controller",ctrl); rec->AddDevice("Servo",serv); rec->AddDevice("Double Solenoid",ds); rec->AddDevice("Solenoid",sol); rec->AddDevice(dev); //Creates macro cout << dev->GetName() << endl; Macro* mac = rec -> macro(); int iterations = 5; for (int i = 0; i<iterations; i++) { mac->Record(); } mac->WriteFile("auto.csv"); mac->Reset(); mac->ReadFile("auto.csv"); while (!mac->IsFinished()) { mac->PlayBack(); } cout << "plz work" << endl; mac->Reset(); Command* recCom = mac->NewRecordFileCommand("auto2.csv"); recCom->Initialize(); for (int i = 0; i < 30; i ++) recCom->Execute(); recCom->End(); return 0; }