Changes to attempt to silence bcc64x
[ACE_TAO.git] / TAO / examples / Advanced / ch_18 / server.h
blobd3c9e58be7e1a3f45e3b9e4c90c281ec3c84a676
1 //=============================================================================
2 /**
3 * @file server.h
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
7 * @author Reading
8 * @author MA.Modified for TAO by Mike Moran <mm4@cs.wustl.edu>
9 */
10 //=============================================================================
15 #ifndef server_HH_
16 #define server_HH_
18 #include "CCSS.h"
19 #include "icp.h"
20 #include <map>
21 #include <list>
22 #include <assert.h>
23 #include "tao/PortableServer/PortableServer.h"
24 #include "tao/PortableServer/ServantLocatorC.h"
26 using namespace std;
28 class Controller_impl;
30 class Thermometer_impl : public virtual POA_CCS::Thermometer {
31 public:
32 // CORBA attributes
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
47 private:
48 // Helper functions
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 {
62 public:
63 // CORBA operations
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();
71 private:
72 // Helper functions
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 {
82 public:
83 // CORBA operations
84 virtual CCS::Controller::ThermometerSeq* list();
85 virtual void find(CCS::Controller::SearchSeq & slist);
86 virtual void change(const CCS::Controller::ThermostatSeq & tlist,
87 CORBA::Short delta);
88 virtual CCS::Thermometer_ptr
89 create_thermometer(
90 CCS::AssetType anum,
91 const char* loc
93 virtual CCS::Thermostat_ptr
94 create_thermostat(
95 CCS::AssetType anum,
96 const char* loc,
97 CCS::TempType temp
100 // Constructor and destructor
101 Controller_impl(
102 PortableServer::POA_ptr poa,
103 const char * asset_file
105 virtual ~Controller_impl();
107 // Helper functions to allow access to the object map
108 void add_impl(
109 CCS::AssetType anum,
110 Thermometer_impl * tip
112 void remove_impl(CCS::AssetType anum);
113 bool exists(CCS::AssetType anum);
115 private:
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;
119 AssetMap m_assets;
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.
133 class StrFinder {
134 public:
135 StrFinder(
136 CCS::Controller::SearchCriterion sc,
137 const char * str
138 ) : m_sc(sc), m_str(str) {}
139 bool operator()(
140 pair<const CCS::AssetType, Thermometer_impl *> & p) const
142 char buf[32];
143 switch (m_sc) {
144 case CCS::Controller::LOCATION:
145 ICP_get(p.first, "location", buf, sizeof(buf));
146 break;
147 case CCS::Controller::MODEL:
148 ICP_get(p.first, "model", buf, sizeof(buf));
149 break;
150 default:
151 assert(0); // Precondition violation
153 return strcmp(buf, m_str) == 0;
155 private:
156 CCS::Controller::SearchCriterion m_sc;
157 const char * m_str;
161 class DeviceLocator_impl :
162 public virtual PortableServer::ServantLocator {
163 public:
164 DeviceLocator_impl(Controller_impl * ctrl);
166 virtual PortableServer::Servant
167 preinvoke(
168 const PortableServer::ObjectId & oid,
169 PortableServer::POA_ptr poa,
170 const char * operation,
171 void * & cookie);
173 virtual void
174 postinvoke(
175 const PortableServer::ObjectId & /* oid */,
176 PortableServer::POA_ptr /* poa */,
177 const char * /* operation */,
178 void * /* cookie */,
179 PortableServer::Servant /* servant */) {}
181 private:
182 Controller_impl * m_ctrl;
184 typedef list<Thermometer_impl *> EvictorQueue;
185 typedef map<CCS::AssetType, EvictorQueue::iterator>
186 ActiveObjectMap;
188 static const unsigned int MAX_EQ_SIZE;// = 100;
189 EvictorQueue m_eq;
190 ActiveObjectMap m_aom;
192 // Copy and assignment not supported
193 DeviceLocator_impl(const DeviceLocator_impl &);
194 void operator=(const DeviceLocator_impl &);
197 #endif