aboutsummaryrefslogtreecommitdiff
path: root/src/corba/server.cc
blob: 61ff77c69f399805c1a7e05a32da60cb2b4e2116 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#include <iostream>
#include "pgsql_int.h"

bool terminate = false;

int main(int argc, char *argv)
{
	CORBA::ORB_var orb = CORBA::ORB_init(argc,argv,"");
	PortableManager::POA_var poa = PortableServer::POA::_narrow(orb->resolve_initial_references("RootPOA"));
	PortableManager::POAManager_var mgr = poa->the_POAManager();

	Server_impl *server = new Server_impl;
	poa->activate_object(server);

	CosNaming::NamingContext_var ctx = CosNaming::NamingContext::_narrow(orb->resolve_initial_references("NamingService"));
	CosNaming::Name_var n = new CosNaming::Name(1);
	n[0].id("PostgreSQL");
	n[0].name("service");
	bool bindok = false;

	if (!CORBA::Object::is_nil(ctx)) {
		try {
			CosNaming::NamingContext_var myctx = ctx->bind_new_context(n);
			CosNaming::Name_var n2 = new CosNaming::Name(1);
			n2[0].id("Server");
			n2[0].name("Server");
			myctx->bind(n2,server->_this());
			bindok = true;
		} catch (CORBA::Exception &e) {
			cerr << "Warning: Naming Service bind failed" << endl;
			bindok = false;
		}
	} else {
		cerr << "Warning: Naming Service not found" << endl;
	}

	mgr->activate();
	while (!terminate) {
		if (orb->work_pending())
			orb->perform_work();
		if (expiry_needed())
			expire_now();
	}

	if (!CORBA::Object::is_nil(ctx) && bindok) {
		try {
			CosNaming::NamingContext myctx = ctx->resolve(n);
			ctx->unbind(n);
			myctx->destroy();
		} catch (CORBA::Exception &e) {
			cerr << "Warning: Naming Service unbind failed" << endl;
		}
	}

	orb->shutdown(true);

	delete server;
	return 0;
}