summaryrefslogtreecommitdiff
path: root/TAO/tao/Connection_Handler.h
blob: 5a20652833bcc849790c229c15c943506a2da885 (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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
/* -*- C++ -*- */

//=============================================================================
/**
 *  @file   Connection_Handler.h
 *
 *  $Id$
 *
 *  @author Bala Natarajan  <bala@cs.wustl.edu>
 */
//=============================================================================


#ifndef TAO_CONNECTION_HANDLER_H
#define TAO_CONNECTION_HANDLER_H
#include "ace/pre.h"

#include "ace/SOCK.h"

#if !defined (ACE_LACKS_PRAGMA_ONCE)
# pragma once
#endif /* ACE_LACKS_PRAGMA_ONCE */

#include "tao/Connection_Cache_Manager.h"

#if defined(_MSC_VER)
#if (_MSC_VER >= 1200)
#pragma warning(push)
#endif /* _MSC_VER >= 1200 */
#pragma warning(disable:4250)
#endif /* _MSC_VER */

class TAO_ORB_Core;
class TAO_ORB_Core_TSS_Resources;
class ACE_Reactor;
class ACE_Event_Handler;

/**
 * @class TAO_Connection_Handler
 *
 * @brief TAO_Connection_Handler
 *
 * This class is an abstraction for the connection handlers. The
 * connections handler in every protocol can derive from this
 * class as well as the ACE_Svc_Handler specialised for the
 * right protocol. This way, most of the common code for the
 * different protocls would be in this implementation. Further,
 * this class wold be of immense use in storing the handlers in
 * the Cache for TAO. This would help in purging entries which
 * is generally accompanied by closing the open handles and
 * deleting memory associated with the handlers.
 */
class TAO_Export TAO_Connection_Handler
{

  //     Note: This class has NOT abstracted the GIOP specific
  //     details. It is just to be safe so that, we can reuse this
  //     class for any messaging protocol underneath. This way we need
  //     not touch the Cache setup even when  using other protocols (I
  //     mean messaging).

public:

  /// Constructor
  TAO_Connection_Handler (void);

  /// Constructor
  TAO_Connection_Handler (TAO_ORB_Core *orb_core);

  /// Destructor
  virtual ~TAO_Connection_Handler (void);

  void cache_map_entry (
      TAO_Connection_Cache_Manager::HASH_MAP_ENTRY *entry);

  /// Set/Get the Cache Map entry
  TAO_Connection_Cache_Manager::HASH_MAP_ENTRY *cache_map_entry (void);

  /// Make ourselves ready for use
  int make_idle (void);

  /// Increment the reference count
  void incr_ref_count (void);

  /// Decrement the reference count
  void decr_ref_count (void);

  /// Get and set method for the flag that indicates whether the
  /// handler has been registered with the reactor or not.
  CORBA::Boolean is_registered (void);
  void is_registered (CORBA::Boolean);

  /// Get the underlying handle
  virtual ACE_HANDLE fetch_handle (void) = 0;

  /// Purge our entry from the Connection Cache
  int purge_entry (void);

protected:

  /// Return our TAO_ORB_Core pointer
  TAO_ORB_Core *orb_core (void);

  /// Return our TSS Resources pointer
  TAO_ORB_Core_TSS_Resources* tss_resources (void);

  /// Set options on the socket
  int set_socket_option (ACE_SOCK &sock,
                         int snd_size,
                         int rcv_size);

  /// This method is invoked from the svc () method of the Svc_Handler
  /// Object.
  int svc_i (void);

  /// Need to be implemented by the underlying protocol objects
  virtual int handle_input_i (ACE_HANDLE = ACE_INVALID_HANDLE,
                              ACE_Time_Value *max_wait_time = 0) = 0;

private:

  /// Pointer to the TAO_ORB_Core
  TAO_ORB_Core *orb_core_;

  /// Cached tss resources of the ORB that activated this object.
  TAO_ORB_Core_TSS_Resources *tss_resources_;

  /// Reference count to the number of external references -- ie. the
  /// count of the number of places our references are being held.
  u_long ref_count_;

  /// The cache map entry -- where we are in the Connection Cache
  TAO_Connection_Cache_Manager::HASH_MAP_ENTRY *cache_map_entry_;

  /// Are we registered with the reactor?
  CORBA::Boolean is_registered_;
};

#if defined (__ACE_INLINE__)
#include "tao/Connection_Handler.inl"
#endif /* __ACE_INLINE__ */

#include "ace/post.h"
#endif /*TAO_CONNECTION_HANDLER_H*/