summaryrefslogtreecommitdiff
path: root/TAO/CIAO/tools/RTComponentServer/RTConfig_Manager.h
blob: 60ea4645f7a089976d58134ab8b1fadb96e739de (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// -*- C++ -*-

//=============================================================================
/**
 *  @file    RTConfig_Manager.h
 *
 *  $Id$
 *
 *  This file contains classes that manage name to configuration
 *  mapping info in a RTComponentServer.
 *
 *  @author Nanbor Wang <nanbor@cs.wustl.edu>
 */
//=============================================================================


#ifndef CIAO_RTCONFIG_MANAGER_H
#define CIAO_RTCONFIG_MANAGER_H
#include /**/ "ace/pre.h"

#include "ace/config-all.h"

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

#include "tao/RTCORBA/RTCORBA.h"
#include "tools/XML_Helpers/RTConfigurationC.h"
#include "ace/Null_Mutex.h"
#include "ace/SString.h"
#include "ace/Hash_Map_Manager_T.h"

namespace CIAO
{
  /**
   * @brief RTResource_Config_Manager maintains a collection of
   * RTCORBA related resources.
   *
   * This class is responsible to create and manage a list of RTCORBA
   * related resources that are global to an RT ComponentServer.  The
   * information required to create and configure these resources are
   * passed in via the @a info argument in the @c init method.  These
   * resources are identified by names.  This class is used by the
   * RTPolicy_Set_Manager for associating these resources with related
   * RTPolicies.  These resources are destoryed along with this class.
   *
   * Currently, the only resources supported (and managed) by this
   * class are Threadpool and Threadpool_with_Lanes.
   */
  class RTResource_Config_Manager
  {
  public:
    RTResource_Config_Manager (RTCORBA::RTORB_ptr orb);
    ~RTResource_Config_Manager ();

    /// Initializing the RTResource_Config_Manager
    void init (const CIAO::RTConfiguration::RTORB_Resource_Info &info
               ACE_ENV_ARG_DECL_WITH_DEFAULTS)
      ACE_THROW_SPEC ((CORBA::SystemException));

    /// Finalizing the RTResource_Config_Manager and the resources it
    /// manages.
    void fini (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS)
      ACE_THROW_SPEC ((CORBA::SystemException));

    /// Query a thread pool by name.
    RTCORBA::ThreadpoolId find_threadpool_by_name (const char *name
                                                   ACE_ENV_ARG_DECL_WITH_DEFAULTS)
      ACE_THROW_SPEC ((CORBA::SystemException));


    /// Query a priority bands info by name.
    RTCORBA::PriorityBands *find_priority_bands_by_name (const char *name
                                                   ACE_ENV_ARG_DECL_WITH_DEFAULTS)
      ACE_THROW_SPEC ((CORBA::SystemException));

  private:
    // Cached an RTORB reference.
    RTCORBA::RTORB_var rtorb_;

    /// Hash_Map stuff.
    typedef ACE_Hash_Map_Manager_Ex<ACE_CString,
                                    RTCORBA::ThreadpoolId,
                                    ACE_Hash<ACE_CString>,
                                    ACE_Equal_To<ACE_CString>,
                                    ACE_Null_Mutex> TP_MAP;

    typedef ACE_Hash_Map_Manager_Ex<ACE_CString,
                                    RTCORBA::PriorityBands_var,
                                    ACE_Hash<ACE_CString>,
                                    ACE_Equal_To<ACE_CString>,
                                    ACE_Null_Mutex> PB_MAP;

    /// Internal TP name to id map.
    TP_MAP threadpool_map_;

    /// Internal PB name to priority bands map.
    PB_MAP priority_bands_map_;
  };

  /**
   * @brief This class creates and maintains named policy sets which
   * can be indexed via names.
   *
   * This class requires to use the RTResource_Config_Manager.
   */
  class RTPolicy_Set_Manager
  {
  public:
    RTPolicy_Set_Manager (RTResource_Config_Manager &resource_config,
                          CORBA::ORB_ptr orb,
                          RTCORBA::RTORB_ptr rtorb);
    ~RTPolicy_Set_Manager ();

    /// Initialize the RTPolicy_Set_Manager and the policies it manages.
    void init (const CIAO::RTConfiguration::Policy_Sets &sets
               ACE_ENV_ARG_DECL_WITH_DEFAULTS)
      ACE_THROW_SPEC ((CORBA::SystemException));

    /// Finalizing the RTPolicy_Set_Manager and the policies it
    /// creates.
    void fini (ACE_ENV_SINGLE_ARG_DECL_WITH_DEFAULTS)
      ACE_THROW_SPEC ((CORBA::SystemException));

    /// Query a policy set by name
    CORBA::PolicyList *find_policies_by_name (const char *name
                                              ACE_ENV_ARG_DECL_WITH_DEFAULTS)
      ACE_THROW_SPEC ((CORBA::SystemException));

  private:
    /// Reference to Resource Manager
    RTResource_Config_Manager &resource_manager_;

    /// Cached an ORB reference.
    CORBA::ORB_var orb_;

    /// Cached an RTORB reference.
    RTCORBA::RTORB_var rtorb_;

    /// create a single policy
    CORBA::Policy_ptr create_single_policy
    (const CIAO::RTConfiguration::Policy_Config &policy_config
     ACE_ENV_ARG_DECL_WITH_DEFAULTS)
      ACE_THROW_SPEC ((CORBA::SystemException));

    /// Hash_Map stuff.
    typedef ACE_Hash_Map_Manager_Ex<ACE_CString,
                                    CORBA::PolicyList_var,
                                    ACE_Hash<ACE_CString>,
                                    ACE_Equal_To<ACE_CString>,
                                    ACE_Null_Mutex> POLICY_MAP;

    /// Internal TP names to id map.
    POLICY_MAP policy_map_;
  };
}

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

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