#include #include "templ.h" #include #include #include "globus_toolkit.h" #include "../GramServer/Server.h" // The host and the port on which the server is running. char *serverHost; int serverPort; // Make sure that the command line arguments are correctly passed on by the // user, and then extract them. void parseArguments(int argc, char ** argv) { const int maxLengthOfName = 100; char localHostName [maxLengthOfName]; if ( gethostname(localHostName, maxLengthOfName) ) { cout << "Error ... gethostname() failed ... exiting \n"; exit(EXIT_FAILURE); } cout << "GramClient is running on: " << localHostName << endl; if (argc != 3) { cout << "Please check your command line arguments\n" << "GramClient \n" << "... Exiting ...\n"; exit(EXIT_FAILURE); } serverHost = strdup(argv[1]); serverPort = atoi(argv[2]); } static HPCxx_Group *group; int main(int argc, char **argv) { int error; // Every HPC++ context (not created by hpcxx_createContext) calls this // function to initialize. Must be called only once in a context. hpcxx_init(argc, argv, group); // Make sure that the arguments are OK and extract the server host and port // from them. parseArguments(argc, argv); // Register all the remote functions that will be invoked on the server Server::registerAll(); // Attach to (i.e. grab) the server context. If successful, this call // returns a HPCxx_ContextID for the server ocntext. HPCxx_ContextID serverCID; if ( error = hpcxx_grabContext(&serverCID, serverHost, serverPort) ) { cout << "Client :: Error: hpcxx_grabContext failed with error: " << error << endl << flush; hpcxx_exit(); } cout << "Client :: Successfully attached to the server context\n"; // To hold a global pointer to the server object HPCxx_GlobalPtr serverGp; // Invoke returnServerGp, // Notice that when making a remote invocation using a contextId, you use // hpcxx_invoke, while for that usin a GP, you use hpcxx_minvoke, which is // ^^^ ^^^^ // illustrated later. hpcxx_invoke(serverCID, serverGp, RETURN_SERVER_GP_ID); cout << "Client :: returnServerGp successful\n"; // Invoke the sayHello() method on the server HPCxx_String returnString; HPCxx_String argumentString("helloWorld from Client"); cout << "Client :: Invoking sayHello() on server " << endl; // As mentioned earlier, for remote request using a global pointer, use // hpcxx_minvoke. hpcxx_minvoke(&serverGp, returnString, SAY_HELLO_ID, argumentString); cout << "Client :: Server replied : " << returnString << endl; cout << "Client :: Invoking killMe on server " << endl; // Kill the server by calling killMe on it. It returns some dummy value // back to the client. int x; hpcxx_minvoke(&serverGp, x, KILL_ME_ID); cout << "Client :: return value from killMe = " << x << endl; // Get rid of the context ID and the global pointer for the server context hpcxx_destroyContextID(&serverCID); hpcxx_destroyContextID(serverGp.getContextID()); // Wait for a few seconds for the connections to really get cut. sleep(5); // Call this before exiting. Used for cleanup. hpcxx_exit(); }