#include #include "temp.h" #include #include #include #include #include "RMIRegistry.h" #include "RMIRegistry.C" #include "GramServer.h" #include "BindObject.h" #include void printCopyright() { cout << endl; cout <<"===========================================" << endl; cout <<"== CAT GRAM Server v0.4" << endl; cout <<"== Copyright © 1998-1999 Indiana University " << endl; cout <<"== All rights reserved." << endl; cout <<"==========================================="<< endl << endl; } void parseInputAndBind(int argc, char **argv) { void bindToTheRegistry(char *, char *, int); unsigned short PORT = 1989; // DEFAULT PORT IN THE CAT // int lengthOfName=100; // char *tempHostName = (char*)malloc(100*sizeof(char)); // int err = gethostname(tempHostName, lengthOfName); // if (err){ // printf("\n GramServer : parseInput(): Error ... gethostname() failed ... exiting \n"); // exit(EXIT_FAILURE); // } // char *registryHost = strdup(tempHostName); // free(tempHostName); // Get the complete host name struct utsname mUName; struct hostent* phostInfo; char* hostName; int error = uname(&mUName); if (error == -1) { printf("\n Error trying to get the host name !!! \n"); } else { phostInfo = gethostbyname(mUName.nodename); hostName = phostInfo->h_name; } char *registryHost = strdup(hostName); // Get the time since 1970 ... struct timeval t1; // second param is actually void* gettimeofday(&t1, &t1); // Get the name of the user char *userHome = strdup(getenv ("USER")); char *nameToBindAs = (char *)(malloc(100*sizeof(char))); sprintf(nameToBindAs, "%s%s%s%s%s%s%ld","GramServer", "-", userHome, "@", hostName, "-", t1.tv_usec); // printf("\n Unique name to bind is %s", nameToBindAs); if (argc == 1) { cout << "GramServer : Using Default Parameters" << endl; cout << "\tGramServer : registryHost: " << registryHost << endl; cout << "\tGramServer : PORT: " << PORT << endl; cout << "\tGramServer : nameToBindAs: " << nameToBindAs << endl; } else if (argc == 2) { registryHost = strdup(argv[1]); cout << "GramServer : Using Default Parameter for PORT and Name" << endl; cout << "GramServer : registryHost \t" << registryHost <" << endl; cout << "GramServer " << endl; cout << "GramServer " << endl; cout << "If host name is not provided, the local host is assumed " << endl; cout << "GramServer : Error ... exiting " << endl << endl; exit(EXIT_FAILURE); } cout << "GramServer : Using: " << registryHost << " " << PORT << " " << nameToBindAs << endl; bindToTheRegistry(registryHost, nameToBindAs, PORT); } void bindToTheRegistry(char *registryHost, char *serverName, int PORT) { printf("GramServer-->Main: creating global pointer to \"GramServer\" object\n"); fflush(stdout); GramServer *gramServerLocal = new GramServer(); HPCxx_GlobalPtr gpGramServer(gramServerLocal); printf("GramServer-->Main: global pointer to \"GramServer\" object created\n"); fflush(stdout); //Get the startpoint of the RMIregistry printf("GramServer-->Main(): attempting RMIRegistry->attachToRegistry() \n"); fflush(stdout); RMIRegistry *rmiRegistry = new RMIRegistry(); rmiRegistry->attachToRegistry(registryHost, PORT); printf("GramServer-->Main(): RMIRegistry->attachToRegistry() succeeded \n"); fflush(stdout); // register "GramServer" in registry printf("GramServer--> : calling rebindRegistry() to register ..\n"); printf("GramServer--> : rebinding \"GramServer\" at rmi://%s:%hu/%s\n", registryHost, PORT, serverName); fflush(stdout); char *service = (char *)malloc(sizeof(char)*100); sprintf(service, "rmi://%s:%hu/%s", registryHost, PORT, serverName); HPCxx_String rmiURL(service); cout << "RMIRegistry service requested at " << rmiURL << endl << endl; HPCxx_String FQN("dpsecat.cd.HPCxxGRAM"); rmiRegistry->rebindRegistry(gpGramServer, service, FQN); free(serverName); free(registryHost); } void waitToBeKilled() { HPCxx_Sync waitForUserToKill; int killMe = waitForUserToKill; } int main(int argc, char **argv) { printCopyright(); parseInputAndBind(argc, argv); waitToBeKilled(); }