Merge branch 'master' into jwi-bcc64xsingletonwarning
[ACE_TAO.git] / ACE / examples / Naming / test_writers.cpp
blob83a4f4fc93a1ffcd06aa0a3effd89641e0bdb600
1 #include "ace/OS_main.h"
2 #include "ace/Naming_Context.h"
3 #include "ace/Log_Msg.h"
4 #include "ace/OS_NS_stdio.h"
5 #include "ace/OS_NS_unistd.h"
7 int ACE_TMAIN (int, ACE_TCHAR *[])
9 int i;
11 ACE_STATIC_SVC_REGISTER(ACE_Naming_Context);
13 ACE_Naming_Context *ns_ptr;
14 ACE_NEW_RETURN (ns_ptr,
15 ACE_Naming_Context,
16 1);
17 ACE_Name_Options *name_options =
18 ns_ptr->name_options ();
20 const ACE_TCHAR *m_argv[] =
22 ACE_TEXT("MyName"),
23 ACE_TEXT("-cNODE_LOCAL"),
27 int m_argc = sizeof (m_argv) / sizeof (ACE_TCHAR *) -1;
29 name_options->parse_args (m_argc,
30 (ACE_TCHAR **) m_argv);
31 i = ns_ptr->open (ACE_Naming_Context::NODE_LOCAL);
32 ACE_DEBUG ((LM_DEBUG,
33 "(%P) opened with %d\n",
34 i));
35 if (i != 0)
36 return -1;
37 else
39 char key[128];
40 char val[32];
41 char type[2];
43 type[0] = '-';
44 type[1] = '\0';
46 int i = 0;
48 for (int l = 1; l <= 1000 ; l++)
50 ACE_OS::sprintf (key,
51 "K_%05d_%05d",
52 (int) ACE_OS::getpid (),
53 l);
54 ACE_OS::sprintf (val,
55 "Val%05d",
56 l);
57 i = ns_ptr->bind (key,
58 val,
59 type);
60 ACE_DEBUG ((LM_DEBUG,
61 "%d: bind of %s: %d\n",
62 ACE_OS::getpid (),
63 key,
64 i));
66 if (i != 0)
67 return -1;
70 return 0;