summaryrefslogtreecommitdiff
path: root/ACEXML/compass/Service.cpp
blob: 249a3d9d0633ae937819727c524541bc942cc247 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// $Id$

#include "Service.h"
#include "ace/Service_Repository.h"
#include "ace/ARGV.h"

ACE_RCSID(EC_Examples, Service, "$Id$");

extern "C"
int
createService (int argc, char* argv[])
{

  if (ACE_Service_Config::process_directive ("dynamic EC_Factory Service_Object * TAO_RTEvent:_make_TAO_EC_Default_Factory() \"-ECDispatching reactive -ECFiltering basic -ECSupplierFiltering per-supplier -ECProxyConsumerLock thread -ECProxySupplierLock thread -ECConsumerControl reactive -ECSupplierControl reactive -ECConsumerControlPeriod 50000 -ECSupplierControlPeriod 50000\"") != 0)
    {

      ACE_ERROR_RETURN ((LM_ERROR,
                         "%p\n",
                         "ERROR: Client unable to process the "
                         "Service Configurator directive"),
                        -1);
    }
  Service service;
  return service.run (argc, argv);
}

Service::Service()
{

}

int
Service::run (int argc, char* argv[])
{
//   int register_with_object_manager = 0;
//   if (TAO_Singleton_Manager::instance ()->init (
//         register_with_object_manager) == -1)
//     ACE_ERROR_RETURN ((LM_ERROR,
//                        "Service::init -- ORB pre-initialization "
//                        "failed.\n"),
//                       -1);  // No exceptions available yet, so return
//                             // an error

  const ACE_Service_Type* service;
  const ACE_TCHAR* factory = "EC_Factory";

  if (ACE_Service_Repository::instance()->find (factory, &service) == -1)
    ACE_ERROR_RETURN ((LM_ERROR, "Unable to locate EC_Factory"), -1);

  if (service->type()->init (argc, argv) != 0)
    return -1;

  ACE_DECLARE_NEW_CORBA_ENV;
  ACE_TRY
    {
      // Initialize the ORB.
      CORBA::ORB_var orb = CORBA::ORB_init (argc,
                                            argv,
                                            "Service"
                                            ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      this->orb_ = orb.in();

      CORBA::Object_var object =
        orb->resolve_initial_references ("RootPOA" ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;
      PortableServer::POA_var poa =
        PortableServer::POA::_narrow (object.in () ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;
      PortableServer::POAManager_var poa_manager =
        poa->the_POAManager (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_TRY_CHECK;
      poa_manager->activate (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_TRY_CHECK;

      TAO_EC_Event_Channel_Attributes attributes (poa.in (),
                                                  poa.in ());

      TAO_EC_Event_Channel ec_impl (attributes);
      ec_impl.activate (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_TRY_CHECK;

      RtecEventChannelAdmin::EventChannel_var event_channel =
        ec_impl._this (ACE_ENV_SINGLE_ARG_PARAMETER);
      ACE_TRY_CHECK;

      TAO_Naming_Client naming_client;

      // Initialization of the naming service.
      if (naming_client.init (orb.in ()) != 0)
        ACE_ERROR_RETURN ((LM_ERROR,
                           "(%P|%t) Unable to initialize "
                           "the TAO_Naming_Client. \n"),
                          -1);

      CosNaming::Name ec_name (1);
      ec_name.length (1);
      ec_name[0].id = CORBA::string_dup ("EventChannel");
      ACE_TRY_CHECK;

      naming_client->bind (ec_name, event_channel.in() ACE_ENV_ARG_PARAMETER);
      ACE_TRY_CHECK;

      // Wait for events, using work_pending()/perform_work() may help
      // or using another thread, this example is too simple for that.

      ACE_Time_Value tv (90, 0);
      orb->run (tv);
    }
  ACE_CATCHANY
    {
      ACE_PRINT_EXCEPTION (ACE_ANY_EXCEPTION, "Service");
      return 1;
    }
  ACE_ENDTRY;
//   if (TAO_Singleton_Manager::instance ()->fini () == -1)
//     ACE_ERROR_RETURN ((LM_ERROR,
//                        "Service::fini -- ORB pre-termination failed."),
//                       -1);
  return 0;

}

#if defined (ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION)
#elif defined(ACE_HAS_TEMPLATE_INSTANTIATION_PRAGMA)
#endif /* ACE_HAS_EXPLICIT_TEMPLATE_INSTANTIATION */