1 // This example uses the ACE_Registry class to iterator through the
2 // entries in the predefined registries. The host of iteration can be
3 // varied through argv[1]. If no host is specified the local host is
4 // used. This is very similar to how regedt32 starts up.
6 // This examples points the cool iterators in ACE_Registry
8 #include "ace/OS_main.h"
10 #if defined (ACE_WIN32) && !defined (ACE_LACKS_WIN32_REGISTRY)
12 #include "ace/Registry.h"
14 // FUZZ: disable check_for_streams_include
15 #include "ace/streams.h"
18 // Indentation while printing names
19 static const u_long INDENTATION_LEVEL
= 3;
22 static int print_naming_context (ACE_Registry::Naming_Context
&naming_context
,
24 static void print_object (const ACE_TString
&name
,
26 static void print_context (ACE_Registry::Naming_Context
&parent
,
27 const ACE_TString
&name
,
29 static void indent (u_long indentation
);
32 ACE_TMAIN (int argc
, ACE_TCHAR
*argv
[])
35 ACE_Registry::Naming_Context naming_context
;
37 // Connect to a predefined naming context
38 result
= ACE_Predefined_Naming_Contexts::connect (naming_context
,
43 argc
== 2 ? argv
[1] : 0);
46 ACE_ERROR_RETURN ((LM_ERROR
, "%p\n", "ACE_Predefined_Naming_Contexts::connect failed"), -1);
48 // Print contents of naming context
49 result
= ::print_naming_context (naming_context
, 0);
51 ACE_ERROR_RETURN ((LM_ERROR
, "%p\n", "print_naming_context failed"), -1);
57 // Print contents of <naming_context>
59 print_naming_context (ACE_Registry::Naming_Context
&naming_context
,
62 ACE_Registry::Binding_List list
;
64 // Get the list of all entries
65 int result
= naming_context
.list (list
);
67 ACE_ERROR_RETURN ((LM_ERROR
, "%p\n", "ACE_Registry::Naming_Context::list"), -1);
69 // Iterator through all entries
70 for (ACE_Registry::Binding_List::iterator i
= list
.begin ();
74 // Yeeesss! STL rules!
75 ACE_Registry::Binding
&binding
= *i
;
77 if (binding
.type () == ACE_Registry::OBJECT
)
79 ::print_object (binding
.name (),
83 ::print_context (naming_context
,
91 // Print an object with <name>
93 print_object (const ACE_TString
&name
,
97 ::indent (indentation
);
102 // Print an context with <name> and <parent>
104 print_context (ACE_Registry::Naming_Context
&parent
,
105 const ACE_TString
&name
,
109 indent (indentation
);
110 cout
<< name
<< endl
;
112 ACE_Registry::Naming_Context child_context
;
113 // Find child context
114 int result
= parent
.resolve_context (name
,
118 ACE_ERROR ((LM_ERROR
, "%s %s\n", "ACE_Registry::Naming_Context::resolve_context failed for:", name
.c_str ()));
121 // Print contents of the child
122 result
= ::print_naming_context (child_context
,
123 indentation
+ INDENTATION_LEVEL
);
125 ACE_ERROR ((LM_ERROR
, "%p\n", "print_naming_context failed"));
132 indent (u_long indentation
)
134 for (; indentation
> 0; indentation
--)
137 #else /* !ACE_WIN32 || ACE_LACKS_WIN32_REGISTRY */
139 ACE_TMAIN (int , ACE_TCHAR
*[])
143 #endif /* ACE_WIN32 && !ACE_LACKS_WIN32_REGISTRY */