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

cygnal.h

Go to the documentation of this file.
00001 // 
00002 //   Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010 Free Software
00003 //   Foundation, Inc
00004 // 
00005 // This program is free software; you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation; either version 3 of the License, or
00008 // (at your option) any later version.
00009 // 
00010 // This program is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 // 
00015 // You should have received a copy of the GNU General Public License
00016 // along with this program; if not, write to the Free Software
00017 // Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00018 
00019 #ifndef __CYGNAL_H__
00020 #define __CYGNAL_H__
00021 
00022 #include <boost/cstdint.hpp>
00023 #include <boost/shared_ptr.hpp>
00024 #include <boost/thread/mutex.hpp>
00025 #include <vector>
00026 #include <string>
00027 #include <map>
00028 
00029 #include "extension.h"
00030 #include "handler.h"
00031 
00036 namespace cygnal {    
00037 
00039     
00040 class Cygnal
00041 {
00042 public:
00043     typedef Handler::cygnal_init_t (*initentry_t)();
00044     
00045     typedef struct {
00046         std::string hostname;
00047         short       port;
00048         bool        connected;
00049         int         fd;
00050         gnash::Network::protocols_supported_e protocol;
00051         std::vector<std::string> supported;
00052     } peer_t;
00053     static Cygnal& getDefaultInstance();
00054     ~Cygnal();
00055 
00056     bool loadPeersFile();
00057     bool loadPeersFile(const std::string &filespec);
00058 
00059     void probePeers();
00060     void probePeers(peer_t &peer);
00061     void probePeers(boost::shared_ptr<peer_t> peer);
00062     void probePeers(std::vector<boost::shared_ptr<peer_t> > &peers);
00063 
00064     void addHandler(const std::string &path, boost::shared_ptr<Handler> x) {
00065         _handlers[path] = x;
00066     };
00067 
00068     boost::shared_ptr<Handler> findHandler(const std::string &path);
00069     void removeHandler(const std::string &path);
00070 
00071     std::vector<boost::shared_ptr<peer_t> > & getActive() { return _active_peers; };
00072 
00073     void dump();
00074 
00075 private:
00076     void addPeer(boost::shared_ptr<peer_t> x) {
00077         _peers.push_back(x);
00078     };
00079 
00080     std::vector<boost::shared_ptr<peer_t> > _peers;
00081     std::vector<boost::shared_ptr<peer_t> > _active_peers;
00082     std::map<std::string, boost::shared_ptr<Handler> > _handlers;
00083     boost::mutex _mutex;
00084 };
00085 
00089 class ThreadCounter
00090 {
00091 public:
00092 
00093     ThreadCounter() : _tids(0) {};
00094     void increment() { boost::mutex::scoped_lock lk(_tid_mutex); ++_tids; };
00095     void decrement() { boost::mutex::scoped_lock lk(_tid_mutex); --_tids; };
00096     int num_of_tids() { return _tids; };
00097 private:
00098     boost::mutex  _tid_mutex;
00099     int           _tids;
00100     boost::thread _tid_handle;
00101 };
00102   
00103 // End of gnash namespace 
00104 }
00105 
00106 // __CYGNAL_H__
00107 #endif
00108 
00109 
00110 // local Variables:
00111 // mode: C++
00112 // indent-tabs-mode: t
00113 // End:

Generated on Thu Sep 30 2010 14:34:57 for Gnash by  doxygen 1.7.1