playerclient.h
00001
00002
00003
00004
00005 #ifndef PLAYERCLIENT_H
00006 #define PLAYERCLIENT_H
00007
00008 #include "libplayerc++/playerc++config.h"
00009 #include "libplayerc++/utility.h"
00010
00011 #include <string>
00012 #include <list>
00013
00014 #ifdef HAVE_BOOST_SIGNALS
00015 #include <boost/signal.hpp>
00016 #include <boost/bind.hpp>
00017 #endif
00018
00019 #ifdef HAVE_BOOST_THREAD
00020 #include <boost/thread/mutex.hpp>
00021 #include <boost/thread/thread.hpp>
00022 #include <boost/thread/xtime.hpp>
00023 #else
00024
00025
00026
00027 namespace boost
00028 {
00029 class thread
00030 {
00031 public:
00032 thread() {};
00033 };
00034
00035 class mutex
00036 {
00037 public:
00038 mutex() {};
00039 class scoped_lock
00040 {
00041 public: scoped_lock(mutex m) {};
00042 };
00043 };
00044 }
00045
00046 #endif
00047
00048 namespace PlayerCc
00049 {
00050
00051 class ClientProxy;
00052
00064 class PlayerClient
00065 {
00066 friend class ClientProxy;
00067
00068
00069 typedef boost::thread thread_t;
00070
00071
00072 typedef boost::mutex mutex_t;
00073
00074 private:
00075
00076 std::list<PlayerCc::ClientProxy*> mProxyList;
00077
00078 std::list<playerc_device_info_t> mDeviceList;
00079
00080
00081
00082 void Connect(const std::string aHostname, uint aPort);
00083
00084
00085 void Disconnect();
00086
00087
00088 playerc_client_t* mClient;
00089
00090
00091 std::string mHostname;
00092
00093
00094 uint mPort;
00095
00096
00097 unsigned int mTransport;
00098
00099
00100 bool mIsStop;
00101
00102
00103 thread_t* mThread;
00104
00105
00106 void RunThread();
00107
00108 public:
00109
00111 PlayerClient(const std::string aHostname=PLAYER_HOSTNAME,
00112 uint aPort=PLAYER_PORTNUM,
00113 int transport=PLAYERC_TRANSPORT_TCP);
00114
00116 ~PlayerClient();
00117
00119 mutex_t mMutex;
00120
00121
00122
00123
00124
00126 void StartThread();
00127
00129 void StopThread();
00130
00132 void Run(uint aTimeout=10);
00133
00135 void Stop();
00136
00143 bool Peek(uint timeout=0);
00144
00148 void SetRetryLimit(int limit) { playerc_client_set_retry_limit(this->mClient,limit); }
00149
00152 int GetRetryLimit() { return(this->mClient->retry_limit); }
00153
00156 void SetRetryTime(double time) { playerc_client_set_retry_time(this->mClient,time); }
00157
00160 double GetRetryTime() { return(this->mClient->retry_time); }
00161
00169 void Read();
00170
00175 void ReadIfWaiting();
00176
00177
00178
00179
00180
00181
00182
00183
00184
00197 void SetDataMode(uint aMode);
00198
00215 void SetReplaceRule(bool aReplace,
00216 int aType = -1,
00217 int aSubtype = -1,
00218 int aInterf = -1);
00219
00222 void RequestDeviceList();
00223
00224 std::list<playerc_device_info_t> GetDeviceList();
00225
00227 std::string GetHostname() const { return(mHostname); };
00228
00230 uint GetPort() const { return(mPort); };
00231
00233 int LookupCode(std::string aName) const;
00234
00236 std::string LookupName(int aCode) const;
00237 };
00238
00239
00240
00241 }
00242
00243 namespace std
00244 {
00245 std::ostream& operator << (std::ostream& os, const PlayerCc::PlayerClient& c);
00246 }
00247
00248 #endif
00249
Last updated 12 September 2005 21:38:45
|