summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/FtRtEvent/EventChannel/UpdateableHandler.cpp
blob: 93879192db3cdef95c1282e2528661197194cdab (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
// $Id$

#include "orbsvcs/FtRtEvent/EventChannel/UpdateableHandler.h"
#include "orbsvcs/FtRtEvent/EventChannel/Update_Manager.h"
#include "orbsvcs/FtRtEvent/EventChannel/AMI_Primary_Replication_Strategy.h"
#include "../Utils/resolve_init.h"

ACE_RCSID (EventChannel,
           UpdateableHandler,
           "$Id$")


TAO_BEGIN_VERSIONED_NAMESPACE_DECL

UpdateableHandler::UpdateableHandler(AMI_Primary_Replication_Strategy* strategy)
  : strategy_(strategy)
{
}

UpdateableHandler::~UpdateableHandler()
{
}

FTRT::AMI_UpdateableHandler_ptr UpdateableHandler::activate(
  Update_Manager* mgr, int id,
  PortableServer::ObjectId& object_id)
{
  object_id.length(sizeof(mgr) + sizeof(id));
  ACE_OS::memcpy(object_id.get_buffer(), &mgr, sizeof(mgr));
  ACE_OS::memcpy(object_id.get_buffer() + sizeof(mgr), &id, sizeof(id));
  strategy_->poa()->activate_object_with_id(object_id,
                                            this);
  CORBA::Object_var object = strategy_->poa()->id_to_reference(
    object_id);

  return FTRT::AMI_UpdateableHandler::_narrow(object.in());
}



void UpdateableHandler::dispatch(UpdateableHandler::Handler handler)
{
  PortableServer::Current_var current =
    resolve_init<PortableServer::Current>(strategy_->orb(),
    "POACurrent");

  PortableServer::ObjectId_var object_id =
    current->get_object_id();

  Update_Manager* mgr;
  int id;

  ACE_OS::memcpy(&mgr, object_id->get_buffer(), sizeof(mgr));
  ACE_OS::memcpy(&id, object_id->get_buffer()+sizeof(mgr), sizeof(id));

  ACE_DEBUG((LM_DEBUG, "%d\n", id));

  (mgr->*handler)(id);

  strategy_->poa()->deactivate_object(object_id.in());
}

void UpdateableHandler::set_update (
                                    )
{
  ACE_DEBUG((LM_DEBUG,"Received reply from "));
  dispatch(&Update_Manager::handle_reply);
}
void UpdateableHandler::set_update_excep (
  ::Messaging::ExceptionHolder * excep_holder
  )
{
  ACE_DEBUG((LM_DEBUG, "Received Exception from"));
  try{
    excep_holder->raise_exception();
  }
  catch (const CORBA::Exception& ex){
    ex._tao_print_exception ("A corba exception\n");
  }

  dispatch(&Update_Manager::handle_exception);
}

TAO_END_VERSIONED_NAMESPACE_DECL