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 //=============================================================================
23 #include "tao/PortableServer/PortableServer.h"
24 #include "tao/PortableServer/ServantLocatorC.h"
28 class Controller_impl
;
30 class Thermometer_impl
: public virtual POA_CCS::Thermometer
{
33 virtual CCS::ModelType
model();
34 virtual CCS::AssetType
asset_num();
35 virtual CCS::TempType
temperature();
36 virtual CCS::LocType
location();
37 virtual void location(const char *loc
);
38 virtual void remove();
40 // Constructor & destructor
41 Thermometer_impl(CCS::AssetType anum
);
42 virtual ~Thermometer_impl();
44 static Controller_impl
* m_ctrl
; // My controller
45 const CCS::AssetType m_anum
; // My asset number
49 CCS::ModelType
get_model();
50 CCS::TempType
get_temp();
51 CCS::LocType
get_loc();
52 void set_loc(const char * new_loc
);
54 // Copy and assignment not supported
55 Thermometer_impl(const Thermometer_impl
&);
56 void operator=(const Thermometer_impl
&);
59 class Thermostat_impl
:
60 public virtual POA_CCS::Thermostat
,
61 public virtual Thermometer_impl
{
64 virtual CCS::TempType
get_nominal();
65 virtual CCS::TempType
set_nominal(CCS::TempType new_temp
);
67 // Constructor and destructor
68 Thermostat_impl(CCS::AssetType anum
);
69 virtual ~Thermostat_impl();
73 CCS::TempType
get_nominal_temp();
74 CCS::TempType
set_nominal_temp(CCS::TempType new_temp
);
76 // Copy and assignment not supported
77 Thermostat_impl(const Thermostat_impl
&);
78 void operator=(const Thermostat_impl
&);
81 class Controller_impl
: public virtual POA_CCS::Controller
{
84 virtual CCS::Controller::ThermometerSeq
* list();
85 virtual void find(CCS::Controller::SearchSeq
& slist
);
86 virtual void change(const CCS::Controller::ThermostatSeq
& tlist
,
88 virtual CCS::Thermometer_ptr
93 virtual CCS::Thermostat_ptr
100 // Constructor and destructor
102 PortableServer::POA_ptr poa
,
103 const char * asset_file
105 virtual ~Controller_impl();
107 // Helper functions to allow access to the object map
110 Thermometer_impl
* tip
112 void remove_impl(CCS::AssetType anum
);
113 bool exists(CCS::AssetType anum
);
116 // Map of existing assets. The servant pointer is null
117 // the corresponding servant is not in memory.
118 typedef map
<CCS::AssetType
, Thermometer_impl
*> AssetMap
;
121 // POA for thermometers and thermostats
122 PortableServer::POA_var m_poa
;
124 // Name of asset number file
125 CORBA::String_var m_asset_file
;
127 // Copy and assignment not supported
128 Controller_impl(const Controller_impl
&);
129 void operator=(const Controller_impl
&);
131 // Function object for the find_if algorithm to search for
132 // devices by location and model string.
136 CCS::Controller::SearchCriterion sc
,
138 ) : m_sc(sc
), m_str(str
) {}
140 pair
<const CCS::AssetType
, Thermometer_impl
*> & p
) const
144 case CCS::Controller::LOCATION
:
145 ICP_get(p
.first
, "location", buf
, sizeof(buf
));
147 case CCS::Controller::MODEL
:
148 ICP_get(p
.first
, "model", buf
, sizeof(buf
));
151 assert(0); // Precondition violation
153 return strcmp(buf
, m_str
) == 0;
156 CCS::Controller::SearchCriterion m_sc
;
161 class DeviceLocator_impl
:
162 public virtual PortableServer::ServantLocator
{
164 DeviceLocator_impl(Controller_impl
* ctrl
);
166 virtual PortableServer::Servant
168 const PortableServer::ObjectId
& oid
,
169 PortableServer::POA_ptr poa
,
170 const char * operation
,
175 const PortableServer::ObjectId
& /* oid */,
176 PortableServer::POA_ptr
/* poa */,
177 const char * /* operation */,
179 PortableServer::Servant
/* servant */) {}
182 Controller_impl
* m_ctrl
;
184 typedef list
<Thermometer_impl
*> EvictorQueue
;
185 typedef map
<CCS::AssetType
, EvictorQueue::iterator
>
188 static const unsigned int MAX_EQ_SIZE
;// = 100;
190 ActiveObjectMap m_aom
;
192 // Copy and assignment not supported
193 DeviceLocator_impl(const DeviceLocator_impl
&);
194 void operator=(const DeviceLocator_impl
&);