diff options
Diffstat (limited to 'src/components/functional_module/include/functional_module')
6 files changed, 0 insertions, 794 deletions
diff --git a/src/components/functional_module/include/functional_module/function_ids.h b/src/components/functional_module/include/functional_module/function_ids.h deleted file mode 100644 index 1a504df6c9..0000000000 --- a/src/components/functional_module/include/functional_module/function_ids.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright (c) 2017, 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_FUNCTIONAL_MODULE_INCLUDE_FUNCTIONAL_MODULE_FUNCTION_IDS_H_ -#define SRC_COMPONENTS_FUNCTIONAL_MODULE_INCLUDE_FUNCTIONAL_MODULE_FUNCTION_IDS_H_ -#include "interfaces/MOBILE_API.h" -#include "interfaces/HMI_API.h" - -namespace functional_modules { - -enum RCFunctionID { - // Remote SDL functions ids - BUTTON_PRESS = mobile_apis::FunctionID::ButtonPressID, - GET_INTERIOR_VEHICLE_DATA = mobile_apis::FunctionID::GetInteriorVehicleDataID, - SET_INTERIOR_VEHICLE_DATA = mobile_apis::FunctionID::SetInteriorVehicleDataID, - ON_INTERIOR_VEHICLE_DATA = mobile_apis::FunctionID::OnInteriorVehicleDataID, - ON_REMOTE_CONTROL_SETTINGS = hmi_apis::FunctionID::RC_OnRemoteControlSettings, -}; - -namespace hmi_api { -const char get_interior_vehicle_data[] = "RC.GetInteriorVehicleData"; -const char set_interior_vehicle_data[] = "RC.SetInteriorVehicleData"; -const char on_interior_vehicle_data[] = "RC.OnInteriorVehicleData"; -const char button_press[] = "Buttons.ButtonPress"; -const char on_remote_control_settings[] = "RC.OnRemoteControlSettings"; - -const char get_user_consent[] = "RC.GetInteriorVehicleDataConsent"; -const char on_app_deactivated[] = "BasicCommunication.OnAppDeactivated"; -const char sdl_activate_app[] = "SDL.ActivateApp"; -} - -} // namespace functional_modules - -#endif // SRC_COMPONENTS_FUNCTIONAL_MODULE_INCLUDE_FUNCTIONAL_MODULE_FUNCTION_IDS_H_ diff --git a/src/components/functional_module/include/functional_module/generic_module.h b/src/components/functional_module/include/functional_module/generic_module.h deleted file mode 100644 index 15d572be6d..0000000000 --- a/src/components/functional_module/include/functional_module/generic_module.h +++ /dev/null @@ -1,180 +0,0 @@ -/* - * Copyright (c) 2017, 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_FUNCTIONAL_MODULE_INCLUDE_FUNCTIONAL_MODULE_GENERIC_MODULE_H_ -#define SRC_COMPONENTS_FUNCTIONAL_MODULE_INCLUDE_FUNCTIONAL_MODULE_GENERIC_MODULE_H_ - -#include <deque> -#include <string> -#include "functional_module/module_observer.h" -#include "functional_module/function_ids.h" -#include "utils/shared_ptr.h" -#include "application_manager/service.h" - -namespace functional_modules { - -/** - * @brief The PolicyEvent enum defines events related to policy - */ -enum PolicyEvent { kApplicationPolicyUpdated = 0, kApplicationsDisabled }; - -/** - * @brief The ApplicationEvent enum defines events related to single application - */ -enum ApplicationEvent { kApplicationExit = 0, kApplicationUnregistered }; - -enum ProcessResult { - NONE = -1, - PROCESSED, - PARTIALLY_PROCESSED, - CANNOT_PROCESS, - FAILED -}; - -enum ServiceState { IDLE = 0, SUSPENDED, LOWVOLTAGE, HMI_ADAPTER_INITIALIZED }; - -typedef std::string HMIFunctionID; - -class GenericModule; -typedef utils::SharedPtr<GenericModule> ModulePtr; - -struct PluginInfo { - std::string name; - int version; - std::deque<RCFunctionID> rc_function_list; - std::deque<HMIFunctionID> hmi_function_list; -}; - -class GenericModule { - public: - typedef std::deque<ModuleObserver*> Observers; - - virtual ~GenericModule(); - ModuleID GetModuleID() const { - return kModuleId_; - } - virtual PluginInfo GetPluginInfo() const = 0; - - /** - * @brief Setter for service (interface for plugin t access SDL functionality) - * @param service pointer to new service instance - */ - virtual void set_service(application_manager::ServicePtr service); - - /** - * @brief Returns pointer to SDL core service interface - * @return pointer to core service interface - */ - virtual application_manager::ServicePtr service(); - - virtual ProcessResult ProcessMessage(application_manager::MessagePtr msg) = 0; - virtual ProcessResult ProcessHMIMessage( - application_manager::MessagePtr msg) = 0; - virtual void OnServiceStateChanged(ServiceState state); - - /** - * @brief Adds pointer to observer of module to be notified about - * exceptional sutiations in module. - * Raw pointer is passed to avoid circular dependencies. - * Module is not responsible for freeing observer's memory. - */ - void AddObserver(ModuleObserver* const observer); - - /** - * @brief Removes pointer to observer of module when it's no loger - * wants to be notified about exceptional sutiations in module. - * Raw pointer is passed to avoid circular dependencies. - * Module is not responsible for freeing observer's memory. - */ - void RemoveObserver(ModuleObserver* const observer); - - /** - * @brief Remove extension created for specified application - * @param app_id application id - */ - virtual void RemoveAppExtension(uint32_t app_id) = 0; - - /** - * @brief Check registering app can be handled by plugin - * @param msg Registration message - * @param app Application basis already create by Core - */ - virtual bool IsAppForPlugin( - application_manager::ApplicationSharedPtr app) = 0; - - /** - * @brief Notify about change of HMILevel of plugin's app - * @param app App with new HMILevel - * @param old_level Old HMILevel of app - */ - virtual void OnAppHMILevelChanged( - application_manager::ApplicationSharedPtr app, - mobile_apis::HMILevel::eType old_level) = 0; - - /** - * @brief OnApplicationEvent Processes application related events - * @param event Event - * @param application Pointer to application struct - */ - virtual void OnApplicationEvent( - ApplicationEvent event, - application_manager::ApplicationSharedPtr application) = 0; - - /** - * @brief OnPolicyEvent Processes policy related events - * @param event Policy event - */ - virtual void OnPolicyEvent(PolicyEvent event) = 0; - - protected: - explicit GenericModule(ModuleID module_id); - void NotifyObservers(ModuleObserver::Errors error); - - /** - * @brief Remove extension for all applications - */ - virtual void RemoveAppExtensions() = 0; - - private: - application_manager::ServicePtr service_; - const ModuleID kModuleId_; - - Observers observers_; - ServiceState state_; - - friend class DriverGenericModuleTest; - DISALLOW_COPY_AND_ASSIGN(GenericModule); -}; - -} // namespace functional_modules - -#endif // SRC_COMPONENTS_FUNCTIONAL_MODULE_INCLUDE_FUNCTIONAL_MODULE_GENERIC_MODULE_H_ diff --git a/src/components/functional_module/include/functional_module/module_observer.h b/src/components/functional_module/include/functional_module/module_observer.h deleted file mode 100644 index a5e34db040..0000000000 --- a/src/components/functional_module/include/functional_module/module_observer.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2017, 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_FUNCTIONAL_MODULE_INCLUDE_FUNCTIONAL_MODULE_MODULE_OBSERVER_H_ -#define SRC_COMPONENTS_FUNCTIONAL_MODULE_INCLUDE_FUNCTIONAL_MODULE_MODULE_OBSERVER_H_ - -namespace functional_modules { - -typedef int ModuleID; - -class ModuleObserver { - public: - enum Errors { NONE = -1, OUT_OF_MEMORY, FS_FAILURE }; - virtual ~ModuleObserver() {} - - /** - * @brief OnError callback for module to notify SDL about internal error - * @param error error type - * @param module_id module that triggered error - */ - virtual void OnError(Errors error, ModuleID module_id) = 0; -}; -} // namespace functional_modules { - -#endif // SRC_COMPONENTS_FUNCTIONAL_MODULE_INCLUDE_FUNCTIONAL_MODULE_MODULE_OBSERVER_H_ diff --git a/src/components/functional_module/include/functional_module/plugin_manager.h b/src/components/functional_module/include/functional_module/plugin_manager.h deleted file mode 100644 index c573d843b2..0000000000 --- a/src/components/functional_module/include/functional_module/plugin_manager.h +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (c) 2017, 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_FUNCTIONAL_MODULE_INCLUDE_FUNCTIONAL_MODULE_PLUGIN_MANAGER_H_ -#define SRC_COMPONENTS_FUNCTIONAL_MODULE_INCLUDE_FUNCTIONAL_MODULE_PLUGIN_MANAGER_H_ - -#include <map> -#include <string> -#include "functional_module/generic_module.h" -#include "application_manager/service.h" -#include "application_manager/message.h" - -namespace functional_modules { - -class PluginManager : public ModuleObserver { - public: - PluginManager(); - ~PluginManager(); - typedef std::map<ModuleID, ModulePtr> Modules; - - /** - * @brief LoadPlugins initialize loading plugins - * @param plugin_path path to search to plugin shared libraries - * @return count of loaded plugins - */ - int LoadPlugins(const std::string& plugin_path); - - /** - * @brief UnloadPlugins unload from memory all plugins - */ - void UnloadPlugins(); - - /** - * @brief IsMessageForPlugin Verifies whether mobile message will be processed - * by plugins - * @param msg Mobile message - * @return True if any of plugins will process the message, otherwise - false - */ - bool IsMessageForPlugin(application_manager::MessagePtr msg); - - /** - * @brief IsHMIMessageForPlugin Verifies whether HMI message will be processed - * by plugins - * @param msg HMI message - * @return True if any of plugins will process the message, otherwise - false - */ - bool IsHMIMessageForPlugin(application_manager::MessagePtr msg); - - /** - * @brief ProcessMessage forwards mobile message to modules if any is - * subsribed for the message. - * @param msg Mobile message to process - * @return Result of processing - */ - ProcessResult ProcessMessage(application_manager::MessagePtr msg); - - /** - * @brief ProcessHMIMessage forwards HMI message to modules if any is - * subscribed for the message - * @param msg HMI message to process - * @return Result of processing - */ - ProcessResult ProcessHMIMessage(application_manager::MessagePtr msg); - void SetServiceHandler(application_manager::ServicePtr service) { - service_ = service; - } - void OnServiceStateChanged(ServiceState state); - void OnError(ModuleObserver::Errors error, ModuleID module_id) FINAL; - - /** - * @brief Remove extension created for specified application - * @param app_id application id - */ - void RemoveAppExtension(uint32_t app_id); - - /** - * @brief Check if app cooperates with one or more plugins, init it - * inside plugin accordingly if needed. - * @param app Application in question. - */ - bool IsAppForPlugins(application_manager::ApplicationSharedPtr app); - - /** - * Check if app cooperates with plugin - * @param app application - * @param module_id unique identifier of plugin - * @return true if application cooperates with this plugin - */ - bool IsAppForPlugin(application_manager::ApplicationSharedPtr app, - ModuleID module_id) const; - - /** - * @brief Notify plugins about change of HMILevel of app - * if app is related to plugin - * @param app App with new HMILevel - * @param old_level Old HMILevel of app - */ - void OnAppHMILevelChanged(application_manager::ApplicationSharedPtr app, - mobile_apis::HMILevel::eType old_level); - - /** - * @brief OnApplicationEvent Notifies modules on certain application events - * @param event Event - * @param application Pointer to application struct - */ - void OnApplicationEvent( - functional_modules::ApplicationEvent event, - application_manager::ApplicationSharedPtr application); - - /** - * @brief OnPolicyEvent Notifies modules on certain events from policy - * @param event Policy event - */ - void OnPolicyEvent(functional_modules::PolicyEvent event); - - Modules& plugins(); - - private: - Modules plugins_; - std::map<ModuleID, void*> dlls_; - std::map<RCFunctionID, ModulePtr> mobile_subscribers_; - std::map<HMIFunctionID, ModulePtr> hmi_subscribers_; - application_manager::ServicePtr service_; - - DISALLOW_COPY_AND_ASSIGN(PluginManager); -}; - -} // namespace functional_modules - -#endif // SRC_COMPONENTS_FUNCTIONAL_MODULE_INCLUDE_FUNCTIONAL_MODULE_PLUGIN_MANAGER_H_ diff --git a/src/components/functional_module/include/functional_module/timer/module_timer.h b/src/components/functional_module/include/functional_module/timer/module_timer.h deleted file mode 100644 index e24259241b..0000000000 --- a/src/components/functional_module/include/functional_module/timer/module_timer.h +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright (c) 2017, 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_FUNCTIONAL_MODULE_INCLUDE_FUNCTIONAL_MODULE_TIMER_MODULE_TIMER_H_ -#define SRC_COMPONENTS_FUNCTIONAL_MODULE_INCLUDE_FUNCTIONAL_MODULE_TIMER_MODULE_TIMER_H_ - -#include <list> -#include <deque> -#include <algorithm> -#include <time.h> -#include "utils/lock.h" - -namespace functional_modules { - -typedef unsigned int TimeUnit; // seconds - -class Trackable { - public: - Trackable() : start_time_(0) {} - virtual ~Trackable() {} - - /** - * @brief custom_interval getter for custom interval - * @return return timer interval for trackable message - */ - virtual TimeUnit custom_interval() const { - return 0; - } - - /** - * @brief start_time getter for start time of message - * @return start time of message - */ - virtual TimeUnit start_time() const { - return start_time_; - } - - /** - * @brief set_start_time setting start time of message - * @param start_time start time - */ - virtual void set_start_time(TimeUnit start_time) { - start_time_ = start_time; - } - - private: - TimeUnit start_time_; -}; - -template <class Trackable> -class TimerObserver { - public: - virtual ~TimerObserver() {} - virtual void OnTimeoutTriggered(const Trackable& expired) = 0; -}; - -template <class Trackable> -class ModuleTimer { - public: - ModuleTimer(); - ~ModuleTimer(); - void set_period(TimeUnit period) { - period_ = period; - } - TimeUnit period() const { - return period_; - } - void AddObserver(TimerObserver<Trackable>* observer); - void RemoveObserver(TimerObserver<Trackable>* observer); - - void CheckTimeout(); - /** - * @brief Gets time in seconds when the nearest request timeout will be - * triggered - * @return time in seconds when the nearest request timeout will be triggered - */ - TimeUnit GetSecondsToNearestTimeout(); - - /* - * @brief Adds object to be tracked by timer. - If same object is already added replaces it with new one - correspondingly updating start time of tracking. - */ - void AddTrackable(const Trackable& object); - void RemoveTrackable(const Trackable& object); - - protected: - void Notify(const Trackable& object); - void OnTimeout(const Trackable& object); - TimeUnit CurrentTime() const; - typename std::list<Trackable> trackables_; - volatile TimeUnit period_; - - private: - std::deque<TimerObserver<Trackable>*> observers_; - mutable sync_primitives::Lock trackables_lock_; - friend class ModuleTimerTest; -}; - -template <class Trackable> -ModuleTimer<Trackable>::ModuleTimer() - : period_(10) {} - -template <class Trackable> -ModuleTimer<Trackable>::~ModuleTimer() { - observers_.clear(); - sync_primitives::AutoLock auto_lock(trackables_lock_); - trackables_.clear(); -} - -template <class Trackable> -void ModuleTimer<Trackable>::AddObserver(TimerObserver<Trackable>* observer) { - DCHECK(observer); - if (!observer) { - return; - } - observers_.push_back(observer); -} - -template <class Trackable> -void ModuleTimer<Trackable>::RemoveObserver( - TimerObserver<Trackable>* observer) { - DCHECK(observer); - if (!observer) { - return; - } - for (typename std::deque<TimerObserver<Trackable>*>::iterator it = - observers_.begin(); - observers_.end() != it; - ++it) { - if (*it == observer) { - observers_.erase(it); - return; - } - } -} - -template <class Trackable> -void ModuleTimer<Trackable>::CheckTimeout() { - sync_primitives::AutoLock trackables_lock(trackables_lock_); - for (typename std::list<Trackable>::iterator it = trackables_.begin(); - trackables_.end() != it; - ++it) { - TimeUnit period = it->custom_interval(); - if (!period) { - period = period_; - } - if (CurrentTime() - it->start_time() >= period) { - OnTimeout(*it); - it = trackables_.erase(it); - } - } -} - -template <class Trackable> -TimeUnit ModuleTimer<Trackable>::GetSecondsToNearestTimeout() { - sync_primitives::AutoLock trackables_lock(trackables_lock_); - TimeUnit result = period_; - for (typename std::list<Trackable>::iterator it = trackables_.begin(); - trackables_.end() != it; - ++it) { - TimeUnit period = it->custom_interval(); - if (!period) { - period = period_; - } - const TimeUnit current_secs_to_timeout = - period - (CurrentTime() - it->start_time()); - if (result > current_secs_to_timeout) { - result = current_secs_to_timeout; - } - } - return result; -} - -template <class Trackable> -void ModuleTimer<Trackable>::AddTrackable(const Trackable& object) { - sync_primitives::AutoLock trackables_lock(trackables_lock_); - trackables_.remove(object); - trackables_.push_back(object); - trackables_.back().set_start_time(CurrentTime()); -} - -template <class Trackable> -void ModuleTimer<Trackable>::RemoveTrackable(const Trackable& object) { - sync_primitives::AutoLock trackables_lock(trackables_lock_); - trackables_.remove(object); -} - -template <class Trackable> -void ModuleTimer<Trackable>::Notify(const Trackable& object) { - for (typename std::deque<TimerObserver<Trackable>*>::const_iterator it = - observers_.begin(); - observers_.end() != it; - ++it) { - (*it)->OnTimeoutTriggered(object); - } -} - -template <class Trackable> -void ModuleTimer<Trackable>::OnTimeout(const Trackable& object) { - Notify(object); -} - -template <class Trackable> -TimeUnit ModuleTimer<Trackable>::CurrentTime() const { - // TODO(PV): move outside to platform-dependant parts - struct timespec current_time; - if (0 == clock_gettime(CLOCK_MONOTONIC, ¤t_time)) { - return current_time.tv_sec; - } else { - return 0; - } -} - -} // namespace functional_modules - -#endif // SRC_COMPONENTS_FUNCTIONAL_MODULE_INCLUDE_FUNCTIONAL_MODULE_TIMER_MODULE_TIMER_H_ diff --git a/src/components/functional_module/include/functional_module/timer/timer_director.h b/src/components/functional_module/include/functional_module/timer/timer_director.h deleted file mode 100644 index fb67b9b5de..0000000000 --- a/src/components/functional_module/include/functional_module/timer/timer_director.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2017, 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_FUNCTIONAL_MODULE_INCLUDE_FUNCTIONAL_MODULE_TIMER_TIMER_DIRECTOR_H_ -#define SRC_COMPONENTS_FUNCTIONAL_MODULE_INCLUDE_FUNCTIONAL_MODULE_TIMER_TIMER_DIRECTOR_H_ - -#include <map> -#include "utils/threads/thread.h" -#include "utils/conditional_variable.h" -#include "functional_module/timer/module_timer.h" - -namespace functional_modules { - -template <class T> -class TimerThreadDelegate : public threads::ThreadDelegate { - public: - explicit TimerThreadDelegate(ModuleTimer<T>& timer); - void threadMain(); - void exitThreadMain(); - - /** - * @brief Reset awaiting timer by notifying cond var - */ - void ResetTimer(); - - private: - ModuleTimer<T>& timer_; - volatile bool keep_running_; - mutable sync_primitives::Lock keep_running_lock_; - mutable sync_primitives::ConditionalVariable keep_running_cond_; - friend class TimerThreadDelegateTest; -}; - -class TimerDirector { - public: - TimerDirector(); - ~TimerDirector(); - - /** - * @brief Register timer for execution in separate thread. - Registers only one timer of a type. Attempt to register timer - of already existing type will fail. - */ - template <class T> - void RegisterTimer(ModuleTimer<T>& timer); - template <class T> - void UnregisterTimer(const ModuleTimer<T>& timer); - void UnregisterAllTimers(); - /** - * @brief Reset awaiting timeout for specified module timer - * @param timer timer to reset awaiting timeout - */ - template <class T> - void ResetTimer(ModuleTimer<T>& timer); - - private: - DISALLOW_COPY_AND_ASSIGN(TimerDirector); - std::map<std::string, threads::Thread*> timer_threads_; -}; - -} // namespace functional_modules - -#endif // SRC_COMPONENTS_FUNCTIONAL_MODULE_INCLUDE_FUNCTIONAL_MODULE_TIMER_TIMER_DIRECTOR_H_ |