~ubuntu-branches/ubuntu/oneiric/libpgjava/oneiric

« back to all changes in this revision

Viewing changes to src/corba/server.cc

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Vandyck
  • Date: 2005-04-21 14:25:11 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050421142511-wibh5vc31fkrorx7
Tags: 7.4.7-3
Built with sources...

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
}