1 //=============================================================================
5 * @author Source code used in TAO has been modified and adapted from the codeprovided in the book
6 * @author "Advanced CORBA Programming with C++" by MichiHenning and Steve Vinoski. Copyright 1999. Addison-Wesley
8 * @author MA.Modified for TAO by Mike Moran <mm4@cs.wustl.edu>
10 //=============================================================================
24 #include "tao/PortableServer/PortableServer.h"
25 #include "tao/PortableServer/ServantLocatorC.h"
31 class Controller_impl
;
33 class Thermometer_impl
: public virtual POA_CCS::Thermometer
{
36 virtual CCS::ModelType
model();
37 virtual CCS::AssetType
asset_num();
38 virtual CCS::TempType
temperature();
39 virtual CCS::LocType
location();
40 virtual void location(const char *loc
);
41 virtual void remove();
43 // Constructor & destructor
44 Thermometer_impl(CCS::AssetType anum
);
45 virtual ~Thermometer_impl();
47 static Controller_impl
* m_ctrl
; // My controller
48 const CCS::AssetType m_anum
; // My asset number
55 CCS::ModelType
get_model();
56 CCS::TempType
get_temp();
57 CCS::LocType
get_loc();
58 void set_loc(const char * new_loc
);
60 ACE_Mutex m_count_mutex
;
61 CORBA::ULong m_ref_count
;
64 // Copy and assignment not supported
65 Thermometer_impl(const Thermometer_impl
&);
66 void operator=(const Thermometer_impl
&);
69 class Thermostat_impl
:
70 public virtual POA_CCS::Thermostat
,
71 public virtual Thermometer_impl
{
74 virtual CCS::TempType
get_nominal();
75 virtual CCS::TempType
set_nominal(CCS::TempType new_temp
);
77 // Constructor and destructor
78 Thermostat_impl(CCS::AssetType anum
);
79 virtual ~Thermostat_impl();
83 CCS::TempType
get_nominal_temp();
84 CCS::TempType
set_nominal_temp(CCS::TempType new_temp
);
86 // Copy and assignment not supported
87 Thermostat_impl(const Thermostat_impl
&);
88 void operator=(const Thermostat_impl
&);
91 class Controller_impl
: public virtual POA_CCS::Controller
{
94 virtual CCS::Controller::ThermometerSeq
* list();
95 virtual void find(CCS::Controller::SearchSeq
& slist
);
96 virtual void change(const CCS::Controller::ThermostatSeq
& tlist
,
99 virtual CCS::Thermometer_ptr
create_thermometer(CCS::AssetType anum
,
102 virtual CCS::Thermostat_ptr
create_thermostat(CCS::AssetType anum
,
106 // Constructor and destructor
107 Controller_impl(PortableServer::POA_ptr poa
,
108 const char * asset_file
);
110 virtual ~Controller_impl();
112 // Helper functions to allow access to the object map
113 void add_impl(CCS::AssetType anum
);
114 void remove_impl(CCS::AssetType anum
);
115 bool exists(CCS::AssetType anum
);
117 ACE_Mutex m_assets_mutex
;
120 typedef set
<CCS::AssetType
> AssetSet
;
123 // POA for thermometers and thermostats
124 PortableServer::POA_var m_poa
;
126 // Name of asset number file
127 CORBA::String_var m_asset_file
;
129 // Copy and assignment not supported
130 Controller_impl(const Controller_impl
&);
131 void operator=(const Controller_impl
&);
133 // Function object for the find_if algorithm to search for
134 // devices by location and model string.
138 CCS::Controller::SearchCriterion sc
,
140 ) : m_sc(sc
), m_str(str
) {}
142 CCS::AssetType anum
) const
146 case CCS::Controller::LOCATION
:
147 ICP_get(anum
, "location", buf
, sizeof(buf
));
149 case CCS::Controller::MODEL
:
150 ICP_get(anum
, "model", buf
, sizeof(buf
));
153 assert(0); // Precondition violation
155 return strcmp(buf
, m_str
) == 0;
158 CCS::Controller::SearchCriterion m_sc
;
163 class DeviceLocator_impl
:
164 public virtual PortableServer::ServantLocator
{
166 DeviceLocator_impl(Controller_impl
* ctrl
);
168 virtual PortableServer::Servant
170 const PortableServer::ObjectId
& oid
,
171 PortableServer::POA_ptr
/* poa */ ,
172 const char * operation
,
173 void * & /* cookie */
178 const PortableServer::ObjectId
& /* oid */ ,
179 PortableServer::POA_ptr
/* poa */ ,
180 const char * /* operation */ ,
181 void * /* cookie */ ,
182 PortableServer::Servant
/* servant */
185 Controller_impl
* m_ctrl
;
187 typedef list
<Thermometer_impl
*> EvictorQueue
;
188 typedef map
<CCS::AssetType
, EvictorQueue::iterator
>
191 static const unsigned int MAX_EQ_SIZE
;// = 100;
193 ActiveObjectMap m_aom
;
195 // Copy and assignment not supported
196 DeviceLocator_impl(const DeviceLocator_impl
&);
197 void operator=(const DeviceLocator_impl
&);