summaryrefslogtreecommitdiff
path: root/src/components/application_manager/include/application_manager/event_engine
diff options
context:
space:
mode:
authorJustin Dickow <jjdickow@gmail.com>2014-10-20 17:44:41 -0400
committerJustin Dickow <jjdickow@gmail.com>2014-10-20 17:44:41 -0400
commit34e7256493ff0e6594029b9857d7e2aa31f5dbeb (patch)
tree367306b507c52d3af211533810adbc22004e0192 /src/components/application_manager/include/application_manager/event_engine
parent2eef966e9b5fd4d94dd98820095eb765e200c64b (diff)
downloadsdl_core-34e7256493ff0e6594029b9857d7e2aa31f5dbeb.tar.gz
SDL 3.8!
Signed-off-by: Justin Dickow <jjdickow@gmail.com>
Diffstat (limited to 'src/components/application_manager/include/application_manager/event_engine')
-rw-r--r--src/components/application_manager/include/application_manager/event_engine/event.h147
-rw-r--r--src/components/application_manager/include/application_manager/event_engine/event_dispatcher.h117
-rw-r--r--src/components/application_manager/include/application_manager/event_engine/event_observer.h116
3 files changed, 380 insertions, 0 deletions
diff --git a/src/components/application_manager/include/application_manager/event_engine/event.h b/src/components/application_manager/include/application_manager/event_engine/event.h
new file mode 100644
index 0000000000..e76b767f17
--- /dev/null
+++ b/src/components/application_manager/include/application_manager/event_engine/event.h
@@ -0,0 +1,147 @@
+/*
+ Copyright (c) 2013, Ford Motor Company
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided with the
+ distribution.
+
+ Neither the name of the Ford Motor Company nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_EVENT_H_
+#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_EVENT_H_
+
+#include <interfaces/HMI_API.h>
+
+#include "smart_objects/smart_object.h"
+#include "application_manager/smart_object_keys.h"
+
+namespace application_manager {
+namespace event_engine {
+
+namespace smart_objects = NsSmartDeviceLink::NsSmartObjects;
+
+class Event {
+ public:
+
+ // Typedef for possible Event ID's from mobile_apis functionID enum
+ typedef hmi_apis::FunctionID::eType EventID;
+
+ /*
+ * @brief Constructor with parameters
+ *
+ * @param id Event ID. Please see mobile_apis::FunctionID for possible ID's
+ */
+ explicit Event(const EventID& id);
+
+ /*
+ * @brief Destructor
+ */
+ virtual ~Event();
+
+ /*
+ * @brief Sends synchronously event to all subscribers.
+ *
+ */
+ void raise();
+
+ /*
+ * @brief Provides event ID
+ */
+ inline const EventID& id() const;
+
+ /*
+ * @brief Sets event smart object
+ *
+ * @param so The smart_object received in HMI response
+ */
+ void set_smart_object(smart_objects::SmartObject& so);
+
+ /*
+ * @brief Retrieves event smart object
+ *
+ * @return The smart_object received in HMI response
+ */
+ inline const smart_objects::SmartObject& smart_object() const;
+
+ /*
+ * @brief Retrieves smart object request ID
+ */
+ inline int32_t smart_object_function_id() const;
+
+ /*
+ * @brief Retrieves smart object correlation ID
+ */
+ inline int32_t smart_object_correlation_id() const;
+
+ /*
+ * @brief Retrieves smart_object response type
+ */
+ inline int32_t smart_object_type() const;
+
+ protected:
+
+ private:
+
+ EventID id_;
+ smart_objects::SmartObject response_so_;
+
+ /*
+ * @brief Default constructor
+ *
+ * Unimplemented to avoid misusing
+ */
+ Event();
+
+ DISALLOW_COPY_AND_ASSIGN(Event);
+};
+
+const Event::EventID& Event::id() const {
+ return id_;
+}
+
+const smart_objects::SmartObject& Event::smart_object() const {
+ return response_so_;
+}
+
+int32_t Event::smart_object_function_id() const {
+ return response_so_.getElement(
+ strings::params).getElement(strings::function_id).asInt();
+}
+
+int32_t Event::smart_object_correlation_id() const {
+ return response_so_.getElement(
+ strings::params).getElement(strings::correlation_id).asInt();
+}
+
+int32_t Event::smart_object_type() const {
+ return response_so_.getElement(
+ strings::params).getElement(strings::message_type).asInt();
+}
+
+}
+}
+
+#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_EVENT_H_
diff --git a/src/components/application_manager/include/application_manager/event_engine/event_dispatcher.h b/src/components/application_manager/include/application_manager/event_engine/event_dispatcher.h
new file mode 100644
index 0000000000..875add2828
--- /dev/null
+++ b/src/components/application_manager/include/application_manager/event_engine/event_dispatcher.h
@@ -0,0 +1,117 @@
+/*
+ Copyright (c) 2013, Ford Motor Company
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided with the
+ distribution.
+
+ Neither the name of the Ford Motor Company nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_EVENT_DISPATCHER_H_
+#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_EVENT_DISPATCHER_H_
+
+#include <list>
+#include <map>
+
+#include "utils/lock.h"
+#include "utils/singleton.h"
+
+#include "application_manager/event_engine/event.h"
+
+namespace application_manager {
+namespace event_engine {
+
+class EventObserver;
+
+class EventDispatcher : public utils::Singleton<EventDispatcher> {
+ public:
+
+ /*
+ * @brief Delivers the event to all subscribers
+ *
+ * @param event Received event
+ */
+ void raise_event(const Event& event);
+
+ /*
+ * @brief Subscribe the observer to event
+ *
+ * @param event_id The event ID to subscribe for
+ * @param hmi_correlation_id The event HMI correlation ID
+ * @param observer The observer to subscribe for event
+ */
+ void add_observer(const Event::EventID& event_id,
+ int32_t hmi_correlation_id,
+ EventObserver* const observer);
+
+ /*
+ * @brief Unsubscribes the observer from specific event
+ *
+ * @param event_id The event ID to unsubscribe from
+ * @param observer The observer to be unsubscribed
+ */
+ void remove_observer(const Event::EventID& event_id,
+ EventObserver* const observer);
+
+ /*
+ * @brief Unsubscribes the observer from all events
+ *
+ * @param observer The observer to be unsubscribed
+ */
+ void remove_observer(EventObserver* const observer);
+
+ protected:
+
+ private:
+
+ /*
+ * @brief Default constructor
+ */
+ EventDispatcher();
+
+ /*
+ * @brief Destructor
+ */
+ virtual ~EventDispatcher();
+
+ DISALLOW_COPY_AND_ASSIGN(EventDispatcher);
+
+ FRIEND_BASE_SINGLETON_CLASS(EventDispatcher);
+
+ // Data types section
+ typedef std::list<EventObserver*> ObserverList;
+ typedef std::map<int32_t, ObserverList> ObserversMap;
+ typedef std::map<Event::EventID, ObserversMap> EventObserverMap;
+
+ // Members section
+ sync_primitives::Lock state_lock_;
+ EventObserverMap observers_;
+};
+
+}
+}
+
+#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_EVENT_DISPATCHER_H_
diff --git a/src/components/application_manager/include/application_manager/event_engine/event_observer.h b/src/components/application_manager/include/application_manager/event_engine/event_observer.h
new file mode 100644
index 0000000000..8631203290
--- /dev/null
+++ b/src/components/application_manager/include/application_manager/event_engine/event_observer.h
@@ -0,0 +1,116 @@
+/*
+ Copyright (c) 2013, Ford Motor Company
+ All rights reserved.
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions are met:
+
+ Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+ Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following
+ disclaimer in the documentation and/or other materials provided with the
+ distribution.
+
+ Neither the name of the Ford Motor Company nor the names of its contributors
+ may be used to endorse or promote products derived from this software
+ without specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_EVENT_OBSERVER_H_
+#define SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_EVENT_OBSERVER_H_
+
+#include <string>
+#include "application_manager/event_engine/event.h"
+#include "application_manager/event_engine/event_dispatcher.h"
+
+namespace application_manager {
+namespace event_engine {
+
+class EventObserver
+{
+ public:
+
+ friend class EventDispatcher;
+
+ // Typedef for possible Observer ID's from mobile_apis functionID enum
+ typedef unsigned long ObserverID;
+
+ /*
+ * @brief Constructor
+ *
+ */
+ EventObserver();
+
+ /*
+ * @brief Destructor
+ */
+ virtual ~EventObserver();
+
+ /**
+ * @brief Retrieves observer unique id
+ *
+ * @return Unique Observer id
+ */
+ inline const ObserverID& id() const;
+
+ /**
+ * @brief Interface method that is called whenever new event received
+ *
+ * @param event The received event
+ */
+ virtual void on_event(const Event& event) = 0;
+
+ protected:
+
+ /*
+ * @brief Subscribe to an event
+ *
+ * @param event_id The event ID to subscribe for
+ * @param hmi_correlation_id The event HMI correlation ID.
+ * If param is omitted, it means subscription for HMI notification
+ */
+ void subscribe_on_event(
+ const Event::EventID& event_id, int32_t hmi_correlation_id = 0);
+
+ /*
+ * @brief Unsubscribes the observer from specific event
+ *
+ * @param event_id The event ID to unsubscribe from
+ */
+ void unsubscribe_from_event(const Event::EventID& event_id);
+
+ /*
+ * @brief Unsubscribes the observer from all events
+ *
+ */
+ void unsubscribe_from_all_events();
+
+ private:
+
+ ObserverID id_;
+
+ DISALLOW_COPY_AND_ASSIGN(EventObserver);
+};
+
+const EventObserver::ObserverID& EventObserver::id() const {
+ return id_;
+}
+
+}
+}
+
+#endif // SRC_COMPONENTS_APPLICATION_MANAGER_INCLUDE_APPLICATION_MANAGER_EVENT_OBSERVER_H_