📄 server.h
字号:
#ifndef server_HH_#define server_HH_#include <map>#include <list>#ifdef HAVE_STDLIB_H# include <stdlib.h>#endif#include "CCS_skel.h"class Controller_impl;class Thermometer_impl : public virtual POA_CCS::Thermometer, public virtual PortableServer::RefCountServantBase {public: // IDL attributes virtual CCS::ModelType model() throw(CORBA::SystemException); virtual CCS::AssetType asset_num() throw(CORBA::SystemException); virtual CCS::TempType temperature() throw(CORBA::SystemException); virtual CCS::LocType location() throw(CORBA::SystemException); virtual void location(const char *loc) throw(CORBA::SystemException); virtual void destroy() throw(CORBA::SystemException); // Override _default_POA virtual PortableServer::POA_ptr _default_POA() { return PortableServer::POA::_duplicate(m_poa); } // Allow m_poa member to be set once and to be read static void poa(PortableServer::POA_ptr poa) { if (!CORBA::is_nil(m_poa)) throw "Thermometer_impl::m_poa already set"; m_poa = PortableServer::POA::_duplicate(poa); } static PortableServer::POA_ptr poa() { if (CORBA::is_nil(m_poa)) throw "Thermometer_impl::m_poa not set"; return m_poa; } // Constructor & destructor Thermometer_impl(CCS::AssetType anum); virtual ~Thermometer_impl(); const CCS::AssetType m_anum; // My asset number static Controller_impl * m_ctrl; // My controllerprivate: // Helper functions CCS::ModelType get_model(); CCS::TempType get_temp(); CCS::LocType get_loc(); void set_loc(const char * new_loc); static PortableServer::POA_var m_poa; // My POA // Copy and assignment not supported Thermometer_impl(const Thermometer_impl &); void operator=(const Thermometer_impl &);};class Thermostat_impl : public virtual POA_CCS::Thermostat, public virtual Thermometer_impl {public: // IDL operations virtual CCS::TempType get_nominal() throw(CORBA::SystemException); virtual CCS::TempType set_nominal( CCS::TempType new_temp ) throw( CORBA::SystemException, CCS::Thermostat::BadTemp ); // Override _default_POA virtual PortableServer::POA_ptr _default_POA() { return PortableServer::POA::_duplicate(m_poa); } // Allow m_poa member to be set once and to be read static void poa(PortableServer::POA_ptr poa) { if (!CORBA::is_nil(m_poa)) throw "Thermostat_impl::m_poa already set"; m_poa = PortableServer::POA::_duplicate(poa); } static PortableServer::POA_ptr poa() { if (CORBA::is_nil(m_poa)) throw "Thermostat_impl::m_poa not set"; return m_poa; } // Constructor and destructor Thermostat_impl(CCS::AssetType anum); virtual ~Thermostat_impl();private: // Helper functions CCS::TempType get_nominal_temp(); CCS::TempType set_nominal_temp(CCS::TempType new_temp) throw(CCS::Thermostat::BadTemp); // My POA static PortableServer::POA_var m_poa; // Copy and assignment not supported Thermostat_impl(const Thermostat_impl &); void operator=(const Thermostat_impl &);};class Controller_impl : public virtual POA_CCS::Controller, public virtual PortableServer::RefCountServantBase {public: // IDL operations virtual CCS::Controller::ThermometerSeq * list() throw(CORBA::SystemException); virtual void find(CCS::Controller::SearchSeq & slist) throw(CORBA::SystemException); virtual void change( const CCS::Controller::ThermostatSeq & tlist, CORBA::Short delta ) throw( CORBA::SystemException, CCS::Controller::EChange ); virtual CCS::Thermometer_ptr create_thermometer( CCS::AssetType anum, const char* loc ) throw( CORBA::SystemException, CCS::Controller::DuplicateAsset ); virtual CCS::Thermostat_ptr create_thermostat( CCS::AssetType anum, const char* loc, CCS::TempType temp ) throw( CORBA::SystemException, CCS::Controller::DuplicateAsset, CCS::Thermostat::BadTemp ); // Constructor and destructor Controller_impl(const char * asset_file) throw(int); virtual ~Controller_impl(); // Override _default_POA virtual PortableServer::POA_ptr _default_POA() { return PortableServer::POA::_duplicate(m_poa); } // Allow m_poa member to be set once and to be read static void poa(PortableServer::POA_ptr poa) { if (!CORBA::is_nil(m_poa)) throw "Controller_impl::m_poa already set"; m_poa = PortableServer::POA::_duplicate(poa); } static PortableServer::POA_ptr poa() { if (CORBA::is_nil(m_poa)) throw "Controller_impl::m_poa not set"; return m_poa; } // Helper functions to allow access to the object map void add_impl( CCS::AssetType anum, Thermometer_impl * tip ); void remove_impl(CCS::AssetType anum); bool exists(CCS::AssetType anum);private: // Map of existing assets. The servant pointer is null // the corresponding servant is not in memory. typedef map<CCS::AssetType, Thermometer_impl *> AssetMap; AssetMap m_assets; // Name of asset number file CORBA::String_var m_asset_file; // My POA static PortableServer::POA_var m_poa; // Copy and assignment not supported Controller_impl(const Controller_impl &); void operator=(const Controller_impl &); // Function object for the find_if algorithm to search for // devices by location and model string. class StrFinder { public: StrFinder( CCS::Controller::SearchCriterion sc, const char * str ) : m_sc(sc), m_str(str) {} bool operator()( pair<const CCS::AssetType, Thermometer_impl *> & p ) const { char buf[32]; switch (m_sc) { case CCS::Controller::LOCATION: ICP_get(p.first, "location", buf, sizeof(buf)); break; case CCS::Controller::MODEL: ICP_get(p.first, "model", buf, sizeof(buf)); break; default: abort(); // Precondition violation } return strcmp(buf, m_str) == 0; } private: CCS::Controller::SearchCriterion m_sc; const char * m_str; };};#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -