#ifndef SHARED_HPP #define SHARED_HPP #include #include #include #include class SharedData { public: typedef boost::unique_lock< boost::shared_mutex > writer_lock; typedef boost::shared_lock< boost::shared_mutex > reader_lock; explicit SharedData() { } void set(std::string key, std::string value) { writer_lock lock(mutex_); ndsStatus_[key] = value; } std::string get(std::string key) { reader_lock lock(mutex_); std::string tmp; if(key == "ALL") { std::map::iterator iter; for (iter = ndsStatus_.begin(); iter != ndsStatus_.end(); iter++) { tmp += (*iter).first + " = " + (*iter).second + "\n"; } }else{ if(ndsStatus_.find(key) == ndsStatus_.end()) { tmp += key + " = failed\n"; }else{ tmp += key + " = " + ndsStatus_[key]; } } return tmp; } private: boost::shared_mutex mutex_; std::map ndsStatus_; }; #endif // SHARED_HPP