1
2
3
4
5
6
7
8 #include <iostream>
9 using namespace std;
10
11
12
13 #pragma warning (disable: 4267)
14 #include <coss/CosNaming.h>
15 #include "Helper.h"
16
17 #include "HomeFinder_Impl.h"
18 using namespace POA_HPI;
19
20
21
22 int main(int argc, char* argv[])
23 {
24 try
{
25
26 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
27
28
29
30 cout << "Initialize POA ..." << endl;
31
32 CORBA::Object_var poaObject = orb->resolve_initial_references("RootPOA");
33
34
35 PortableServer::POA_var poa = PortableServer::POA::_narrow(poaObject);
36 CorbaAssert(poa, "Failed to obtain POA server.");
37
38 PortableServer::POAManager_var poaManager = poa->the_POAManager();
39 CorbaAssert(poaManager, "Failed to obtain POA manager.");
40
41
42
43 cout << "Initialize server ..." << endl;
44
45 HomeFinder_Impl* homeFinder = new HomeFinder_Impl(orb);
46
47 PortableServer::ObjectId_var objectId = poa->activate_object(homeFinder);
48
49 CORBA::Object_var objectReference = poa->id_to_reference(objectId.in());
50
51
52 cout << orb->object_to_string(objectReference.in()) << endl;
53
54
55
56 cout << "Resolve Naming Service ..." << endl;
57
58 CORBA::Object_var namingService = orb->resolve_initial_references("NameService");
59
60 CorbaAssert(namingService, "Couldn't locate the Naming Service.");
61
62
63 CosNaming::NamingContext_var namingContext = CosNaming::NamingContext::_narrow(namingService);
64
65 CorbaAssert(namingContext, "Couldn't locate the Naming Service.");
66
67 CosNaming::Name newName;
68 newName.length(1);
69 newName[0].id = CORBA::string_dup("HomeFinder");
70 newName[0].kind = CORBA::string_dup("CCM");
71
72
73 try
{
74
75 namingContext->rebind(newName, objectReference);
76 }
77 catch (CosNaming::NamingContext::NotFound&)
78 {
79 CorbaError("Naming context not found.");
80 }
81 catch (CosNaming::NamingContext::InvalidName&)
82 {
83 CorbaError("Invalid name.");
84 }
85
86 cout << "HomeFinder is ready." << endl;
87
88 poaManager->activate();
89 orb->run();
90
91
92 poa->destroy(true, true);
93 delete homeFinder;
94
95 return 0;
96 }
97 catch (CORBA::Exception&)
98 {
99 CorbaError("Corba failed to run properly.");
100 }
101 }
102