summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/Event/Event_Manip.cpp
blob: 0d8e97cb479607e70721509f8be3078cba7000eb (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
/* -*- C++ -*- */
// $Id$
//
// ============================================================================
//
// = LIBRARY
//   TAO Real-tiem Event Services
//
// ============================================================================

#include "orbsvcs/Event/Event_Manip.h"

#if !defined (__ACE_INLINE__)
#include "Event_Manip.i"
#endif /* __ACE_INLINE__ */

TAO_EC_Event_Set::~TAO_EC_Event_Set (void)
{
  RtecEventComm::EventSet::freebuf (this->buffer_);
  this->buffer_ = 0;
  this->length_ = 0;
}

TAO_EC_Event_Set*
TAO_EC_Event_Set::_create (const RtecEventComm::Event& event)
{
  RtecEventComm::Event* buffer =
    RtecEventComm::EventSet::allocbuf (1);
  buffer[0] = event;
  return new TAO_EC_Event_Set (1, buffer);
}

TAO_EC_Event_Set*
TAO_EC_Event_Set::_create (RtecEventComm::EventSet& event_set)
{
  // Orphan the buffer....
  CORBA::ULong length = event_set.length ();
  return new TAO_EC_Event_Set (length,
                               event_set.get_buffer (1));
}

CORBA::ULong
TAO_EC_Event_Set::_incr_refcnt (void)
{
  ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, 0);
  return this->refcnt_++;
}

CORBA::ULong
TAO_EC_Event_Set::_decr_refcnt (void)
{
  {
    ACE_GUARD_RETURN (TAO_SYNCH_MUTEX, ace_mon, this->lock_, 0);
    this->refcnt_--;
    if (this->refcnt_ != 0)
      return this->refcnt_;
  }

  delete this;
  return 0;
}

// ****************************************************************

TAO_EC_Event::TAO_EC_Event (void)
  :  event_set_ (0),
     index_ (0)
{
}

TAO_EC_Event::TAO_EC_Event (TAO_EC_Event_Set *event_set,
                            CORBA::ULong index)
  :  event_set_ (TAO_EC_Event_Set::_duplicate (event_set)),
     index_ (index)
{
}

TAO_EC_Event::~TAO_EC_Event (void)
{
  TAO_EC_Event_Set::_release (this->event_set_);
  this->event_set_ = 0;
}

TAO_EC_Event::TAO_EC_Event (const TAO_EC_Event& rhs)
  :  event_set_ (TAO_EC_Event_Set::_duplicate (rhs.event_set_)),
     index_ (rhs.index_)
{
}

TAO_EC_Event&
TAO_EC_Event::operator= (const TAO_EC_Event& rhs)
{
  if (this == &rhs)
    return *this;

  // Be careful, increase the reference count and then release our
  // event set, just in case they happen to be the same.
  TAO_EC_Event_Set* tmp = 
    TAO_EC_Event_Set::_duplicate (rhs.event_set_);
  
  TAO_EC_Event_Set::_release (this->event_set_);
  this->event_set_ = tmp;
  this->index_ = rhs.index_;

  return *this;
}