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 __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
00104 }
00105
00106
00107 #endif
00108
00109
00110
00111
00112
00113