Merge pull request #2216 from jwillemsen/jwi-cxxversionchecks
[ACE_TAO.git] / ACE / examples / Service_Configurator / Misc / main.cpp
blob0dde3f483a8add42bc59acacbe7adfcb7e43c6bb
2 //=============================================================================
3 /**
4 * @file main.cpp
6 * This directory contains an example that illustrates how the ACE
7 * Service Configurator can configure static and dynamic services,
8 * both from the command-line and from a svc.config file.
10 * @author Doug Schmidt <d.schmidt@vanderbilt.edu>
12 //=============================================================================
15 #include "ace/OS_main.h"
16 #include "ace/Service_Config.h"
17 #include "ace/ARGV.h"
18 #include "ace/Log_Msg.h"
19 #include "Timer_Service.h"
22 // Create an object that will insert the <Timer_Service> into the list
23 // of statically linked services that the <ACE_Service_Config> will
24 // process at run-time.
25 ACE_STATIC_SVC_REQUIRE (Timer_Service_1)
27 int
28 ACE_TMAIN (int argc, ACE_TCHAR *argv[])
30 // Set up an argument vector that we can add entries to!
31 ACE_ARGV args;
33 // Manufacture a "fake" svc.conf entry to demonstrate the -S option
34 // that allows us to pass these entries via the "command-line"
35 // rather than the svc.conf file.
37 for (int i = 0; i < argc; i++)
38 args.add (argv[i]);
40 args.add (ACE_TEXT ("-y"));
41 args.add (ACE_TEXT ("-d"));
42 args.add (ACE_TEXT ("-S"));
43 args.add (ACE_TEXT ("\"static Timer_Service_1 'timer 1 10 $TRACE'\""));
44 args.add (ACE_TEXT ("-S"));
45 args.add (ACE_TEXT ("\"dynamic Timer_Service_2 Service_Object * Timer:_make_Timer_Service_2() 'timer 2 10 $TRACE'\""));
46 // Test the -f option!
47 args.add (ACE_TEXT ("-f svc.conf1"));
48 args.add (ACE_TEXT ("-f svc.conf2"));
50 ACE_DEBUG ((LM_DEBUG,
51 ACE_TEXT ("argc = %d\n"),
52 args.argc ()));
54 // Print the contents of the combined <ACE_ARGV>.
55 for (int i = 0; i < args.argc (); i++)
56 ACE_DEBUG ((LM_DEBUG,
57 ACE_TEXT ("(%d) %s\n"),
59 args.argv ()[i]));
61 int const result = ACE_Service_Config::open (args.argc (),
62 args.argv (),
63 ACE_DEFAULT_LOGGER_KEY,
64 0);
65 if (result != 0)
66 ACE_ERROR_RETURN ((LM_ERROR,
67 ACE_TEXT ("%p\n"),
68 ACE_TEXT ("open")),
69 1);
71 // Run forever, performing the configured services until we
72 // shutdown.
74 ACE_Reactor::run_event_loop ();
75 return 0;