summaryrefslogtreecommitdiff
path: root/TAO/orbsvcs/orbsvcs/PortableGroup/Portable_Group_Map.h
blob: d4c8ecd01b68e0f304ff111a7e373358e30ca8c2 (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
// -*- C++ -*-

//=============================================================================
/**
 *  @file   Portable_Group_Map.h
 *
 *  $Id$
 *
 *  @author Frank Hunleth <fhunleth@cs.wustl.edu>
 */
//=============================================================================

#ifndef TAO_PORTABLE_GROUP_MAP_H
#define TAO_PORTABLE_GROUP_MAP_H

#include /**/ "ace/pre.h"

#include "orbsvcs/PortableGroup/portablegroup_export.h"

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

#include "orbsvcs/PortableGroupC.h"

#include "tao/Object_KeyC.h"

#include "ace/Null_Mutex.h"
#include "ace/Hash_Map_Manager_T.h"

TAO_BEGIN_VERSIONED_NAMESPACE_DECL

class TAO_ServerRequest;

/**
 * @class TAO_GroupId_Hash
 *
 * @brief Hashing class for Group Ids.
 *
 * Define the hash() method for Group Ids.
 */
class TAO_PortableGroup_Export TAO_GroupId_Hash
{
public:

  /// Returns hash value.
  u_long operator () (const PortableGroup::TagGroupTaggedComponent *id) const;
};

/**
 * @class TAO_GroupId_Equal_To
 *
 * @brief Hashing class for Group Ids.
 *
 * Define the Equal_To () method for Object Ids.
 */
class TAO_PortableGroup_Export TAO_GroupId_Equal_To
{
public:

  /// Returns 1 if equal.
  int operator () (const PortableGroup::TagGroupTaggedComponent *lhs,
                   const PortableGroup::TagGroupTaggedComponent *rhs) const;
};

/**
 * @class TAO_Portable_Group_Map
 *
 * @brief Map of GroupIds to ObjectKeys.
 */
class TAO_PortableGroup_Export TAO_Portable_Group_Map
{
public:

  /**
   * @struct Map_Entry
   *
   * @brief Value field of the portable group map.
   */
  struct Map_Entry
  {
    /// The key.
    TAO::ObjectKey key;

    /// next ObjectKey in the group.
    struct Map_Entry *next;
  };

  /// Constructor.
  TAO_Portable_Group_Map ();

  /// Destructor.
  ~TAO_Portable_Group_Map (void);

  /// Add a GroupId->ObjectKey mapping to the map.
  /// This function takes ownership of the memory pointed to be group_id
  void add_groupid_objectkey_pair (PortableGroup::TagGroupTaggedComponent *group_id,
                                   const TAO::ObjectKey &key);


  /// Remove a GroupId->ObjectKey mapping from the map.
  void remove_groupid_objectkey_pair (const PortableGroup::TagGroupTaggedComponent* group_id,
                                      const TAO::ObjectKey &key);

  /// Dispatch a request to all of the ObjectIds that belong to
  /// the specified group.
  void dispatch (PortableGroup::TagGroupTaggedComponent* group_id,
                                    TAO_ORB_Core *orb_core,
                                    TAO_ServerRequest &request,
                                    CORBA::Object_out forward_to);

  /// Id hash map.
  typedef ACE_Hash_Map_Manager_Ex<
    PortableGroup::TagGroupTaggedComponent *,
    Map_Entry *,
    TAO_GroupId_Hash,
    TAO_GroupId_Equal_To,
    ACE_Null_Mutex> GroupId_Table;
  typedef GroupId_Table::iterator Iterator;

protected:
  /// Lock used to synchronize access to map_.
  TAO_SYNCH_MUTEX lock_;

  /// Id map.
  GroupId_Table map_;
};

TAO_END_VERSIONED_NAMESPACE_DECL

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

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