Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #ifndef __HANDLER_H__
00020 #define __HANDLER_H__ 1
00021
00022 #include <map>
00023 #include <boost/cstdint.hpp>
00024 #include <boost/thread/mutex.hpp>
00025 #include <boost/shared_ptr.hpp>
00026 #include <boost/shared_array.hpp>
00027 #include <boost/scoped_ptr.hpp>
00028
00029
00030 #include <vector>
00031 #include <string>
00032
00033 #ifdef HAVE_POLL
00034 # include <sys/poll.h>
00035 #else
00036 # ifdef HAVE_EPOLL
00037 # include <sys/epoll.h>
00038 # endif
00039 #endif
00040
00041 #include "log.h"
00042 #include "network.h"
00043 #include "buffer.h"
00044 #include "element.h"
00045 #include "cque.h"
00046 #include "network.h"
00047 #include "dsodefs.h"
00048 #include "proc.h"
00049
00050 #include "diskstream.h"
00051 #include "sharedlib.h"
00052 #include "extension.h"
00053 #include "diskstream.h"
00054
00055 #include "rtmp.h"
00056 #include "rtmp_msg.h"
00057 #include "http.h"
00058 #include "network.h"
00059
00060
00061 namespace cygnal
00062 {
00063
00064
00065 const size_t STREAMS_BLOCK = 1000;
00066
00067 class Cygnal;
00068 class HTTPServer;
00069 class RTMPServer;
00070
00071 class Handler : public gnash::Extension, gnash::Network
00072 {
00073 public:
00076 typedef enum {
00077 UNKNOWN,
00078 STATUS,
00079 POLL,
00080 HELP,
00081 INTERVAL,
00082 QUIT,
00083 } admin_cmd_e;
00086 typedef enum {
00087 RECORD,
00088 LIVE,
00089 APPEND
00090 } pub_stream_e;
00093 typedef size_t (*cygnal_io_write_t)(boost::uint8_t *data, size_t size);
00094 typedef boost::shared_ptr<cygnal::Buffer> (*cygnal_io_read_t)();
00095 typedef struct {
00096 std::string version;
00097 std::string description;
00098 std::string hostname;
00099 std::string path;
00100 cygnal_io_read_t read_func;
00101 cygnal_io_write_t write_func;
00102 gnash::Network::protocols_supported_e protocol;
00103 } cygnal_init_t;
00104
00107 typedef boost::shared_ptr<cygnal_init_t>(*cygnal_io_init_t)(boost::shared_ptr<gnash::RTMPMsg> &msg);
00108
00109 DSOEXPORT Handler();
00110 ~Handler();
00111
00114 bool sync() { return sync(_in_fd); };
00115 bool sync(int in_fd);
00116
00117
00118 void setName(const std::string &x) { _name = x; };
00119 std::string &getName() { return _name; }
00120
00121
00122
00123 int getActiveDiskStreams() { return _diskstreams.size(); }
00124
00125
00126
00127 boost::shared_ptr<gnash::DiskStream> getDiskStream(int x) { return _diskstreams[x]; }
00128 void setDiskStream(int x, boost::shared_ptr<gnash::DiskStream> y) { _diskstreams[x] = y; }
00129
00131 void addSOL(boost::shared_ptr<cygnal::Element> x) {
00132 _sol.push_back(x);
00133 };
00134
00139 size_t addClient(int fd, gnash::Network::protocols_supported_e proto);
00142 void removeClient(int fd);
00145 std::vector<int> &getClients() { return _clients; };
00149 int getClient(int x) { return _clients[x]; };
00150
00156 int recvMsg(int fd);
00157
00158 gnash::Network::protocols_supported_e getProtocol(int x) { return _protocol[x]; };
00159 void setProtocol(int fd, gnash::Network::protocols_supported_e x) { _protocol[fd] = x; };
00160
00163 size_t addRemote(int x) { _remote.push_back(x); return _remote.size(); };
00164
00165 void setPlugin(boost::shared_ptr<Handler::cygnal_init_t> &init);
00166 void setPlugin(Handler::cygnal_io_read_t read_ptr, Handler::cygnal_io_write_t write_ptr );
00167
00169
00170 boost::shared_ptr<cygnal_init_t> initModule(const std::string& module);
00171
00174 bool initialized();
00175
00177 boost::shared_ptr<cygnal::Buffer> readFromPlugin();
00178
00180 size_t writeToPlugin(cygnal::Buffer &buf) {
00181 return writeToPlugin(buf.begin(), buf.allocated()); };
00182 size_t writeToPlugin(boost::uint8_t *data, size_t size);
00183
00184
00185
00186
00188 double createStream(double transid);
00191 double createStream(double transid, const std::string &filespec);
00192
00195 bool playStream();
00197 bool playStream(const std::string &filespec);
00198
00199
00200 int publishStream();
00201 int publishStream(const std::string &filespec, pub_stream_e op);
00202
00203
00204 int seekStream();
00205 int seekStream(int offset);
00206
00207
00208 int pauseStream(double transid);
00209
00210
00211 boost::shared_ptr<gnash::DiskStream> findStream(const std::string &filespec);
00212
00213
00214 int togglePause(double);
00215
00216
00217 double resumeStream(double transid);
00218
00219
00220 double closeStream(double transid);
00221
00222
00223 double deleteStream(double transid);
00224
00225
00226 void setFCSubscribe(const std::string &x) { _fcsubscribe = x; };
00227 std::string &getFCSubscribe() { return _fcsubscribe; }
00228
00229 #if 1
00230
00231
00232
00233 void setNetConnection(gnash::RTMPMsg *msg) { _netconnect.reset(msg); };
00234 void setNetConnection(boost::shared_ptr<gnash::RTMPMsg> msg) { _netconnect = msg; };
00235 boost::shared_ptr<gnash::RTMPMsg> getNetConnection() { return _netconnect;};
00236 #endif
00237
00238 #if 1
00239 boost::shared_ptr<HTTPServer> &getHTTPHandler(int fd) { return _http[fd]; };
00240 boost::shared_ptr<RTMPServer> getRTMPHandler(int fd) { return _rtmp[fd]; };
00241 #endif
00242
00243
00244
00245
00246 cygnal::Buffer *parseFirstRequest(int fd, gnash::Network::protocols_supported_e proto);
00247
00248 std::string &getKey(int x) { return _keys[x]; };
00249 void setKey(int fd, std::string x) { _keys[fd] = x; };
00250
00251
00252 void dump();
00253
00254 protected:
00257 std::string _name;
00263 int _streams;
00267
00268 std::map<int, boost::shared_ptr<gnash::DiskStream> > _diskstreams;
00272 std::map<int, gnash::Network::protocols_supported_e> _protocol;
00273 #if 1
00274 std::map<int, boost::shared_ptr<HTTPServer> > _http;
00275 std::map<int, boost::shared_ptr<RTMPServer> > _rtmp;
00276 #endif
00277
00278
00279
00280 std::vector<int> _clients;
00284 std::vector<int> _remote;
00285
00289 boost::shared_ptr<cygnal::Proc> _local;
00292 boost::shared_ptr<cygnal_init_t> _plugin;
00295 std::vector<boost::shared_ptr<gnash::DiskStream> > _files;
00298 std::vector<boost::shared_ptr<cygnal::Element> > _sol;
00303 std::map<int, size_t> _bodysize;
00307 int _in_fd;
00308
00312 std::string _fcsubscribe;
00313
00314 #if 1
00315
00316
00317
00318
00319
00320 boost::shared_ptr<gnash::RTMPMsg> _netconnect;
00321 #endif
00322
00323 std::map<int, std::string> _keys;
00324 private:
00325 boost::mutex _mutex;
00326
00327
00328
00329 };
00330
00331 }
00332
00333 #endif // end of __HANDLER_H__
00334
00335
00336
00337
00338