2 //=============================================================================
6 * @author Source code used in TAO has been modified and adapted from thecode provided in the book
7 * @author "Advanced CORBA Programming with C++"by Michi Henning and Steve Vinoski. Copyright1999. Addison-Wesley
9 * @author MA. Used with permission ofAddison-Wesley.Modified for TAO by Mike Moran <mm4@cs.wustl.edu>
11 //=============================================================================
18 #include "icp.h" // mine
22 #include "tao/PortableServer/PortableServer.h"
23 #include "tao/PortableServer/ServantLocatorC.h"
27 // The following headers are #included automatically by ACE+TAO.
28 // Therefore, they don't need to be included explicitly.
30 //#include <corba/poaS.h>
32 class Controller_impl
;
34 class Thermometer_impl
: public virtual POA_CCS::Thermometer
38 virtual CCS::ModelType
model ();
39 virtual CCS::AssetType
asset_num ();
40 virtual CCS::TempType
temperature ();
41 virtual CCS::LocType
location ();
42 virtual void location (const char *loc
);
43 virtual void remove ();
45 // Constructor & destructor
46 Thermometer_impl (CCS::AssetType anum
);
47 virtual ~Thermometer_impl ();
49 static Controller_impl
* m_ctrl
; // My controller
50 const CCS::AssetType m_anum
; // My asset number
54 CCS::ModelType
get_model ();
55 CCS::TempType
get_temp ();
56 CCS::LocType
get_loc ();
57 void set_loc (const char * new_loc
);
59 // Copy and assignment not supported
60 Thermometer_impl (const Thermometer_impl
&);
61 void operator= (const Thermometer_impl
&);
64 class Thermostat_impl
: public virtual POA_CCS::Thermostat
,
65 public virtual Thermometer_impl
69 virtual CCS::TempType
get_nominal ();
70 virtual CCS::TempType
set_nominal (CCS::TempType new_temp
);
72 // Constructor and destructor
73 Thermostat_impl (CCS::AssetType anum
);
74 virtual ~Thermostat_impl ();
78 CCS::TempType
get_nominal_temp ();
79 CCS::TempType
set_nominal_temp (CCS::TempType new_temp
);
81 // Copy and assignment not supported
82 Thermostat_impl (const Thermostat_impl
&);
83 void operator= (const Thermostat_impl
&);
86 class Controller_impl
: public virtual POA_CCS::Controller
90 virtual CCS::Controller::ThermometerSeq
* list ();
92 find (CCS::Controller::SearchSeq
& slist
);
93 virtual void change (const CCS::Controller::ThermostatSeq
& tlist
,
95 virtual CCS::Thermometer_ptr
96 create_thermometer (CCS::AssetType anum
,
98 virtual CCS::Thermostat_ptr
99 create_thermostat (CCS::AssetType anum
,
103 // Constructor and destructor
104 Controller_impl (PortableServer::POA_ptr poa
,
105 const char * asset_file
);
106 virtual ~Controller_impl ();
108 // Helper functions to allow access to the object map
109 void add_impl (CCS::AssetType anum
,
110 Thermometer_impl
* tip
);
111 void remove_impl (CCS::AssetType anum
);
112 bool exists (CCS::AssetType anum
);
115 // Map of existing assets. The servant pointer is null the
116 // corresponding servant is not in memory.
117 typedef map
<CCS::AssetType
, Thermometer_impl
*> AssetMap
;
120 // POA for thermometers and thermostats
121 PortableServer::POA_var m_poa
;
123 // Name of asset number file
124 CORBA::String_var m_asset_file
;
126 // Copy and assignment not supported
127 Controller_impl (const Controller_impl
&);
128 void operator= (const Controller_impl
&);
130 // Function object for the find_if algorithm to search for
131 // devices by location and model string.
135 StrFinder (CCS::Controller::SearchCriterion sc
,
137 : m_sc (sc
), m_str (str
) {}
138 bool operator () (pair
<const CCS::AssetType
, Thermometer_impl
*> & p
) const
143 case CCS::Controller::LOCATION
:
144 ICP_get (p
.first
, "location", buf
, sizeof (buf
));
146 case CCS::Controller::MODEL
:
147 ICP_get (p
.first
, "model", buf
, sizeof (buf
));
150 assert (0); // Precondition violation
152 return strcmp (buf
, m_str
) == 0;
155 CCS::Controller::SearchCriterion m_sc
;
160 class DeviceLocator_impl
:
161 public virtual PortableServer::ServantLocator
164 DeviceLocator_impl (Controller_impl
* ctrl
);
166 virtual PortableServer::Servant
167 preinvoke (const PortableServer::ObjectId
& oid
,
168 PortableServer::POA_ptr poa
,
169 const char * operation
,
172 postinvoke (const PortableServer::ObjectId
& /*oid*/,
173 PortableServer::POA_ptr
/*poa*/,
174 const char * /*operation*/,
176 PortableServer::Servant
/*servant*/) {}
178 Controller_impl
* m_ctrl
;
180 typedef list
<Thermometer_impl
*> EvictorQueue
;
181 typedef map
<CCS::AssetType
, EvictorQueue::iterator
>
184 static const unsigned int MAX_EQ_SIZE
;// = 100;
186 ActiveObjectMap m_aom
;
188 // Copy and assignment not supported
189 DeviceLocator_impl (const DeviceLocator_impl
&);
190 void operator= (const DeviceLocator_impl
&);