1
2
3
4
5
6
7
8
9 #include "HomeFinder_Impl.h"
10
11 #include <coss/CosNaming.h>
12
13
14
15
16 CORBA::Long HomeFinder_Impl::uniqueId = 271278;
17
18
19
20
21 CCMHome_ptr HomeFinder_Impl::find_home_by_component_type( const char* comp_repid )
22 {
23 for (directoryIterator iteDirectory = directory.begin(); iteDirectory != directory.end(); iteDirectory++)
24 if (iteDirectory->compRepId == comp_repid)
25
26 return CCMHome::_narrow(orb->string_to_object(iteDirectory->homeName.c_str()));
27
28
29 throw new HomeNotFound;
30 }
31
32
33
34
35 CCMHome_ptr HomeFinder_Impl::find_home_by_home_type( const char* home_repid )
36 {
37 for (directoryIterator iteDirectory = directory.begin(); iteDirectory != directory.end(); iteDirectory++)
38 if (iteDirectory->homeRepId == home_repid)
39
40 return CCMHome::_narrow(orb->string_to_object(iteDirectory->homeName.c_str()));
41
42
43 throw new HomeNotFound;
44 }
45
46
47
48
49 CCMHome_ptr HomeFinder_Impl::find_home_by_name( const char* home_name )
50 {
51
52 CORBA::Object_var namingService = orb->resolve_initial_references("NameService");
53
54 CosNaming::NamingContext_var namingContext = CosNaming::NamingContext::_narrow(namingService);
55
56
57 if(CORBA::is_nil(namingContext))
58 {
59 cout << "Couldn't locate the Naming Service." << endl;
60 throw new HomeNotFound;
61 }
62
63
64 CosNaming::Name findName;
65 findName.length(1);
66 findName[0].id = CORBA::string_dup(home_name);
67 findName[0].kind = CORBA::string_dup("");
68
69
70 CORBA::Object_var home = namingContext->resolve(findName);
71
72
73 if(CORBA::is_nil(home))
74 throw new HomeNotFound;
75
76 return CCMHome::_narrow(home);
77 }
78
79
80
81 CORBA::Long HomeFinder_Impl::_cxx_register( const char* comp_repid, const char* home_repid, ::Components::CCMHome_ptr the_home )
82 {
83
84 uniqueId++;
85
86
87 Entry entry;
88 entry.compRepId = comp_repid;
89 entry.homeRepId = home_repid;
90 entry.homeName = orb->object_to_string(the_home);
91 entry.uniqueId = uniqueId;
92
93
94 directory.push_back(entry);
95 return uniqueId;
96 }
97
98
99
100
101 void HomeFinder_Impl::unregister( CORBA::Long cookie )
102 {
103 for (directoryIterator iteDirectory = directory.begin(); iteDirectory != directory.end(); iteDirectory++)
104 if (iteDirectory->uniqueId == cookie)
105 {
106 directory.erase(iteDirectory, iteDirectory++);
107 return;
108 }
109
110
111 throw new HomeNotFound;
112 }
113