summaryrefslogtreecommitdiff
path: root/TAO/tests/Portable_Interceptors/Slot/driver.cpp
blob: b7d2b3205001ba4ea89d31266caf0da74816299d (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
// file      : Slot/driver.cpp
// author    : Boris Kolpackov <boris@kolpackov.net>
// cvs-id    : $Id$

#include "tao/PI/PI.h"
#include "tao/LocalObject.h"
#include "tao/ORBInitializer_Registry.h"

PortableInterceptor::SlotId slot_id;

class ORB_Initializer : public virtual PortableInterceptor::ORBInitializer,
                        public virtual TAO_Local_RefCounted_Object
{
public:
  virtual void
  pre_init (PortableInterceptor::ORBInitInfo_ptr) throw (CORBA::SystemException)
  {
  }

  virtual void
  post_init (PortableInterceptor::ORBInitInfo_ptr info) throw (CORBA::SystemException)
  {
    slot_id = info->allocate_slot_id ();
    ACE_DEBUG ((LM_DEBUG, "Allocated slot with id %d.\n", slot_id));
  }
};

int
main (int argc, char *argv[])
{

  try
  {
    PortableInterceptor::ORBInitializer_var orb_initializer = new ORB_Initializer ();
    PortableInterceptor::register_orb_initializer (orb_initializer.in ());

    CORBA::ORB_var orb = CORBA::ORB_init (argc, argv);

    CORBA::Object_var pic_obj = orb->resolve_initial_references ("PICurrent");
    PortableInterceptor::Current_var pic (
      PortableInterceptor::Current::_narrow (pic_obj.in ()));

    CORBA::Any in;
    in <<= CORBA::ULong (1);
    pic->set_slot (slot_id, in);

    CORBA::ULong v (0);
    CORBA::Any_var out = pic->get_slot (slot_id);
    out >>= v;

    if (v != 1)
    {
      ACE_ERROR ((LM_ERROR, "ERROR: Slot value was not preserved.\n"));
      return 1;
    }
  }
  catch (PortableInterceptor::InvalidSlot const&)
  {
    ACE_ERROR ((LM_ERROR, "ERROR: Caught InvalidSlot exception.\n"));
    return 1;
  }

  return 0;
}