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(_MEDIASTREAM_H_)
00028 #define _MEDIASTREAM_H_
00029
00030 #if _MSC_VER > 1000
00031 #pragma once
00032 #endif // _MSC_VER > 1000
00033
00034 #include "Object.h"
00035 #include "Collections.h"
00036 #include "InfoItem.h"
00037 #include "DataSample.h"
00038 #include "JSemaphore.h"
00039
00040 namespace cmlabs {
00041
00042 class MediaStream : public Object
00043 {
00044 public:
00045 MediaStream(const JString& streamname, long hardMaxSize = -1, long softMaxSize = -1, long maxCount = -1, long maxBackupCount = -1);
00046 virtual ~MediaStream();
00047 Object* clone() const;
00048
00049 JString print() ;
00050
00051 bool handleMultipleWriters(bool allow);
00052
00053 bool addSample(DataSample* sample);
00054 bool addSamples(ObjectCollection* samples, bool deleteCol = true);
00055 bool deleteSample(DataSample* sample);
00056 bool deleteSample(int pos);
00057
00058 bool deleteSampleAt(const JTime& time);
00059 bool deleteSamplesOlderThan(const JTime& time);
00060 bool deleteSamplesNewerThan(const JTime& time);
00061 bool deleteSamplesBetween(const JTime& fromTime, const JTime& toTime);
00062
00063 long getTotalDataSize();
00064 long getTotalDataMemUse();
00065 int getCount();
00066
00067 double getInputDataRate();
00068 double getOutputDataRate();
00069 double getTotalDataEverHandled();
00070 long getTotalCountEverHandled();
00071
00072 JTime getOldestSampleTime();
00073 JTime getNewestSampleTime();
00074 ObjectCollection* getDataSampleList();
00075 ObjectCollection* getTimestampList();
00076
00077 DataSample* getOldestSample();
00078 DataSample* getNewestSample();
00079 DataSample* getSample(const JString& id);
00080 DataSample* getSampleAt(const JTime& time);
00081 DataSample* getFirstSampleAfter(const JString& id);
00082 DataSample* getFirstSampleAfter(const JTime& time);
00083 DataSample* getLastSampleBefore(const JTime& time);
00084 ObjectCollection* getSamplesBetween(const JTime& fromTime, const JTime& toTime);
00085
00086 DataSample* waitForFirstSampleAfter(const JTime& time, long ms);
00087 DataSample* waitForLastSampleAfter(const JTime& time, long ms);
00088 DataSample* waitForFirstSampleAfter(const JString& id, long ms);
00089 DataSample* waitForLastSampleAfter(const JString& id, long ms);
00090
00091 bool createChannel(const JString& name, const JString& fieldname);
00092 bool destroyChannel(const JString& name);
00093 ObjectCollection* searchChannel(const JString& name, double val1, double val2);
00094
00095 InfoItem* getInfo();
00096
00097 bool doMaintenance();
00098
00099 protected:
00100
00101 bool addChannelSample(DataSample* sample);
00102 bool removeChannelSample(DataSample* sample);
00103
00104
00105
00106
00107 ObjectTable dataSamples;
00108 JTime lastAccessTime;
00109 ObjectCollection deletedSamples;
00110
00111 Dictionary channelNames;
00112 ObjectDictionary channels;
00113
00114 JSemaphore newDataSem;
00115 JMutex accessMutex;
00116
00117 JString name;
00118 long softMax;
00119 long hardMax;
00120 long maxCount;
00121 long maxBackupCount;
00122 long currentSize;
00123
00124 bool allowMultipleWriters;
00125 double bytesEverHandled;
00126 long countEverHandled;
00127 ObjectTable outputData;
00128 };
00129
00130 }
00131
00132 #endif //_MEDIASTREAM_H_
00133