#ifndef C81E1B2C_54AF_4E7D_800B_F21E0DACFD8B #define C81E1B2C_54AF_4E7D_800B_F21E0DACFD8B /* ******************************************************************************* * INCLUDE ******************************************************************************* */ #include #include #include #include #include namespace Util { /* ******************************************************************************* * CLASS DECLARE ******************************************************************************* */ class Intent { public: using Ptr = Poco::SharedPtr; template Intent& putExtra(const std::string& key, const T& value); Intent& putExtra(const std::string& key, const char* value); template const T getExtra(const std::string& key) const; const std::string& getAction() const; void setAction(const std::string& action); private: using Value = Poco::Any; using Values = std::unordered_map; Values _values; std::string _action; }; template inline Intent& Intent::putExtra(const std::string& key, const T& value) { _values[key] = value; return *this; } template inline const T Intent::getExtra(const std::string& key) const { if (_values.find(key) == _values.end()) throw Poco::NotFoundException(Poco::format("Intent: Can't find value: %s", key), -ENODATA); return Poco::AnyCast(_values.at(key)); } inline const std::string& Intent::getAction() const { return _action; } inline void Intent::setAction(const std::string& action) { _action = action; } /* ******************************************************************************* * CLASS DECLARE ******************************************************************************* */ class IntentFilter { public: using Ptr = Poco::SharedPtr; void addAction(const std::string& action); bool match(Intent::Ptr pIntent) const; private: std::vector _actions; }; /* ******************************************************************************* * CLASS DECLARE ******************************************************************************* */ class BroadcastReceiver { public: virtual void onReceive(Intent::Ptr pIntent) = 0; }; /* ******************************************************************************* * CLASS DECLARE ******************************************************************************* */ class BroadcastSender { public: void sendBroadcast(Intent::Ptr pIntent); }; /* ******************************************************************************* * CLASS DECLARE ******************************************************************************* */ class BroadcastReceiverRegistry { public: void registerReceiver(BroadcastReceiver& receiver, IntentFilter::Ptr pFilter); void unregisterReceiver(BroadcastReceiver& receiver); }; } #endif