OSDN Git Service

61ff77c69f399805c1a7e05a32da60cb2b4e2116
[pg-rex/syncrep.git] / src / corba / server.cc
1 #include <iostream>
2 #include "pgsql_int.h"
3
4 bool terminate = false;
5
6 int main(int argc, char *argv)
7 {
8         CORBA::ORB_var orb = CORBA::ORB_init(argc,argv,"");
9         PortableManager::POA_var poa = PortableServer::POA::_narrow(orb->resolve_initial_references("RootPOA"));
10         PortableManager::POAManager_var mgr = poa->the_POAManager();
11
12         Server_impl *server = new Server_impl;
13         poa->activate_object(server);
14
15         CosNaming::NamingContext_var ctx = CosNaming::NamingContext::_narrow(orb->resolve_initial_references("NamingService"));
16         CosNaming::Name_var n = new CosNaming::Name(1);
17         n[0].id("PostgreSQL");
18         n[0].name("service");
19         bool bindok = false;
20
21         if (!CORBA::Object::is_nil(ctx)) {
22                 try {
23                         CosNaming::NamingContext_var myctx = ctx->bind_new_context(n);
24                         CosNaming::Name_var n2 = new CosNaming::Name(1);
25                         n2[0].id("Server");
26                         n2[0].name("Server");
27                         myctx->bind(n2,server->_this());
28                         bindok = true;
29                 } catch (CORBA::Exception &e) {
30                         cerr << "Warning: Naming Service bind failed" << endl;
31                         bindok = false;
32                 }
33         } else {
34                 cerr << "Warning: Naming Service not found" << endl;
35         }
36
37         mgr->activate();
38         while (!terminate) {
39                 if (orb->work_pending())
40                         orb->perform_work();
41                 if (expiry_needed())
42                         expire_now();
43         }
44
45         if (!CORBA::Object::is_nil(ctx) && bindok) {
46                 try {
47                         CosNaming::NamingContext myctx = ctx->resolve(n);
48                         ctx->unbind(n);
49                         myctx->destroy();
50                 } catch (CORBA::Exception &e) {
51                         cerr << "Warning: Naming Service unbind failed" << endl;
52                 }
53         }
54
55         orb->shutdown(true);
56
57         delete server;
58         return 0;
59 }