00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #ifndef PLAYERCLIENT_H
00045 #define PLAYERCLIENT_H
00046
00047 #include "libplayerc++/utility.h"
00048 #include "libplayerc++/playerc++config.h"
00049
00050 #include <string>
00051 #include <list>
00052
00053 #if defined (WIN32)
00054 #if defined (PLAYER_STATIC)
00055 #define PLAYERCC_EXPORT
00056 #elif defined (playerc___EXPORTS)
00057 #define PLAYERCC_EXPORT __declspec (dllexport)
00058 #else
00059 #define PLAYERCC_EXPORT __declspec (dllimport)
00060 #endif
00061 #else
00062 #define PLAYERCC_EXPORT
00063 #endif
00064
00065 #ifdef HAVE_BOOST_SIGNALS
00066 #include <boost/signal.hpp>
00067 #endif
00068
00069 #ifdef HAVE_BOOST_THREAD
00070 #include <boost/thread/mutex.hpp>
00071 #include <boost/thread/thread.hpp>
00072 #include <boost/thread/xtime.hpp>
00073 #include <boost/bind.hpp>
00074 #else
00075
00076
00077
00078 namespace boost
00079 {
00080 class PLAYERCC_EXPORT thread
00081 {
00082 public:
00083 thread() {};
00084 };
00085
00086 class PLAYERCC_EXPORT mutex
00087 {
00088 public:
00089 mutex() {};
00090 class scoped_lock
00091 {
00092 public: scoped_lock(mutex ) {};
00093 };
00094 };
00095 }
00096
00097 #endif
00098
00099 namespace PlayerCc
00100 {
00101
00102 class ClientProxy;
00103
00115 class PLAYERCC_EXPORT PlayerClient
00116 {
00117 friend class ClientProxy;
00118
00119
00120 typedef boost::thread thread_t;
00121
00122
00123 typedef boost::mutex mutex_t;
00124
00125 private:
00126
00127 std::list<PlayerCc::ClientProxy*> mProxyList;
00128
00129 std::list<playerc_device_info_t> mDeviceList;
00130
00131
00132
00133 void Connect(const std::string aHostname, uint32_t aPort);
00134
00135
00136 void Disconnect();
00137
00138
00139 playerc_client_t* mClient;
00140
00141
00142 std::string mHostname;
00143
00144
00145 uint32_t mPort;
00146
00147
00148 unsigned int mTransport;
00149
00150
00151 bool mIsStop;
00152
00153
00154 thread_t* mThread;
00155
00156
00157 void RunThread();
00158
00159 public:
00160
00162 PlayerClient(const std::string aHostname=PLAYER_HOSTNAME,
00163 uint32_t aPort=PLAYER_PORTNUM,
00164 int transport=PLAYERC_TRANSPORT_TCP);
00165
00167 ~PlayerClient();
00168
00170 bool Connected() { return (NULL!=mClient && mClient->connected == 1) ? true : false; }
00171
00173 mutex_t mMutex;
00174
00175
00176
00177
00178
00180 void StartThread();
00181
00183 void StopThread();
00184
00186 void Run(uint32_t aTimeout=10);
00187
00189 void Stop();
00190
00197 bool Peek(uint32_t timeout=0);
00198
00199
00201 void SetRequestTimeout(uint32_t seconds) { playerc_client_set_request_timeout(this->mClient,seconds); }
00202
00203
00207 void SetRetryLimit(int limit) { playerc_client_set_retry_limit(this->mClient,limit); }
00208
00211 int GetRetryLimit() { return(this->mClient->retry_limit); }
00212
00215 void SetRetryTime(double time) { playerc_client_set_retry_time(this->mClient,time); }
00216
00219 double GetRetryTime() { return(this->mClient->retry_time); }
00220
00228 void Read();
00229
00234 void ReadIfWaiting();
00235
00236
00237
00238
00239
00240
00241
00242
00243
00256 void SetDataMode(uint32_t aMode);
00257
00274 void SetReplaceRule(bool aReplace,
00275 int aType = -1,
00276 int aSubtype = -1,
00277 int aInterf = -1);
00278
00281 void RequestDeviceList();
00282
00283 std::list<playerc_device_info_t> GetDeviceList();
00284
00286 std::string GetHostname() const { return(mHostname); };
00287
00289 uint32_t GetPort() const { return(mPort); };
00290
00292 int LookupCode(std::string aName) const;
00293
00295 std::string LookupName(int aCode) const;
00296
00298 uint32_t GetOverflowCount();
00299 };
00300
00301
00302
00303 }
00304
00305 namespace std
00306 {
00307 PLAYERCC_EXPORT std::ostream& operator << (std::ostream& os, const PlayerCc::PlayerClient& c);
00308 }
00309
00310 #endif
00311