#ifndef OCTOPUS_H #define OCTOPUS_H /* @author Manuel Jung, */ /* #if !defined(NDEBUG) #define BOOST_MULTI_INDEX_ENABLE_INVARIANT_CHECKING #define BOOST_MULTI_INDEX_ENABLE_SAFE_MODE #endif */ #include #include #include #include #include #include #include #include #include #include #include "slots.h" #include "whale.h" #include "shark.h" #include "dolphin.h" #include "diver.h" #include "myconnection.h" using boost::multi_index_container; using namespace boost::multi_index; class octopus : public slot { //Metacrawler private: class thread : public shark, public whale, public dolphin { public: thread(diver::pointer diver_tmp, queue::pointer Queue_tmp); virtual ~thread(); void Call(); }; class arm { public: arm(unsigned int id); ~arm(); unsigned int id; bool free; boost::mutex m_free; boost::condition cond_free; boost::shared_ptr Handle; qoctopus::pointer Query; typedef boost::shared_ptr pointer; }; typedef multi_index_container< arm::pointer, indexed_by< ordered_unique< tag, member >, ordered_non_unique< tag, member >, sequenced > > > arms_set; class arms : public arms_set { public: arms(diver::pointer diver_tmp) : cnt(0), diver_(diver_tmp) {}; virtual ~arms(){}; unsigned int Set(unsigned int setcnt); boost::mutex m; private: unsigned int cnt; diver::pointer diver_; }; typedef arms::index::type arms_by_id; typedef arms::index::type arms_by_free_flag; /*struct slot_free_key:composite_key< slot::pointer, member, mem_fun >{};*/ typedef multi_index_container< slot::pointer, indexed_by< ordered_unique< tag, member > //sequenced > > > slots_set; class slots : public slots_set { public: slots(diver::pointer diver_tmp, queue::pointer Queue_tmp) : diver_(diver_tmp), Queue(Queue_tmp) {}; virtual ~slots(){}; unsigned int Set(unsigned int setcnt); boost::mutex m; private: diver::pointer diver_; queue::pointer Queue; }; typedef slots::index::type slots_by_id; //typedef index::type slots_as_sequence; static size_t WriteCallback(char* ptr, size_t size, size_t nmemb, void* stream) { string* buffer = reinterpret_cast(stream); if (buffer) { buffer->append(ptr, size * nmemb); return size*nmemb; } return 0; } public: octopus(diver::pointer diver_tmp); virtual ~octopus(); typedef boost::shared_ptr pointer; static pointer create(diver::pointer diver_tmp) { return pointer(new octopus(diver_tmp)); } void Start(); void Call(); void AddOpt(cURLpp::OptionBase *Opt); int GetJobs(); void AddJob(arm::pointer Arm); int ReturnCode(int sec, int usec); unsigned int MAX_SLOTS; cURLpp::Multi Requests; cURLpp::Cleanup cleaner; queue::pointer Queue; arms Arms; slots Slots; protected: void DownloadCallback(const cURLpp::Easy* pos, const int ErrCode); private: vector Optlist; int Jobs; }; #endif