playerclient.h
/*
* Player - One Hell of a Robot Server
* Copyright (C) 2000-2003
* Brian Gerkey, Kasper Stoy, Richard Vaughan, & Andrew Howard
*
*
* 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 2 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, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
/********************************************************************
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library 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
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
********************************************************************/
/*
$Id: playerclient.h 8463 2009-12-16 00:33:35Z gbiggs $
*/
#ifndef PLAYERCLIENT_H
#define PLAYERCLIENT_H
#include "libplayerc++/utility.h"
#include "libplayerc++/playerc++config.h"
#include <string>
#include <list>
#if defined (WIN32)
#if defined (PLAYER_STATIC)
#define PLAYERCC_EXPORT
#elif defined (playerc___EXPORTS)
#define PLAYERCC_EXPORT __declspec (dllexport)
#else
#define PLAYERCC_EXPORT __declspec (dllimport)
#endif
#else
#define PLAYERCC_EXPORT
#endif
#ifdef HAVE_BOOST_SIGNALS
#include <boost/signal.hpp>
#endif
#ifdef HAVE_BOOST_THREAD
#include <boost/thread/mutex.hpp>
#include <boost/thread/thread.hpp>
#include <boost/thread/xtime.hpp>
#include <boost/bind.hpp>
#else
// we have to define this so we don't have to
// comment out all the instances of scoped_lock
// in all the proxies
namespace boost
{
class PLAYERCC_EXPORT thread
{
public:
thread() {};
};
class PLAYERCC_EXPORT mutex
{
public:
mutex() {};
class scoped_lock
{
public: scoped_lock(mutex /*m*/) {};
};
};
}
#endif
namespace PlayerCc
{
class ClientProxy;
class PLAYERCC_EXPORT PlayerClient
{
friend class ClientProxy;
// our thread type
typedef boost::thread thread_t;
// our mutex type
typedef boost::mutex mutex_t;
private:
// list of proxies associated with us
std::list<PlayerCc::ClientProxy*> mProxyList;
std::list<playerc_device_info_t> mDeviceList;
// Connect to the indicated host and port.
// @exception throws PlayerError if unsuccessfull
void Connect(const std::string aHostname, uint32_t aPort);
// Disconnect from server.
void Disconnect();
// our c-client from playerc
playerc_client_t* mClient;
// The hostname of the server, stored for convenience
std::string mHostname;
// The port number of the server, stored for convenience
uint32_t mPort;
// Which transport (TCP or UDP) we're using
unsigned int mTransport;
// Is the thread currently stopped or stopping?
bool mIsStop;
// This is the thread where we run @ref Run()
thread_t* mThread;
// A helper function for starting the thread
void RunThread();
public:
PlayerClient(const std::string aHostname=PLAYER_HOSTNAME,
uint32_t aPort=PLAYER_PORTNUM,
int transport=PLAYERC_TRANSPORT_TCP);
~PlayerClient();
bool Connected() { return (NULL!=mClient && mClient->connected == 1) ? true : false; }
mutex_t mMutex;
// ideally, we'd use the read_write mutex, but I was having some problems
// (with their code) because it's under development
//boost::read_write_mutex mMutex;
void StartThread();
void StopThread();
void Run(uint32_t aTimeout=10); // aTimeout in ms
void Stop();
bool Peek(uint32_t timeout=0);
//bool Peek2(uint32_t timeout=0);
void SetRequestTimeout(uint32_t seconds) { playerc_client_set_request_timeout(this->mClient,seconds); }
void SetRetryLimit(int limit) { playerc_client_set_retry_limit(this->mClient,limit); }
int GetRetryLimit() { return(this->mClient->retry_limit); }
void SetRetryTime(double time) { playerc_client_set_retry_time(this->mClient,time); }
double GetRetryTime() { return(this->mClient->retry_time); }
void Read();
void ReadIfWaiting();
// /// @brief You can change the rate at which your client receives data from the
// /// server with this method. The value of @p freq is interpreted as Hz;
// /// this will be the new rate at which your client receives data (when in
// /// continuous mode).
// ///
// /// @exception throws PlayerError if unsuccessfull
// void SetFrequency(uint32_t aFreq);
void SetDataMode(uint32_t aMode);
void SetReplaceRule(bool aReplace,
int aType = -1,
int aSubtype = -1,
int aInterf = -1);
void RequestDeviceList();
std::list<playerc_device_info_t> GetDeviceList();
std::string GetHostname() const { return(mHostname); };
uint32_t GetPort() const { return(mPort); };
int LookupCode(std::string aName) const;
std::string LookupName(int aCode) const;
uint32_t GetOverflowCount();
};
}
namespace std
{
PLAYERCC_EXPORT std::ostream& operator << (std::ostream& os, const PlayerCc::PlayerClient& c);
}
#endif
PlayerCc::PLAYER_HOSTNAME
const std::string PLAYER_HOSTNAME
The default hostname for PlayerClient.
Definition: utility.h:63
PlayerCc::PlayerClient::SetRequestTimeout
void SetRequestTimeout(uint32_t seconds)
Set the timeout for client requests.
Definition: playerclient.h:201
PlayerCc::limit
T limit(T a, T min, T max)
Limit a value to the range of min, max.
Definition: utility.h:114
PlayerCc::PlayerClient::mMutex
mutex_t mMutex
A mutex for handling synchronization.
Definition: playerclient.h:173
PlayerCc::PlayerClient::GetPort
uint32_t GetPort() const
Returns the port.
Definition: playerclient.h:289
PlayerCc::PlayerClient
The PlayerClient is used for communicating with the player server.
Definition: playerclient.h:115
PlayerCc::PlayerClient::GetRetryTime
double GetRetryTime()
Get connection retry time, which is number of seconds to wait between reconnection attempts...
Definition: playerclient.h:219
PlayerCc::ClientProxy
The client proxy base class.
Definition: clientproxy.h:79
PlayerCc::PLAYER_PORTNUM
const int PLAYER_PORTNUM
The default port number for PlayerClient.
Definition: utility.h:61
boost::thread
Definition: playerclient.h:80
playerc_client_set_request_timeout
PLAYERC_EXPORT void playerc_client_set_request_timeout(playerc_client_t *client, uint32_t seconds)
Set the timeout for client requests.
boost::mutex::scoped_lock
Definition: playerclient.h:90
PlayerCc::PlayerClient::SetRetryLimit
void SetRetryLimit(int limit)
Set connection retry limit, which is the number of times that we'll try to reconnect to the server af...
Definition: playerclient.h:207
PLAYERC_TRANSPORT_TCP
#define PLAYERC_TRANSPORT_TCP
The valid transports.
Definition: playerc.h:114
PlayerCc::PlayerClient::SetRetryTime
void SetRetryTime(double time)
Set connection retry time, which is number of seconds to wait between reconnection attempts...
Definition: playerclient.h:215
playerc_client_set_retry_limit
PLAYERC_EXPORT void playerc_client_set_retry_limit(playerc_client_t *client, int limit)
Set the connection retry limit.
_playerc_client_t
Client object data.
Definition: playerc.h:460
PlayerCc::PlayerClient::GetRetryLimit
int GetRetryLimit()
Get connection retry limit, which is the number of times that we'll try to reconnect to the server af...
Definition: playerclient.h:211
boost::mutex
Definition: playerclient.h:86
playerc_client_set_retry_time
PLAYERC_EXPORT void playerc_client_set_retry_time(playerc_client_t *client, double time)
Set the connection retry sleep time.
PlayerCc::PlayerClient::GetHostname
std::string GetHostname() const
Returns the hostname.
Definition: playerclient.h:286
PlayerCc::PlayerClient::Connected
bool Connected()
Are we currently connected?
Definition: playerclient.h:170

Last updated 12 September 2005 21:38:45