/* * mainClientRMPA.cpp * * Gouverneur Th. - Cuisinier Gi. * * Main function&calls for the Administration-RMP * client. */ #include #include #include #include #include #include using namespace std; #ifdef TRU64 extern "C" { #endif void Handler (int ); int Arme (int, void (*)(int)); #ifdef TRU64 } #endif Sock_Client *client; int main(void) { std::string login, pass; cout << "Welcome in Inpres-Hollyday C++ RMPA Client." << endl; // cout << endl << "Login: "; cin >> login; // cout << "Password: "; cin >> pass; try { client = new Sock_Client(ADDRESS_REMOT, PORT_ADMIN); client->addCommand(Command("LCLIENTS", (void(*)(void*))RMPAClientProtocol::cmdLClients, 1)); client->addCommand(Command("SUSPS", (void(*)(void*))RMPAClientProtocol::cmdSusps, 5)); client->addCommand(Command("STOPS", (void(*)(void*))RMPAClientProtocol::cmdStops, 2)); client->start(); Arme(SIGINT, Handler); // handle ctrl+c and clean propertly /* try to get authentificated */ /* Message m; m.numRequest = client->getMsgSent() + 1; m.ident = "Hotel California"; m.token = "LOGIN"; // login first m.args.Push(login); m.args.Push(pass); *client << m.serialize(); // send it through ! ClientProtocol::waiting = true; */ while(1) { //if (ClientProtocol::auth && !ClientProtocol::waiting) if (!RMPAClientProtocol::waiting) { /* print menu and wait for user-input, * this will block all socket operation * and read will be delayed until next * user-action, in this protocol implementation, * we don't care of this, cause all request are * client-based. */ cout << endl << endl << "Menu: " << endl << "-----" << endl << endl; cout << "1. List clients." << endl; cout << "2. Suspend/restart Server." << endl; cout << "3. Stop server." << endl; cout << "4. Exit." << endl; cout << "\tYour choice: "; int c; cin >> c; cout << endl << endl; if (RMPAClientProtocol::execOption(c, client)) // we should wait for an answer... RMPAClientProtocol::waiting = true; } client->evolve(); } } catch (Exception e) { cout << e << endl; } } #ifdef TRU64 extern "C" { #endif int Arme (int s, void (*f)(int)) { struct sigaction a; a.sa_flags = 0; a.sa_handler = f; return sigaction(s, &a, NULL); } void Handler (int s) { if (client) client->stop(); exit(0); } #ifdef TRU64 } #endif