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 //=============================================================================
25 #include "tao/PortableServer/PortableServer.h"
26 #include "tao/PortableServer/ServantLocatorC.h"
32 class Controller_impl
;
34 class Thermometer_impl
: public virtual POA_CCS::Thermometer
{
37 virtual CCS::ModelType
model();
38 virtual CCS::AssetType
asset_num();
39 virtual CCS::TempType
temperature();
40 virtual CCS::LocType
location();
41 virtual void location(const char *loc
);
42 virtual void remove();
44 // Constructor & destructor
45 Thermometer_impl(CCS::AssetType anum
);
46 virtual ~Thermometer_impl();
48 static Controller_impl
* m_ctrl
; // My controller
49 const CCS::AssetType m_anum
; // My asset number
56 CCS::ModelType
get_model();
57 CCS::TempType
get_temp();
58 CCS::LocType
get_loc();
59 void set_loc(const char * new_loc
);
61 ACE_Mutex m_count_mutex
;
62 CORBA::ULong m_ref_count
;
65 // Copy and assignment not supported
66 Thermometer_impl(const Thermometer_impl
&);
67 void operator=(const Thermometer_impl
&);
70 class Thermostat_impl
:
71 public virtual POA_CCS::Thermostat
,
72 public virtual Thermometer_impl
{
75 virtual CCS::TempType
get_nominal();
76 virtual CCS::TempType
set_nominal(CCS::TempType new_temp
);
78 // Constructor and destructor
79 Thermostat_impl(CCS::AssetType anum
);
80 virtual ~Thermostat_impl();
84 CCS::TempType
get_nominal_temp();
85 CCS::TempType
set_nominal_temp(CCS::TempType new_temp
);
87 // Copy and assignment not supported
88 Thermostat_impl(const Thermostat_impl
&);
89 void operator=(const Thermostat_impl
&);
92 class Controller_impl
: public virtual POA_CCS::Controller
{
95 virtual CCS::Controller::ThermometerSeq
* list();
96 virtual void find(CCS::Controller::SearchSeq
& slist
);
97 virtual void change(const CCS::Controller::ThermostatSeq
& tlist
,
100 virtual CCS::Thermometer_ptr
create_thermometer(CCS::AssetType anum
,
103 virtual CCS::Thermostat_ptr
create_thermostat(CCS::AssetType anum
,
107 // Constructor and destructor
108 Controller_impl(PortableServer::POA_ptr poa
,
109 const char * asset_file
);
111 virtual ~Controller_impl();
113 // Helper functions to allow access to the object map
114 void add_impl(CCS::AssetType anum
);
115 void remove_impl(CCS::AssetType anum
);
116 bool exists(CCS::AssetType anum
);
118 ACE_Mutex m_assets_mutex
;
121 typedef set
<CCS::AssetType
> AssetSet
;
124 // POA for thermometers and thermostats
125 PortableServer::POA_var m_poa
;
127 // Name of asset number file
128 CORBA::String_var m_asset_file
;
130 // Copy and assignment not supported
131 Controller_impl(const Controller_impl
&);
132 void operator=(const Controller_impl
&);
134 // Function object for the find_if algorithm to search for
135 // devices by location and model string.
139 CCS::Controller::SearchCriterion sc
,
141 ) : m_sc(sc
), m_str(str
) {}
148 case CCS::Controller::LOCATION
:
149 ICP_get(anum
, "location", buf
, sizeof(buf
));
151 case CCS::Controller::MODEL
:
152 ICP_get(anum
, "model", buf
, sizeof(buf
));
155 assert(0); // Precondition violation
157 return strcmp(buf
, m_str
) == 0;
160 CCS::Controller::SearchCriterion m_sc
;
165 class DeviceLocator_impl
:
166 public virtual PortableServer::ServantLocator
{
168 DeviceLocator_impl(Controller_impl
* ctrl
);
170 virtual PortableServer::Servant
172 const PortableServer::ObjectId
& oid
,
173 PortableServer::POA_ptr
/* poa */ ,
174 const char * operation
,
175 void * & /* cookie */
180 const PortableServer::ObjectId
& /* oid */ ,
181 PortableServer::POA_ptr
/* poa */ ,
182 const char * /* operation */ ,
183 void * /* cookie */ ,
184 PortableServer::Servant
/* servant */
187 Controller_impl
* m_ctrl
;
189 typedef list
<Thermometer_impl
*> EvictorQueue
;
190 typedef map
<CCS::AssetType
, EvictorQueue::iterator
>
193 static const unsigned int MAX_EQ_SIZE
;// = 100;
195 ActiveObjectMap m_aom
;
197 // Copy and assignment not supported
198 DeviceLocator_impl(const DeviceLocator_impl
&);
199 void operator=(const DeviceLocator_impl
&);