summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/LWFT/StateSyncAgentTask.cpp
blob: 6f477a869a2d0c85568f7fe6ccf8ee3ea07cc89e (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
// -*- C++ -*-
// $Id$

#include "tao/PortableServer/POAC.h"

#include "Barrier_Guard.h"

#include "StateSyncAgentTask.h"
#include "StateSynchronizationAgent_i.h"

StateSyncAgentTask::StateSyncAgentTask (
  CORBA::ORB_ptr orb,
  StateSynchronizationAgent_i * agent)
  : orb_ (CORBA::ORB::_duplicate (orb)),
    agent_ (agent),
    sync_ (2),
    agent_ref_ (StateSynchronizationAgent::_nil ())
{
}

int
StateSyncAgentTask::svc (void)
{
  try
    {
      {
        Barrier_Guard barrier_guard (sync_);

        CORBA::Object_var object =
          this->orb_->resolve_initial_references ("RootPOA");

        PortableServer::POA_var root_poa =
          PortableServer::POA::_narrow (object.in ());

        PortableServer::POAManager_var poa_manager =
          root_poa->the_POAManager ();

        // ***************************************************
        // activate state synchronzation agent

        PortableServer::ObjectId_var ssa_oid =
	        root_poa->activate_object (agent_);
   
        CORBA::Object_var ssa_object =
          root_poa->id_to_reference (ssa_oid.in ());

        agent_ref_ =
	        StateSynchronizationAgent::_narrow (ssa_object.in ());

        poa_manager->activate ();
      }

      this->orb_->run ();

      this->orb_->destroy ();
    }
  catch (const CORBA::Exception& ex)
    {
      ex._tao_print_exception ("SSA task thread: exception caught:");
      return 1;
    }

  return 0;
}

int
StateSyncAgentTask::activate (long /* flags */,
                              int /* n_threads */,
                              int /* force_active */,
                              long /* priority */,
                              int /* grp_id */,
                              ACE_Task_Base* /* task */,
                              ACE_hthread_t /* thread_handles */ [],
                              void* /* stack */ [],
                              size_t /* stack_size */ [],
                              ACE_thread_t /* thread_ids */ [],
                              const char* /* thr_name */ [])
{
  // This will end up back in our overridden svc() method. We
  // want to wait for it to execute the statements in its body
  // before returning control to the calling application.
  int retval = this->ACE_Task_Base::activate ();
  sync_.wait ();
  return retval;
}

StateSynchronizationAgent_ptr
StateSyncAgentTask::agent_ref (void)
{
  return agent_ref_.in ();
}