Existing code was violating the SOLID principle OCP by being closed for additional events.
To solve this problem, the strategy pattern was applied so that even if new events were added,
the existing business logic remained unchanged and the structure was improved so that new classes could be added.
Change-Id: I386ef353d9a0427dc8e32a89fb1e386a30bafc76
*
* @since_tizen 6.5
*/
- void notify(int type, int type2, void *src) override;
+ void notify(EventType type, void *src) override;
/**
* @brief Changes Node state to invalidate.
/**
* @copydoc @IEventSource::notifyAll()
*/
- void notifyAll(int type1, int type2, void *src) override;
+ void notifyAll(EventType type, void *src) override;
private:
std::set<std::shared_ptr<IEventConsumer>> mSources;
*/
enum class EventType {
none = 0,
- Object = 1,
-};
-
-/**
- * @class ObjectEventType
- *
- * @ingroup aurum
- *
- * @brief Enum class for Object Event Type.
- */
-enum class ObjectEventType {
- none = 0,
- ObjectStateDefunct = 1,
+ ObjectDefunct = 1,
};
/**
/**
* @brief Notifies event to source node.
*
- * @param[in] type1 @EventType
- * @param[in] type2 @ObjectEventType
+ * @param[in] type @EventType
* @param[in] src source Node ptr
*
* @since_tizen 6.5
*/
- virtual void notify(int type1, int type2, void *src) = 0;
+ virtual void notify(EventType type, void *src) = 0;
};
}
/**
* @brief Notifies all attached event.
*
- * @param[in] type1 @EventType
- * @param[in] type2 @ObjectEventType
+ * @param[in] type @EventType
* @param[in] src source Node ptr
*
* @since_tizen 6.5
*/
- virtual void notifyAll(int type1, int type2, void *src) = 0;
+ virtual void notifyAll(EventType type, void *src) = 0;
};
}
using namespace Aurum;
+class Event {
+public:
+
+ Event(std::shared_ptr<AccessibleNode> node)
+ : mNode{node} {}
+
+ virtual ~Event(){};
+ virtual void handleEvent() = 0;
+protected:
+
+ std::shared_ptr<AccessibleNode> mNode;
+};
+
+class ObjectDefunctEvent : public Event {
+public:
+
+ ObjectDefunctEvent(std::shared_ptr<AccessibleNode> node)
+ : Event{node} {}
+
+ virtual ~ObjectDefunctEvent(){};
+ void handleEvent() override {
+ mNode->invalidate();
+ }
+};
+
AccessibleNode::~AccessibleNode()
{
}
return ss.str();
}
-void AccessibleNode::notify(int type1, int type2, void *src)
+void AccessibleNode::notify(EventType type, void *src)
{
- void *handler = getRawHandler();
+ if (src != getRawHandler()) return;
- if ((EventType)type1 == EventType::Object && (ObjectEventType)type2 == ObjectEventType::ObjectStateDefunct) {
- if (handler == src) invalidate();
- }
+ std::unique_ptr<Event> event;
+ if (type == EventType::ObjectDefunct)
+ event = std::make_unique<ObjectDefunctEvent>(this->shared_from_this());
+
+ event->handleEvent();
}
void AccessibleNode::invalidate()
}
}
-void AccessibleWatcher::notifyAll(int type1, int type2, void *src)
+void AccessibleWatcher::notifyAll(EventType type, void *src)
{
std::unique_lock<std::mutex> lock(mLock);
std::for_each(mSources.begin(), mSources.end(), [&](auto source){
- source->notify(type1, type2, src);
+ source->notify(type, src);
});
}
void AtspiAccessibleWatcher::onObjectDefunct(AtspiAccessible *node)
{
LOGI("onObjectDefunct obj:%p", node);
- notifyAll((int)EventType::Object, (int)ObjectEventType::ObjectStateDefunct, node);
+ notifyAll(EventType::ObjectDefunct, node);
}
bool AtspiAccessibleWatcher::executeAndWaitForEvents(const Runnable *cmd, const A11yEvent type, const int timeout, const std::string packageName, std::shared_ptr<AccessibleNode> obj, const int count)