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"
29 class Controller_impl
;
31 class Thermometer_impl
: public virtual POA_CCS::Thermometer
{
34 virtual CCS::ModelType
model();
35 virtual CCS::AssetType
asset_num();
36 virtual CCS::TempType
temperature();
37 virtual CCS::LocType
location();
38 virtual void location(const char *loc
);
39 virtual void remove();
41 // Constructor & destructor
42 Thermometer_impl(CCS::AssetType anum
);
43 virtual ~Thermometer_impl();
45 static Controller_impl
* m_ctrl
; // My controller
46 const CCS::AssetType m_anum
; // My asset number
50 CCS::ModelType
get_model();
51 CCS::TempType
get_temp();
52 CCS::LocType
get_loc();
53 void set_loc(const char * new_loc
);
55 // Copy and assignment not supported
56 Thermometer_impl(const Thermometer_impl
&);
57 void operator=(const Thermometer_impl
&);
60 class Thermostat_impl
:
61 public virtual POA_CCS::Thermostat
,
62 public virtual Thermometer_impl
{
65 virtual CCS::TempType
get_nominal();
66 virtual CCS::TempType
set_nominal(CCS::TempType new_temp
);
68 // Constructor and destructor
69 Thermostat_impl(CCS::AssetType anum
);
70 virtual ~Thermostat_impl();
74 CCS::TempType
get_nominal_temp();
75 CCS::TempType
set_nominal_temp(CCS::TempType new_temp
);
77 // Copy and assignment not supported
78 Thermostat_impl(const Thermostat_impl
&);
79 void operator=(const Thermostat_impl
&);
82 class Controller_impl
: public virtual POA_CCS::Controller
{
85 virtual CCS::Controller::ThermometerSeq
* list();
86 virtual void find(CCS::Controller::SearchSeq
& slist
);
87 virtual void change(const CCS::Controller::ThermostatSeq
& tlist
,
89 virtual CCS::Thermometer_ptr
94 virtual CCS::Thermostat_ptr
101 // Constructor and destructor
103 PortableServer::POA_ptr poa
,
104 const char * asset_file
106 virtual ~Controller_impl();
108 // Helper functions to allow access to the object map
111 Thermometer_impl
* tip
113 void remove_impl(CCS::AssetType anum
);
114 bool exists(CCS::AssetType anum
);
117 // Map of existing assets. The servant pointer is null
118 // the corresponding servant is not in memory.
119 typedef map
<CCS::AssetType
, Thermometer_impl
*> AssetMap
;
122 // POA for thermometers and thermostats
123 PortableServer::POA_var m_poa
;
125 // Name of asset number file
126 CORBA::String_var m_asset_file
;
128 // Copy and assignment not supported
129 Controller_impl(const Controller_impl
&);
130 void operator=(const Controller_impl
&);
132 // Function object for the find_if algorithm to search for
133 // devices by location and model string.
137 CCS::Controller::SearchCriterion sc
,
139 ) : m_sc(sc
), m_str(str
) {}
141 pair
<const CCS::AssetType
, Thermometer_impl
*> & p
146 case CCS::Controller::LOCATION
:
147 ICP_get(p
.first
, "location", buf
, sizeof(buf
));
149 case CCS::Controller::MODEL
:
150 ICP_get(p
.first
, "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
,
177 const PortableServer::ObjectId
& /* oid */,
178 PortableServer::POA_ptr
/* poa */,
179 const char * /* operation */,
181 PortableServer::Servant
/* servant */) {}
184 Controller_impl
* m_ctrl
;
186 typedef list
<Thermometer_impl
*> EvictorQueue
;
187 typedef map
<CCS::AssetType
, EvictorQueue::iterator
>
190 static const unsigned int MAX_EQ_SIZE
;// = 100;
192 ActiveObjectMap m_aom
;
194 // Copy and assignment not supported
195 DeviceLocator_impl(const DeviceLocator_impl
&);
196 void operator=(const DeviceLocator_impl
&);