(C++) WtServerPusherClient
January 25, 2018 · View on GitHub
(C++) WtServerPusherClient
Technical facts
Operating system(s) or programming environment(s)
Lubuntu 11.04 (natty)
Qt Creator 2.0.1
- G++ 4.5.2
Libraries used:
wtserverpusherclient.cpp
//--------------------------------------------------------------------------- /* WtServerPusherClient, client of WtServerPusher Copyright 2011 Richel Bilderbeek This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ //--------------------------------------------------------------------------- //From http://www.richelbilderbeek.nl/CppWtServerPusherClient.htm //--------------------------------------------------------------------------- #include <boost/bind.hpp> //--------------------------------------------------------------------------- #include <Wt/WApplication> //--------------------------------------------------------------------------- #include "wtserverpusher.h" #include "wtserverpusherclient.h" //--------------------------------------------------------------------------- WtServerPusherClient::WtServerPusherClient() { Wt::WApplication::instance()->enableUpdates(true); WtServerPusher::GetInstance()->Connect( this,boost::bind(&WtServerPusherClient::OnServer,this)); //Never call virtual functions during construction or destroyion //Scott Meyers, Effective C++, item 9 //OnServer(); } //--------------------------------------------------------------------------- WtServerPusherClient::~WtServerPusherClient() { Wt::WApplication::instance()->enableUpdates(false); WtServerPusher::GetInstance()->Disconnect(this); } //--------------------------------------------------------------------------- const std::string WtServerPusherClient::GetVersion() { return "1.0"; } //--------------------------------------------------------------------------- const std::vector<std::string> WtServerPusherClient::GetVersionHistory() { std::vector<std::string> v; v.push_back("2011-07-27: version 1.0: initial version"); return v; } //--------------------------------------------------------------------------- void WtServerPusherClient::OnServer() { OnServerPush(); Wt::WApplication::instance()->triggerUpdate(); } //---------------------------------------------------------------------------
wtserverpusherclient.h
//--------------------------------------------------------------------------- #ifndef WTSERVERPUSHERCLIENT_H #define WTSERVERPUSHERCLIENT_H //--------------------------------------------------------------------------- #include <string> #include <vector> //--------------------------------------------------------------------------- ///WtServerPusherClient is a client responding to WtServerPusher ///and to be used as a base class struct WtServerPusherClient { virtual ~WtServerPusherClient(); ///Get the version of this class static const std::string GetVersion(); ///Get the version history of this class static const std::vector<std::string> GetVersionHistory(); ///OnServerPush is called when the WtServerPusher is posted to virtual void OnServerPush() = 0; protected: ///WtServerPusherClient constructor is protected ///because it is to be used as a base class WtServerPusherClient(); private: ///Respond to the server void OnServer(); }; //--------------------------------------------------------------------------- #endif // WTSERVERPUSHERCLIENT_H