/** * @file HelloWorldServer.c * * Starts a server and instantiates a HelloWorld_Greetings object. */ #include #include "VMCFCoreImpl.h" #include "HelloWorldImpl.h" int main(int argc, char **argv) { CORBA_Environment lenv = { CORBA_NO_EXCEPTION }; VMCFServer server = NULL; HelloWorld_Greetings obj = CORBA_OBJECT_NIL; CORBA_boolean bind; CORBA_string ior; char ans[4]; if (argc < 2) { fprintf(stderr, "Syntax: %s [--bind]\n" "Where:\n" "- is of one of the forms:\n" " 'corbaloc:iiop::'\n" " 'corbaloc:viop::'\n\n" "- The optional argument '--bind' specifies that this server\n" " should create a named object ('HelloWorld') which may be\n" " accessed by a client using a corbaloc URL.\n" " If the '--bind' argument is not present, the server will\n" " generate an anonymous object with a randomly generated name,\n" " which the client may only access by using the IOR string.\n\n" " Note that the server exits when the user types in 'q',\n" " so the process (reading from 'stdin') should not be run\n" " in the background; otherwise, it will be suspended.\n\n", *argv); return 1; } if (argc > 2 && !strcmp(*(argv+2), "--bind")) { bind = CORBA_TRUE; } else { bind = CORBA_FALSE; } /* One-time initialization of the runtime. */ if (!VMCFCoreImpl_init(CORBA_FALSE, NULL)) { fprintf(stderr, "VMCFCoreImpl_init failed\n"); return 2; } do { /* Create a server on which to instantiate object(s). */ server = VMCFCoreImpl_createServer(*(argv+1), NULL, &lenv); if (!server || VMCF_EXCEPTION_RAISED(&lenv)) { break; } /* Instantiate a HelloWorld_Greetings object. */ obj = HelloWorld_GreetingsImpl_create("HelloWorld", server, bind, CORBA_OBJECT_NIL, &lenv); VMCF_BREAK_ON_EXCEPTION(&lenv); /* Initialize the object. */ HelloWorld_GreetingsImpl_init(obj, CORBA_TRUE, &lenv); VMCF_BREAK_ON_EXCEPTION(&lenv); /* Print out the object's IOR. */ ior = CORBA_ORB_object_to_string(VMCFCoreImpl_getORB(), obj, &lenv); VMCF_BREAK_ON_EXCEPTION(&lenv); printf("\n%s\n\n", ior); fflush(stdout); /* Read stdin, quit the program if necessary. */ while (1) { fgets(ans, sizeof ans, stdin); if (ans[0] == 'q' || ans[0] == 'Q') { /* Properly release the object. */ CORBA_Object_release(obj, &lenv); CORBA_exception_free(&lenv); printf("Exit\n"); break; } } } while (0); if (VMCF_EXCEPTION_RAISED(&lenv)) { fprintf(stderr, "Exception raised: %s\n", CORBA_exception_id(&lenv)); CORBA_exception_free(&lenv); } if (server) { /* Properly close the server. */ VMCFCoreImpl_closeServer(server, &lenv); CORBA_exception_free(&lenv); } return 0; }