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 #if !defined(_MEDIASERVER_H_)
00028 #define _MEDIASERVER_H_
00029
00030 #include "MediaStream.h"
00031 #include "Network.h"
00032 #include "InfoItem.h"
00033 #include "NetworkConnection.h"
00034
00035 namespace cmlabs {
00036
00037 class SubscriptionEntry : public Object {
00038 public:
00039 SubscriptionEntry(const JString& channel, double val1, double val2) {
00040 this->channel = channel;
00041 this->val1 = val1;
00042 this->val2 = val2;
00043 }
00044 bool equals(const Object* o2) const {
00045 if ((o2 == NULL) || (!isSameClass(o2))) return false;
00046 SubscriptionEntry* entry = (SubscriptionEntry*) o2;
00047 return ((channel.equalsIgnoreCase(entry->channel)) && (val1 == entry->val1) && (val2 == entry->val2));
00048 }
00049 unsigned long getHash() const {
00050 return channel.getHash();
00051 }
00052 Object* clone() const {return new SubscriptionEntry(channel, val1, val2);}
00053 double val1, val2;
00054 JString channel;
00055 };
00056
00057 class MediaServer : public Object, public JThread, public TCPReceiver
00058 {
00059 public:
00060 MediaServer(const JString& servername, long hardMaxSize = -1, long softMaxSize = -1, long maxCount = -1, long maxBackupCount = -1);
00061 virtual ~MediaServer();
00062 Object* clone() const;
00063 bool unitTest();
00064
00065
00066
00067 bool init(int port);
00068 void run();
00069
00070 bool handleMultipleWriters(bool allow);
00071
00072 TCPLocation getLocation();
00073
00074 JString getName();
00075 Message* netObjectReceive(Message *msg, NetworkConnection *con);
00076 HTMLPage* serveHTTPRequest(const JString& origin, HTTPRequest* request);
00077 Message* serveTelnetInput(const JString& id, const JString& origin, const JString& text);
00078
00079 long getTotalDataSize();
00080 long getTotalDataMemUse();
00081 int getCount();
00082 double getInputDataRate();
00083 double getOutputDataRate();
00084 double getTotalDataEverHandled();
00085 int getConnectionCount();
00086 ConnectionProfile getConnectionProfile(const JString& client);
00087 InfoItem* getInfo();
00088 InfoItem* getInfoAllStats();
00089
00090
00091
00092 JTime getOldestTimestamp();
00093 JTime getNewestTimestamp();
00094 ObjectCollection* getDataSampleList();
00095
00096
00097 DataSample* getOldestSample(const JString& clientname);
00098 DataSample* getNewestSample(const JString& clientname);
00099 DataSample* getDataSample(const JString& clientname, const JTime& time);
00100 DataSample* getDataSample(const JTime& time);
00101 ObjectCollection* getDataSamples(const JString& clientname, const JTime& t1, const JTime& t2);
00102 ObjectCollection* getDataSamples(const JTime& t1, const JTime& t2);
00103
00104
00105
00106 bool addDataSample(const JString& clientname, DataSample* sample);
00107 bool addDataSample(DataSample* sample);
00108
00109 bool addDataSamples(const JString& clientname, ObjectCollection* samples);
00110 bool addDataSamples(ObjectCollection* samples);
00111
00112 DataSample* waitForFirstSampleAfter(const JString& clientname, const JTime& time, long ms);
00113 DataSample* waitForFirstSampleAfter(const JTime& time, long ms);
00114 DataSample* waitForLastSampleAfter(const JString& clientname, const JTime& time, long ms);
00115 DataSample* waitForLastSampleAfter(const JTime& time, long ms);
00116 DataSample* waitForSampleAt(const JString& clientname, const JTime& time, long ms);
00117 DataSample* waitForSampleAt(const JTime& time, long ms);
00118
00119 DataSample* getSample(const JString& clientname, const JString& id);
00120 DataSample* getFirstSampleAfter(const JString& clientname, const JString& id);
00121 DataSample* waitForFirstSampleAfter(const JString& clientname, const JString& id, long ms);
00122 DataSample* waitForLastSampleAfter(const JString& clientname, const JString& id, long ms);
00123 DataSample* getSample(const JString& id);
00124 DataSample* getFirstSampleAfter(const JString& id);
00125 DataSample* waitForFirstSampleAfter(const JString& id, long ms);
00126 DataSample* waitForLastSampleAfter(const JString& id, long ms);
00127
00128 ObjectDictionary serverProfiles;
00129 ObjectDictionary serverNetworkProfiles;
00130
00131
00132 bool createChannel(const JString& name, const JString& fieldname);
00133 bool destroyChannel(const JString& name);
00134 ObjectCollection* searchChannel(const JString& name, double val1, double val2);
00135 bool subscribeChannel(const JString& connection, const JString& channel, double val1, double val2);
00136 bool unsubscribeChannel(const JString& connection, const JString& channel, double val1, double val2);
00137 bool unsubscribeChannel(const JString& connection, SubscriptionEntry* entry);
00138 bool unsubscribeAllChannels(const JString& connection);
00139 bool subscriptionMatch(ObjectCollection* subs, DataSample* sample);
00140 ObjectDictionary directSubscribers;
00141
00142 protected:
00143
00144 JString name;
00145 MediaStream* mediaStream;
00146 Network* network;
00147 bool shouldContinue;
00148 ObjectCollection continuousCons;
00149 JTime lastContinuousSend;
00150
00151 ObjectDictionary subscriptions;
00152
00153 bool addDataStat(const JString& name, long upbytes, long downbytes, const JTime& time = JTime());
00154
00155 };
00156
00157
00158
00159 class MediaTestServer : public JThread
00160 {
00161 public:
00162 MediaTestServer(const JString& servername, int expectedConnections, bool continuous = false);
00163 virtual ~MediaTestServer();
00164
00165 bool init(int testport);
00166 void run();
00167 bool isTestComplete();
00168 TCPLocation getLocation();
00169
00170 protected:
00171 bool isContinuous;
00172 int numCons;
00173 MediaServer* mediaServer;
00174 };
00175
00176 MediaTestServer* createMediaTestServer(int& port, const JString& name, int count, bool continuous);
00177 bool runMediaTestClient(const JString& name, const JString& host, int testport);
00178 bool runMediaTestClient(const JString& name, const TCPLocation& loc);
00179
00180 }
00181
00182 #endif //_MEDIASERVER_H_
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197