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
27 CORBA::ORB_var orb = CORBA::ORB_init(argc, argv);
28
29
30
31 cout << "Initialize POA ..." << endl;
32
33 CORBA::Object_var poaObject = orb->resolve_initial_references("RootPOA");
34
35
36 PortableServer::POA_var poa = PortableServer::POA::_narrow(poaObject);
37 CorbaAssert(poa, "Failed to obtain POA server.");
38
39 PortableServer::POAManager_var poaManager = poa->the_POAManager();
40 CorbaAssert(poaManager, "Failed to obtain POA manager.");
41
42
43
44 cout << "Initialize server ..." << endl;
45
46 HomeFinder_Impl* homeFinder = new HomeFinder_Impl(orb);
47
48 PortableServer::ObjectId_var objectId = poa->activate_object(homeFinder);
49
50 CORBA::Object_var objectReference = poa->id_to_reference(objectId.in());
51
52
53 cout << orb->object_to_string(objectReference.in()) << endl;
54
55
56
57 cout << "Resolve Naming Service ..." << endl;
58
59 CORBA::Object_var namingService = orb->resolve_initial_references("NameService");
60
61 CorbaAssert(namingService, "Couldn't locate the Naming Service.");
62
63
64 CosNaming::NamingContext_var namingContext = CosNaming::NamingContext::_narrow(namingService);
65
66 CorbaAssert(namingContext, "Couldn't locate the Naming Service.");
67
68 CosNaming::Name newName;
69 newName.length(1);
70 newName[0].id = CORBA::string_dup("HomeFinder");
71 newName[0].kind = CORBA::string_dup("CCM");
72
73
74 try
75 {
76
77 namingContext->rebind(newName, objectReference);
78 }
79 catch (CosNaming::NamingContext::NotFound&)
80 {
81 CorbaError("Naming context not found.");
82 }
83 catch (CosNaming::NamingContext::InvalidName&)
84 {
85 CorbaError("Invalid name.");
86 }
87
88 cout << "HomeFinder is ready." << endl;
89
90 poaManager->activate();
91 orb->run();
92
93
94 poa->destroy(true, true);
95 delete homeFinder;
96
97 return 0;
98 }
99 catch (CORBA::Exception&)
100 {
101 CorbaError("Corba failed to run properly.");
102 }
103 }
104