Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) WtServerPusherClient

 

 

 

 

 

 

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

wtserverpusherclient.cpp

 

//---------------------------------------------------------------------------
/*
WtServerPusherClient, client of WtServerPusher
Copyright (C) 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

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict