Merge pull request #2309 from mitza-oci/warnings
[ACE_TAO.git] / TAO / examples / Advanced / ch_8_and_10 / server.h
blob925de61a5b2225916a4f3527474d927f95a87274
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 <map>
20 #include <iostream>
21 #include <assert.h>
23 using namespace std;
25 class Controller_impl;
27 class Thermometer_impl : public virtual POA_CCS::Thermometer {
28 public:
29 // CORBA attributes
30 virtual CCS::ModelType model();
31 virtual CCS::AssetType asset_num();
32 virtual CCS::TempType temperature();
33 virtual CCS::LocType location();
34 virtual void location(const char * loc);
36 // Constructor and destructor
37 Thermometer_impl(CCS::AssetType anum, const char * location);
38 virtual ~Thermometer_impl();
40 static Controller_impl * m_ctrl; // My controller
42 protected:
43 const CCS::AssetType m_anum; // My asset number
45 private:
46 // Helper functions
47 CCS::ModelType get_model();
48 CCS::TempType get_temp();
49 CCS::LocType get_loc();
50 void set_loc(const char * new_loc);
52 // Copy and assignment not supported
53 Thermometer_impl(const Thermometer_impl &);
54 void operator=(const Thermometer_impl &);
57 class Thermostat_impl :
58 public virtual POA_CCS::Thermostat,
59 public virtual Thermometer_impl {
60 public:
61 // CORBA operations
62 virtual CCS::TempType get_nominal();
63 virtual CCS::TempType set_nominal(CCS::TempType new_temp);
65 // Constructor and destructor
66 Thermostat_impl(
67 CCS::AssetType anum,
68 const char * location,
69 CCS::TempType nominal_temp
71 virtual ~Thermostat_impl() {}
73 private:
74 // Helper functions
75 CCS::TempType get_nominal_temp();
76 CCS::TempType set_nominal_temp(CCS::TempType new_temp);
78 // Copy and assignment not supported
79 Thermostat_impl(const Thermostat_impl &);
80 void operator=(const Thermostat_impl &);
83 class Controller_impl : public virtual POA_CCS::Controller {
84 public:
85 // CORBA operations
86 virtual CCS::Controller::ThermometerSeq* list();
87 virtual void find(CCS::Controller::SearchSeq & slist);
88 virtual void change(const CCS::Controller::ThermostatSeq & tlist,
89 CORBA::Short delta);
91 // Constructor and destructor
92 Controller_impl() {}
93 virtual ~Controller_impl() {}
95 // Helper functions to allow thermometers and
96 // thermostats to add themselves to the m_assets map
97 // and to remove themselves again.
98 void add_impl(CCS::AssetType anum, Thermometer_impl * tip);
99 void remove_impl(CCS::AssetType anum);
101 private:
102 // Map of known servants
103 typedef map<CCS::AssetType, Thermometer_impl *> AssetMap;
104 AssetMap m_assets;
106 // Copy and assignment not supported
107 Controller_impl(const Controller_impl &);
108 void operator=(const Controller_impl &);
110 // Function object for the find_if algorithm to search for
111 // devices by location and model string.
112 class StrFinder {
113 public:
114 StrFinder(
115 CCS::Controller::SearchCriterion sc,
116 const char * str
117 ) : m_sc(sc), m_str(str) {}
118 bool operator()(
119 pair<const CCS::AssetType, Thermometer_impl *> & p) const
121 switch (m_sc) {
122 case CCS::Controller::LOCATION:
123 return strcmp(p.second->location(), m_str) == 0;
124 break;
125 case CCS::Controller::MODEL:
126 return strcmp(p.second->model(), m_str) == 0;
127 break;
128 default:
129 assert(0); // Precondition violation
131 return 0; // Stops compiler warning
133 private:
134 CCS::Controller::SearchCriterion m_sc;
135 const char * m_str;
139 #endif