/** * @file include/ActivMiddleware/ActivFramework/DirectoryWatchApi.h * * @brief Header file for the directory watch api. */ #if (!defined ACTIV_FRAMEWORK_DIRECTORY_WATCH_API_H) #define ACTIV_FRAMEWORK_DIRECTORY_WATCH_API_H #include "ActivMiddleware/ActivFramework/External.h" #include //! Activ namespace. namespace Activ { class Component; class HeapMessage; class ScopedAddress; // --------------------------------------------------------------------------------------------------------------------------------- /** * @brief Api to the agent's directory watching service. */ class DirectoryWatchApi { public: /** * @brief Message type received in OnMessage() by the component adding a directory watch when a change happens. */ static const MessageType MESSAGE_TYPE = ROUTER_MESSAGE_USER_NOTIFY_DIRECTORY_WATCH_EVENTS; typedef uint32_t WatchType; static const WatchType WATCH_TYPE_RECURSIVE = 0x00000001; ///< watch sub-directories? static const WatchType WATCH_TYPE_ADDS_DELETES = 0x00000002;///< watch for file & directory additions / deletions static const WatchType WATCH_TYPE_ATTRIBUTES = 0x00000004; ///< watch for changes in attributes (size, access times etc.) of files & directories /** * @brief List of event types that can be received. */ enum EventType { EVENT_TYPE_ADDED, ///< file or directory has been added EVENT_TYPE_DELETED, ///< file or directory has been deleted EVENT_TYPE_MODIFIED ///< some attribute of the file or directory has changed }; /** * @brief File/directory change event. */ class Event { public: String m_path; ///< path of file or directory that has changed EventType m_eventType; ///< type of event that has happened }; typedef std::vector EventList; ///< list of events /** * @brief Add a directory watch. * * Change notifications will be received in the OnMessage() callback of @a component, with message type * DirectoryWatchApi::MESSAGE_TYPE. Call DirectoryWatchApi::Deserialize() to get a list of Event objects. * * @param component the component wanting to create the watch. * @param directoryPath path of a directory to watch. * @param watchType type of watch to start. * @param watchAddress reference to a ScopedAddress object to receive the address of the new watch. * * @retval STATUS_CODE_SUCCESS * @retval STATUS_CODE_TIMEOUT * @retval STATUS_CODE_NOT_A_DIRECTORY path provided isn't a directory or doesn't exist * @retval ... */ ACTIV_FRAMEWORK_API static StatusCode AddWatch(const Component &component, const String &directoryPath, const WatchType watchType, ScopedAddress &watchAddress); /** * @brief Deserialize a directory watch message. * * @param heapMessage message containing the serialized events. * @param eventList to receive the deserialized events. * * @return STATUS_CODE_SUCCESS or an error status code. */ ACTIV_FRAMEWORK_API static StatusCode Deserialize(const HeapMessage &heapMessage, EventList &eventList); /** * @brief Convert an event type to a string. * * @param eventType the EventType to convert. * * @return String representation of @a eventType. */ ACTIV_FRAMEWORK_API static String EventTypeToString(const EventType eventType); }; } // namespace Activ #endif // (!defined ACTIV_FRAMEWORK_DIRECTORY_WATCH_API_H)