• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • Examples
  • File List
  • File Members

handler.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2008, 2009, 2010 Free Software Foundation, Inc.
00003 // 
00004 // This program is free software; you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation; either version 3 of the License, or
00007 // (at your option) any later version.
00008 // 
00009 // This program is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with this program; if not, write to the Free Software
00016 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
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 //#include <boost/thread/condition.hpp>
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" //For DSOEXPORT.
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 // _definst_ is the default instance name
00061 namespace cygnal
00062 {
00063 
00064 // The number of disk streams in the array.
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     // Access the name field
00118     void setName(const std::string &x) { _name = x; };
00119     std::string &getName() { return _name; }
00120 
00121     // Check the status of active disk streams, which is one less than
00122     // default as the Streams IDs start at 1.
00123     int getActiveDiskStreams() { return _diskstreams.size(); }
00124     // int removeDiskStream(boost::shared_ptr<DiskStream> x);
00125     
00126     // Operate on a disk streaming inprogress
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     // These methods handle control of the file streaming, and are
00185     // used by both HTTP and RTMP*
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     // Publish a live RTMP stream
00200     int publishStream();
00201     int publishStream(const std::string &filespec, pub_stream_e op);
00202 
00203     // Seek within the RTMP stream
00204     int seekStream();
00205     int seekStream(int offset);
00206 
00207     // Pause the RTMP stream
00208     int pauseStream(double transid);
00209 
00210     // Find a stream in the vector or Disk Streams
00211     boost::shared_ptr<gnash::DiskStream> findStream(const std::string &filespec);
00212 
00213     // Pause the RTMP stream
00214     int togglePause(double);
00215 
00216     // Resume the paused RTMP stream
00217     double resumeStream(double transid);
00218 
00219     // Close the RTMP stream
00220     double closeStream(double transid);
00221 
00222     // Delete the RTMP stream
00223     double deleteStream(double transid);
00224 
00225     // This is a site specific identifier of some kind.
00226     void setFCSubscribe(const std::string &x) { _fcsubscribe = x; };
00227     std::string &getFCSubscribe() { return _fcsubscribe; }
00228 
00229 #if 1
00230     // FIXME: This holds the data from the first NetConnection packet,
00231     // and shouldn't really be done here, but we're trying not to
00232     // break things while refactoring.
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     // Parse the first nessages when starting a new message handler,
00244     // which is used to determine the name of the resource to
00245     // initialize, or load from the cache.
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     // Dump internal data.
00252     void dump();
00253     
00254 protected:
00257     std::string _name; 
00263     int         _streams;
00267     //    boost::shared_array<gnash::DiskStream> _diskstreams;
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 // Remote Shared Objects. References are an index into this vector.
00328 //    std::map<std::string, boost::shared_ptr<handler_t> > _handlers;
00329 };
00330 
00331 } // end of gnash namespace
00332 
00333 #endif // end of __HANDLER_H__
00334 
00335 // local Variables:
00336 // mode: C++
00337 // indent-tabs-mode: t
00338 // End:

Generated on Fri Mar 16 2012 15:46:10 for Gnash by  doxygen 1.7.1