Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / examples / Advanced / ch_12 / server.h
blobcebda59b7604cc3158022ce4cd960da985966fb1
2 //=============================================================================
3 /**
4 * @file server.h
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
8 * @author Reading
9 * @author MA. Used with permission ofAddison-Wesley.Modified for TAO by Mike Moran <mm4@cs.wustl.edu>
11 //=============================================================================
14 #ifndef server_HH_
15 #define server_HH_
17 #include "CCSS.h"
18 #include "icp.h" // mine
19 #include "assert.h"
20 #include <map>
21 #include <list>
22 #include "tao/PortableServer/PortableServer.h"
23 #include "tao/PortableServer/ServantLocatorC.h"
25 using namespace std;
27 // The following headers are #included automatically by ACE+TAO.
28 // Therefore, they don't need to be included explicitly.
29 //#include <assert.h>
30 //#include <corba/poaS.h>
32 class Controller_impl;
34 class Thermometer_impl : public virtual POA_CCS::Thermometer
36 public:
37 // CORBA attributes
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
52 private:
53 // Helper functions
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
67 public:
68 // CORBA operations
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 ();
76 private:
77 // Helper functions
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
88 public:
89 // CORBA operations
90 virtual CCS::Controller::ThermometerSeq* list ();
91 virtual void
92 find (CCS::Controller::SearchSeq & slist);
93 virtual void change (const CCS::Controller::ThermostatSeq & tlist,
94 CORBA::Short delta);
95 virtual CCS::Thermometer_ptr
96 create_thermometer (CCS::AssetType anum,
97 const char* loc);
98 virtual CCS::Thermostat_ptr
99 create_thermostat (CCS::AssetType anum,
100 const char* loc,
101 CCS::TempType temp);
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);
114 private:
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;
118 AssetMap m_assets;
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.
132 class StrFinder
134 public:
135 StrFinder (CCS::Controller::SearchCriterion sc,
136 const char * str)
137 : m_sc (sc), m_str (str) {}
138 bool operator () (pair<const CCS::AssetType, Thermometer_impl *> & p) const
140 char buf[32];
141 switch (m_sc)
143 case CCS::Controller::LOCATION:
144 ICP_get (p.first, "location", buf, sizeof (buf));
145 break;
146 case CCS::Controller::MODEL:
147 ICP_get (p.first, "model", buf, sizeof (buf));
148 break;
149 default:
150 assert (0); // Precondition violation
152 return strcmp (buf, m_str) == 0;
154 private:
155 CCS::Controller::SearchCriterion m_sc;
156 const char * m_str;
160 class DeviceLocator_impl :
161 public virtual PortableServer::ServantLocator
163 public:
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,
170 void * & cookie);
171 virtual void
172 postinvoke (const PortableServer::ObjectId & /*oid*/,
173 PortableServer::POA_ptr /*poa*/,
174 const char * /*operation*/,
175 void * /*cookie*/,
176 PortableServer::Servant /*servant*/) {}
177 private:
178 Controller_impl * m_ctrl;
180 typedef list<Thermometer_impl *> EvictorQueue;
181 typedef map<CCS::AssetType, EvictorQueue::iterator>
182 ActiveObjectMap;
184 static const unsigned int MAX_EQ_SIZE;// = 100;
185 EvictorQueue m_eq;
186 ActiveObjectMap m_aom;
188 // Copy and assignment not supported
189 DeviceLocator_impl (const DeviceLocator_impl &);
190 void operator= (const DeviceLocator_impl &);
193 #endif