2014-12-18 18:50:47 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2014, Facebook, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This source code is licensed under the BSD-style license found in the
|
|
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
*
|
|
|
|
*/
|
2014-09-18 04:20:30 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <functional>
|
|
|
|
#include <memory>
|
|
|
|
#include <map>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
#include <boost/make_shared.hpp>
|
2014-09-23 01:35:12 +00:00
|
|
|
#include <boost/thread.hpp>
|
2014-09-19 08:54:33 +00:00
|
|
|
#include <boost/thread/locks.hpp>
|
|
|
|
#include <boost/thread/mutex.hpp>
|
2014-09-18 04:20:30 +00:00
|
|
|
|
2014-12-03 23:31:09 +00:00
|
|
|
#include <osquery/database.h>
|
|
|
|
#include <osquery/registry.h>
|
|
|
|
#include <osquery/status.h>
|
2014-12-15 02:03:41 +00:00
|
|
|
#include <osquery/tables.h>
|
2014-09-18 04:20:30 +00:00
|
|
|
|
|
|
|
namespace osquery {
|
|
|
|
|
2014-10-03 15:26:41 +00:00
|
|
|
struct Subscription;
|
2014-12-15 00:05:07 +00:00
|
|
|
template <class SC, class EC> class EventPublisher;
|
|
|
|
template <class PUB> class EventSubscriber;
|
|
|
|
class EventFactory;
|
2014-09-18 04:20:30 +00:00
|
|
|
|
2014-10-03 15:14:36 +00:00
|
|
|
typedef const std::string EventPublisherID;
|
2014-12-15 00:05:07 +00:00
|
|
|
typedef const std::string EventSubscriberID;
|
2014-09-19 08:54:33 +00:00
|
|
|
typedef const std::string EventID;
|
|
|
|
typedef uint32_t EventContextID;
|
2014-09-18 04:20:30 +00:00
|
|
|
typedef uint32_t EventTime;
|
2014-09-25 17:17:32 +00:00
|
|
|
typedef std::pair<EventID, EventTime> EventRecord;
|
2014-09-18 04:20:30 +00:00
|
|
|
|
2014-09-30 19:50:14 +00:00
|
|
|
/**
|
2014-10-03 15:36:22 +00:00
|
|
|
* @brief An EventPublisher will define a SubscriptionContext for
|
|
|
|
* EventSubscriber%s to use.
|
|
|
|
*
|
|
|
|
* Most EventPublisher%s will reqire specific information for interacting with
|
|
|
|
* an OS to receive events. The SubscriptionContext contains information the
|
|
|
|
* EventPublisher will use to register OS API callbacks, create
|
|
|
|
* subscriptioning/listening handles, etc.
|
|
|
|
*
|
|
|
|
* Linux `inotify` should implement a SubscriptionContext that subscriptions
|
2014-12-18 04:10:51 +00:00
|
|
|
* filesystem events based on a filesystem path. `libpcap` will subscribe on
|
|
|
|
* networking protocols at various stacks. Process creation may subscribe on
|
2014-10-03 15:36:22 +00:00
|
|
|
* process name, parent pid, etc.
|
2014-09-30 19:50:14 +00:00
|
|
|
*/
|
2014-10-03 15:26:41 +00:00
|
|
|
struct SubscriptionContext {};
|
2014-09-30 19:50:14 +00:00
|
|
|
|
|
|
|
/**
|
2014-10-03 15:08:06 +00:00
|
|
|
* @brief An EventSubscriber EventCallback method will receive an EventContext.
|
2014-09-30 19:50:14 +00:00
|
|
|
*
|
2014-10-03 15:36:22 +00:00
|
|
|
* The EventContext contains the event-related data supplied by an
|
2014-12-18 04:10:51 +00:00
|
|
|
* EventPublisher when the event occures. If a subscribing EventSubscriber
|
|
|
|
* would be called for the event, the EventSubscriber%'s EventCallback is
|
2014-10-03 15:36:22 +00:00
|
|
|
* passed an EventContext.
|
2014-09-30 19:50:14 +00:00
|
|
|
*/
|
2014-09-25 17:17:32 +00:00
|
|
|
struct EventContext {
|
2014-10-03 15:14:36 +00:00
|
|
|
/// An unique counting ID specific to the EventPublisher%'s fired events.
|
2014-09-25 17:17:32 +00:00
|
|
|
EventContextID id;
|
2014-11-07 22:18:02 +00:00
|
|
|
/// The time the event occurred.
|
2014-09-25 17:17:32 +00:00
|
|
|
EventTime time;
|
2014-09-30 19:50:14 +00:00
|
|
|
/// The string representation of the time, often used for indexing.
|
2014-09-25 17:17:32 +00:00
|
|
|
std::string time_string;
|
|
|
|
};
|
2014-09-18 04:20:30 +00:00
|
|
|
|
2014-10-03 15:26:41 +00:00
|
|
|
typedef std::shared_ptr<Subscription> SubscriptionRef;
|
2014-12-15 00:05:07 +00:00
|
|
|
typedef EventPublisher<SubscriptionContext, EventContext> BaseEventPublisher;
|
|
|
|
typedef std::shared_ptr<BaseEventPublisher> EventPublisherRef;
|
2014-10-03 15:26:41 +00:00
|
|
|
typedef std::shared_ptr<SubscriptionContext> SubscriptionContextRef;
|
2014-09-24 17:20:58 +00:00
|
|
|
typedef std::shared_ptr<EventContext> EventContextRef;
|
2015-02-19 07:51:41 +00:00
|
|
|
typedef EventSubscriber<BaseEventPublisher> BaseEventSubscriber;
|
2014-12-15 00:05:07 +00:00
|
|
|
typedef std::shared_ptr<EventSubscriber<BaseEventPublisher>> EventSubscriberRef;
|
2014-09-18 04:20:30 +00:00
|
|
|
|
2014-12-15 05:20:20 +00:00
|
|
|
/// Use a single placeholder for the EventContextRef passed to EventCallback.
|
|
|
|
using std::placeholders::_1;
|
2015-02-18 02:04:15 +00:00
|
|
|
using std::placeholders::_2;
|
|
|
|
typedef std::function<Status(const EventContextRef&, const void*)>
|
|
|
|
EventCallback;
|
2014-09-18 04:20:30 +00:00
|
|
|
|
2014-10-03 15:26:41 +00:00
|
|
|
/// An EventPublisher must track every subscription added.
|
|
|
|
typedef std::vector<SubscriptionRef> SubscriptionVector;
|
2014-09-22 21:35:07 +00:00
|
|
|
|
2014-09-19 08:54:33 +00:00
|
|
|
/// The set of search-time binned lookup tables.
|
|
|
|
extern const std::vector<size_t> kEventTimeLists;
|
|
|
|
|
2014-12-18 04:10:51 +00:00
|
|
|
/**
|
|
|
|
* @brief DECLARE_PUBLISHER supplies needed boilerplate code that applies a
|
|
|
|
* string-type EventPublisherID to identify the publisher declaration.
|
|
|
|
*/
|
2014-12-15 02:03:41 +00:00
|
|
|
#define DECLARE_PUBLISHER(TYPE) \
|
2014-12-15 05:20:20 +00:00
|
|
|
public: \
|
2015-02-01 11:32:18 +00:00
|
|
|
EventPublisherID type() const { return TYPE; }
|
2014-12-15 02:03:41 +00:00
|
|
|
|
2014-12-18 04:10:51 +00:00
|
|
|
/**
|
|
|
|
* @brief DECLARE_SUBSCRIBER supplies needed boilerplate code that applies a
|
|
|
|
* string-type EventSubscriberID to identify the subscriber declaration.
|
|
|
|
*/
|
2014-12-15 02:03:41 +00:00
|
|
|
#define DECLARE_SUBSCRIBER(NAME) \
|
2014-12-15 05:20:20 +00:00
|
|
|
public: \
|
2015-02-01 11:32:18 +00:00
|
|
|
EventSubscriberID name() const { return NAME; }
|
2014-09-25 17:17:32 +00:00
|
|
|
|
2014-09-18 04:20:30 +00:00
|
|
|
/**
|
2014-10-03 15:36:22 +00:00
|
|
|
* @brief A Subscription is used to configure an EventPublisher and bind a
|
2014-12-18 04:10:51 +00:00
|
|
|
* callback to a SubscriptionContext.
|
2014-09-24 15:03:16 +00:00
|
|
|
*
|
2014-10-03 15:36:22 +00:00
|
|
|
* A Subscription is the input to an EventPublisher when the EventPublisher
|
2014-12-18 04:10:51 +00:00
|
|
|
* decides on the scope and details of the events it watches/generates.
|
2014-10-03 15:36:22 +00:00
|
|
|
* An example includes a filesystem change event. A subscription would include
|
|
|
|
* a path with optional recursion and attribute selectors as well as a callback
|
|
|
|
* function to fire when an event for that path and selector occurs.
|
2014-09-24 15:03:16 +00:00
|
|
|
*
|
2014-10-03 15:26:41 +00:00
|
|
|
* A Subscription also functions to greatly scope an EventPublisher%'s work.
|
2014-10-03 15:36:22 +00:00
|
|
|
* Using the same filesystem example and the Linux inotify subsystem a
|
|
|
|
* Subscription limits the number of inode watches to only those requested by
|
|
|
|
* appropriate EventSubscriber%s.
|
|
|
|
* Note: EventSubscriber%s and Subscriptions can be configured by the osquery
|
|
|
|
* user.
|
2014-09-24 15:03:16 +00:00
|
|
|
*
|
2014-10-03 15:26:41 +00:00
|
|
|
* Subscriptions are usually created with EventFactory members:
|
2014-09-18 04:20:30 +00:00
|
|
|
*
|
2014-09-24 15:03:16 +00:00
|
|
|
* @code{.cpp}
|
2014-10-03 15:26:41 +00:00
|
|
|
* EventFactory::addSubscription("MyEventPublisher", my_subscription_context);
|
2014-09-24 15:03:16 +00:00
|
|
|
* @endcode
|
2014-09-18 04:20:30 +00:00
|
|
|
*/
|
2014-10-03 15:26:41 +00:00
|
|
|
struct Subscription {
|
2014-09-21 21:29:28 +00:00
|
|
|
public:
|
2014-10-03 15:26:41 +00:00
|
|
|
/// An EventPublisher%-specific SubscriptionContext.
|
|
|
|
SubscriptionContextRef context;
|
|
|
|
/// An EventSubscription member EventCallback method.
|
2014-09-18 04:20:30 +00:00
|
|
|
EventCallback callback;
|
2015-02-18 02:04:15 +00:00
|
|
|
/// A pointer to possible extra data
|
|
|
|
void* user_data;
|
2014-09-18 04:20:30 +00:00
|
|
|
|
2014-10-03 15:26:41 +00:00
|
|
|
static SubscriptionRef create() { return std::make_shared<Subscription>(); }
|
2014-09-18 04:20:30 +00:00
|
|
|
|
2014-12-15 18:17:56 +00:00
|
|
|
static SubscriptionRef create(const SubscriptionContextRef& mc,
|
2015-02-18 02:04:15 +00:00
|
|
|
EventCallback ec = 0,
|
|
|
|
void* user_data = nullptr) {
|
2014-10-03 15:26:41 +00:00
|
|
|
auto subscription = std::make_shared<Subscription>();
|
|
|
|
subscription->context = mc;
|
|
|
|
subscription->callback = ec;
|
2015-02-18 02:04:15 +00:00
|
|
|
subscription->user_data = user_data;
|
2014-10-03 15:26:41 +00:00
|
|
|
return subscription;
|
2014-09-18 04:20:30 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-01-30 18:44:25 +00:00
|
|
|
class EventPublisherPlugin : public Plugin {
|
2014-09-21 21:29:28 +00:00
|
|
|
public:
|
2014-09-30 19:50:14 +00:00
|
|
|
/**
|
2014-10-03 15:26:41 +00:00
|
|
|
* @brief A new Subscription was added, potentially change state based on all
|
|
|
|
* subscriptions for this EventPublisher.
|
2014-09-30 19:50:14 +00:00
|
|
|
*
|
2014-10-03 15:36:22 +00:00
|
|
|
* `configure` allows the EventPublisher to optimize on the state of all
|
|
|
|
* subscriptions. An example is Linux `inotify` where multiple
|
|
|
|
* EventSubscription%s will subscription identical paths, e.g., /etc for
|
|
|
|
* config changes. Since Linux `inotify` has a subscription limit, `configure`
|
|
|
|
* can depup paths.
|
2014-09-30 19:50:14 +00:00
|
|
|
*/
|
2014-09-18 04:20:30 +00:00
|
|
|
virtual void configure() {}
|
2014-09-24 15:03:16 +00:00
|
|
|
|
2014-09-30 19:50:14 +00:00
|
|
|
/**
|
|
|
|
* @brief Perform handle opening, OS API callback registration.
|
|
|
|
*
|
2014-10-03 15:36:22 +00:00
|
|
|
* `setUp` is the event framework's EventPublisher constructor equivilent.
|
|
|
|
* When `setUp` is called the EventPublisher is running in a dedicated thread
|
|
|
|
* and may manage/allocate/wait for resources.
|
2014-09-30 19:50:14 +00:00
|
|
|
*/
|
2014-12-14 11:43:31 +00:00
|
|
|
virtual Status setUp() { return Status(0, "Not used"); }
|
2014-09-24 15:03:16 +00:00
|
|
|
|
2014-09-30 19:50:14 +00:00
|
|
|
/**
|
|
|
|
* @brief Perform handle closing, resource cleanup.
|
|
|
|
*
|
2014-10-03 15:14:36 +00:00
|
|
|
* osquery is about to end, the EventPublisher should close handle descriptors
|
2014-09-30 19:50:14 +00:00
|
|
|
* unblock resources, and prepare to exit.
|
|
|
|
*/
|
2014-09-18 04:20:30 +00:00
|
|
|
virtual void tearDown() {}
|
|
|
|
|
2014-09-24 15:03:16 +00:00
|
|
|
/**
|
|
|
|
* @brief Implement a step of an optional run loop.
|
|
|
|
*
|
|
|
|
* @return A SUCCESS status will immediately call `run` again. A FAILED status
|
|
|
|
* will exit the run loop and the thread.
|
|
|
|
*/
|
2014-12-14 11:43:31 +00:00
|
|
|
virtual Status run() { return Status(1, "No runloop required"); }
|
2014-09-18 04:20:30 +00:00
|
|
|
|
2014-09-24 15:03:16 +00:00
|
|
|
/**
|
2014-10-03 15:36:22 +00:00
|
|
|
* @brief A new EventSubscriber is subscriptioning events of this
|
|
|
|
* EventPublisher.
|
2014-09-24 15:03:16 +00:00
|
|
|
*
|
2014-10-03 15:36:22 +00:00
|
|
|
* @param subscription The Subscription context information and optional
|
|
|
|
* EventCallback.
|
2014-09-24 15:03:16 +00:00
|
|
|
*
|
2014-10-03 15:26:41 +00:00
|
|
|
* @return If the Subscription is not appropriate (mismatched type) fail.
|
2014-09-24 15:03:16 +00:00
|
|
|
*/
|
2014-12-15 18:17:56 +00:00
|
|
|
virtual Status addSubscription(const SubscriptionRef& subscription) {
|
2014-10-03 15:26:41 +00:00
|
|
|
subscriptions_.push_back(subscription);
|
2014-09-18 04:20:30 +00:00
|
|
|
return Status(0, "OK");
|
|
|
|
}
|
|
|
|
|
2014-12-15 05:20:20 +00:00
|
|
|
/**
|
|
|
|
* @brief The generic check loop to call SubscriptionContext callback methods.
|
|
|
|
*
|
|
|
|
* It is NOT recommended to override `fire`. The simple logic of enumerating
|
|
|
|
* the Subscription%s and using `shouldFire` is more appropraite.
|
|
|
|
*
|
|
|
|
* @param ec The EventContext created and fired by the EventPublisher.
|
|
|
|
* @param time The most accurate time associated with the event.
|
|
|
|
*/
|
2014-12-15 18:17:56 +00:00
|
|
|
void fire(const EventContextRef& ec, EventTime time = 0);
|
2014-12-15 05:20:20 +00:00
|
|
|
|
2014-10-03 15:26:41 +00:00
|
|
|
/// Number of Subscription%s watching this EventPublisher.
|
2015-02-01 11:32:18 +00:00
|
|
|
size_t numSubscriptions() const { return subscriptions_.size(); }
|
2014-09-24 15:03:16 +00:00
|
|
|
|
2014-09-30 19:50:14 +00:00
|
|
|
/**
|
2014-10-03 15:14:36 +00:00
|
|
|
* @brief The number of events fired by this EventPublisher.
|
2014-09-30 19:50:14 +00:00
|
|
|
*
|
|
|
|
* @return The number of events.
|
|
|
|
*/
|
2015-02-01 11:32:18 +00:00
|
|
|
size_t numEvents() const { return next_ec_id_; }
|
2014-09-18 04:20:30 +00:00
|
|
|
|
2014-10-03 15:14:36 +00:00
|
|
|
/// Overriding the EventPublisher constructor is not recommended.
|
2015-02-01 08:35:44 +00:00
|
|
|
EventPublisherPlugin() : next_ec_id_(0), ending_(false), started_(false) {};
|
2015-01-30 18:44:25 +00:00
|
|
|
virtual ~EventPublisherPlugin() {}
|
2014-09-18 04:20:30 +00:00
|
|
|
|
2014-10-03 15:14:36 +00:00
|
|
|
/// Return a string identifier associated with this EventPublisher.
|
2015-02-01 11:32:18 +00:00
|
|
|
virtual EventPublisherID type() const { return "publisher"; }
|
2014-09-25 17:17:32 +00:00
|
|
|
|
2015-02-01 11:32:18 +00:00
|
|
|
bool isEnding() const { return ending_; }
|
2015-02-01 08:35:44 +00:00
|
|
|
void isEnding(bool ending) { ending_ = ending; }
|
2015-02-01 11:32:18 +00:00
|
|
|
bool hasStarted() const { return started_; }
|
2015-02-01 08:35:44 +00:00
|
|
|
void hasStarted(bool started) { started_ = started; }
|
2015-01-12 03:43:04 +00:00
|
|
|
|
2014-12-15 05:20:20 +00:00
|
|
|
protected:
|
2014-12-18 04:10:51 +00:00
|
|
|
/// The internal fire method used by the typed EventPublisher.
|
2014-12-15 18:17:56 +00:00
|
|
|
virtual void fireCallback(const SubscriptionRef& sub,
|
2015-02-01 11:32:18 +00:00
|
|
|
const EventContextRef& ec) const = 0;
|
2014-12-15 05:20:20 +00:00
|
|
|
|
|
|
|
/// The EventPublisher will keep track of Subscription%s that contain callins.
|
|
|
|
SubscriptionVector subscriptions_;
|
|
|
|
|
|
|
|
/// An Event ID is assigned by the EventPublisher within the EventContext.
|
|
|
|
/// This is not used to store event date in the backing store.
|
|
|
|
EventContextID next_ec_id_;
|
|
|
|
|
2015-02-01 11:32:18 +00:00
|
|
|
private:
|
|
|
|
EventPublisherPlugin(EventPublisherPlugin const&);
|
|
|
|
void operator=(EventPublisherPlugin const&);
|
|
|
|
|
2014-12-15 05:20:20 +00:00
|
|
|
private:
|
2015-01-12 03:43:04 +00:00
|
|
|
/// Set ending to True to cause event type run loops to finish.
|
|
|
|
bool ending_;
|
2015-02-01 08:35:44 +00:00
|
|
|
/// Set to indicate whether the event run loop ever started.
|
|
|
|
bool started_;
|
2015-01-12 03:43:04 +00:00
|
|
|
|
2014-12-15 05:20:20 +00:00
|
|
|
/// A lock for incrementing the next EventContextID.
|
|
|
|
boost::mutex ec_id_lock_;
|
|
|
|
|
|
|
|
private:
|
|
|
|
FRIEND_TEST(EventsTests, test_event_pub);
|
|
|
|
FRIEND_TEST(EventsTests, test_fire_event);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Generate OS events of a type (FS, Network, Syscall, ioctl).
|
|
|
|
*
|
|
|
|
* A 'class' of OS events is abstracted into an EventPublisher responsible for
|
|
|
|
* remaining as agile as possible given a known-set of subscriptions.
|
|
|
|
*
|
|
|
|
* The lifecycle of an EventPublisher may include, `setUp`, `configure`, `run`,
|
|
|
|
* `tearDown`, and `fire`. `setUp` and `tearDown` happen when osquery starts and
|
|
|
|
* stops either as a daemon or interactive shell. `configure` is a pseudo-start
|
|
|
|
* called every time a Subscription is added. EventPublisher%s can adjust their
|
|
|
|
* scope/agility specific to each added subscription by overriding
|
2014-12-18 04:10:51 +00:00
|
|
|
*`addSubscription`, and/or globally in `configure`.
|
2014-12-15 05:20:20 +00:00
|
|
|
*
|
|
|
|
* Not all EventPublisher%s leverage pure async OS APIs, and most will require a
|
|
|
|
* run loop either polling with a timeout on a descriptor or for a change. When
|
|
|
|
* osquery initializes the EventFactory will optionally create a thread for each
|
2014-12-18 04:10:51 +00:00
|
|
|
* EventPublisher using `run` as the thread's entrypoint. `run` is called in a
|
2014-12-15 05:20:20 +00:00
|
|
|
* within-thread loop where returning a FAILED status ends the run loop and
|
|
|
|
* shuts down the thread.
|
|
|
|
*
|
2014-12-18 04:10:51 +00:00
|
|
|
* To opt-out of polling in a thread, consider the following run implementation:
|
2014-12-15 05:20:20 +00:00
|
|
|
*
|
|
|
|
* @code{.cpp}
|
2014-12-18 04:10:51 +00:00
|
|
|
* Status run() { return Status(1, "Not Implemented"); }
|
2014-12-15 05:20:20 +00:00
|
|
|
* @endcode
|
|
|
|
*
|
|
|
|
* The final lifecycle component, `fire` will iterate over the EventPublisher
|
|
|
|
* Subscription%s and call `shouldFire` for each, using the EventContext fired.
|
|
|
|
* The `shouldFire` method should check the subscription-specific selectors and
|
2014-12-18 04:10:51 +00:00
|
|
|
* only call the Subscription%'s callback function if the EventContext
|
2014-12-15 05:20:20 +00:00
|
|
|
* (thus event) matches.
|
|
|
|
*/
|
|
|
|
template <typename SC, typename EC>
|
2015-01-30 18:44:25 +00:00
|
|
|
class EventPublisher : public EventPublisherPlugin {
|
2014-09-30 20:17:54 +00:00
|
|
|
public:
|
2014-12-18 04:10:51 +00:00
|
|
|
/// A nested helper typename for the templated SubscriptionContextRef.
|
2014-12-15 05:20:20 +00:00
|
|
|
typedef typename std::shared_ptr<SC> SCRef;
|
2014-12-18 04:10:51 +00:00
|
|
|
/// A nested helper typename for the templated EventContextRef.
|
2014-12-15 05:20:20 +00:00
|
|
|
typedef typename std::shared_ptr<EC> ECRef;
|
2014-09-24 15:03:16 +00:00
|
|
|
|
2014-12-14 11:43:31 +00:00
|
|
|
public:
|
2014-12-18 04:10:51 +00:00
|
|
|
/// Up-cast a base EventContext reference to the templated ECRef.
|
2014-12-15 18:17:56 +00:00
|
|
|
static ECRef getEventContext(const EventContextRef& ec) {
|
2014-12-14 11:43:31 +00:00
|
|
|
return std::static_pointer_cast<EC>(ec);
|
|
|
|
}
|
|
|
|
|
2014-12-18 04:10:51 +00:00
|
|
|
/// Up-cast a base SubscriptionContext reference to the templated SCRef.
|
2014-12-15 18:17:56 +00:00
|
|
|
static SCRef getSubscriptionContext(const SubscriptionContextRef& sc) {
|
2014-12-14 11:43:31 +00:00
|
|
|
return std::static_pointer_cast<SC>(sc);
|
|
|
|
}
|
|
|
|
|
2014-12-18 04:10:51 +00:00
|
|
|
/// Create a EventContext based on the templated type.
|
2014-12-14 11:43:31 +00:00
|
|
|
static ECRef createEventContext() { return std::make_shared<EC>(); }
|
2014-12-18 04:10:51 +00:00
|
|
|
|
|
|
|
/// Create a SubscriptionContext based on the templated type.
|
2014-12-14 11:43:31 +00:00
|
|
|
static SCRef createSubscriptionContext() { return std::make_shared<SC>(); }
|
|
|
|
|
2014-12-18 04:10:51 +00:00
|
|
|
/// A simple EventPublisher type accessor.
|
2014-12-15 06:17:38 +00:00
|
|
|
template <class PUB>
|
|
|
|
static EventPublisherID getType() {
|
|
|
|
auto pub = std::make_shared<PUB>();
|
|
|
|
return pub->type();
|
|
|
|
}
|
|
|
|
|
2014-12-15 05:20:20 +00:00
|
|
|
protected:
|
2014-12-18 04:10:51 +00:00
|
|
|
/**
|
|
|
|
* @brief The internal `fire` phase of publishing.
|
|
|
|
*
|
|
|
|
* This is a template-generated method that up-casts the generic fired
|
|
|
|
* event/subscription contexts, and calls the callback if the event should
|
|
|
|
* fire given a scription.
|
|
|
|
*
|
|
|
|
* @param sub The SubscriptionContext and optional EventCallback.
|
|
|
|
* @param ec The event that was fired.
|
|
|
|
*/
|
2015-02-01 11:32:18 +00:00
|
|
|
void fireCallback(const SubscriptionRef& sub,
|
|
|
|
const EventContextRef& ec) const {
|
2014-12-15 05:20:20 +00:00
|
|
|
auto pub_sc = getSubscriptionContext(sub->context);
|
|
|
|
auto pub_ec = getEventContext(ec);
|
|
|
|
if (shouldFire(pub_sc, pub_ec) && sub->callback != nullptr) {
|
2015-02-18 02:04:15 +00:00
|
|
|
sub->callback(pub_ec, sub->user_data);
|
2014-12-15 05:20:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-25 17:17:32 +00:00
|
|
|
protected:
|
2014-09-24 15:03:16 +00:00
|
|
|
/**
|
2014-10-03 15:26:41 +00:00
|
|
|
* @brief The generic `fire` will call `shouldFire` for each Subscription.
|
2014-09-24 15:03:16 +00:00
|
|
|
*
|
2014-10-03 15:36:22 +00:00
|
|
|
* @param mc A SubscriptionContext with optional specifications for events
|
|
|
|
* details.
|
2014-09-24 15:03:16 +00:00
|
|
|
* @param ec The event fired with event details.
|
|
|
|
*
|
2014-10-03 15:26:41 +00:00
|
|
|
* @return should the Subscription%'s EventCallback be called for this event.
|
2014-09-24 15:03:16 +00:00
|
|
|
*/
|
2015-02-01 11:32:18 +00:00
|
|
|
virtual bool shouldFire(const SCRef& sc, const ECRef& ec) const {
|
|
|
|
return true;
|
|
|
|
}
|
2014-09-19 08:54:33 +00:00
|
|
|
|
2014-09-22 21:35:07 +00:00
|
|
|
private:
|
2014-12-15 05:20:20 +00:00
|
|
|
FRIEND_TEST(EventsTests, test_event_sub_subscribe);
|
|
|
|
FRIEND_TEST(EventsTests, test_event_sub_context);
|
2014-09-19 08:54:33 +00:00
|
|
|
FRIEND_TEST(EventsTests, test_fire_event);
|
2014-09-18 04:20:30 +00:00
|
|
|
};
|
|
|
|
|
2015-01-30 18:44:25 +00:00
|
|
|
class EventSubscriberPlugin : public Plugin {
|
2014-12-15 00:05:07 +00:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* @brief Store parsed event data from an EventCallback in a backing store.
|
|
|
|
*
|
|
|
|
* Within a EventCallback the EventSubscriber has an opprotunity to create
|
|
|
|
* an osquery Row element, add the relevant table data for the EventSubscriber
|
|
|
|
* and store that element in the osquery backing store. At query-time
|
|
|
|
* the added data will apply selection criteria and return these elements.
|
|
|
|
* The backing store data retrieval is optimized by time-based indexes. It
|
|
|
|
* is important to added EventTime as it relates to "when the event occurred".
|
|
|
|
*
|
|
|
|
* @param r An osquery Row element.
|
|
|
|
* @param time The time the added event occurred.
|
|
|
|
*
|
|
|
|
* @return Was the element added to the backing store.
|
|
|
|
*/
|
|
|
|
virtual Status add(const osquery::Row& r, EventTime time) final;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Return all events added by this EventSubscriber within start, stop.
|
|
|
|
*
|
|
|
|
* This is used internally (for the most part) by EventSubscriber::genTable.
|
|
|
|
*
|
|
|
|
* @param start Inclusive lower bound time limit.
|
|
|
|
* @param stop Inclusive upper bound time limit.
|
|
|
|
* @return Set of event rows matching time limits.
|
|
|
|
*/
|
|
|
|
virtual QueryData get(EventTime start, EventTime stop);
|
|
|
|
|
2015-01-02 05:55:10 +00:00
|
|
|
private:
|
2014-12-15 00:05:07 +00:00
|
|
|
/*
|
|
|
|
* @brief When `get`ting event results, return EventID%s from time indexes.
|
|
|
|
*
|
|
|
|
* Used by EventSubscriber::get to retrieve EventID, EventTime indexes. This
|
|
|
|
* applies the lookup-efficiency checks for time list appropriate bins.
|
|
|
|
* If the time range in 24 hours and there is a 24-hour list bin it will
|
|
|
|
* be queried using a single backing store `Get` followed by two `Get`s of
|
|
|
|
* the most-specific boundary lists.
|
|
|
|
*
|
|
|
|
* @return List of EventID, EventTime%s
|
|
|
|
*/
|
|
|
|
std::vector<EventRecord> getRecords(const std::vector<std::string>& indexes);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Get a unique storage-related EventID.
|
|
|
|
*
|
|
|
|
* An EventID is an index/element-identifier for the backing store.
|
|
|
|
* Each EventPublisher maintains a fired EventContextID to identify the many
|
|
|
|
* events that may or may not be fired to subscriptioning criteria for this
|
|
|
|
* EventSubscriber. This EventContextID is NOT the same as an EventID.
|
|
|
|
* EventSubscriber development should not require use of EventID%s, if this
|
|
|
|
* indexing is required within-EventCallback consider an
|
|
|
|
* EventSubscriber%-unique indexing, counting mechanic.
|
|
|
|
*
|
|
|
|
* @return A unique ID for backing storage.
|
|
|
|
*/
|
|
|
|
EventID getEventID();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Plan the best set of indexes for event record access.
|
|
|
|
*
|
|
|
|
* @param start an inclusive time to begin searching.
|
|
|
|
* @param stop an inclusive time to end searching.
|
|
|
|
* @param list_key optional key to bind to a specific index binning.
|
|
|
|
*
|
|
|
|
* @return List of 'index.step' index strings.
|
|
|
|
*/
|
|
|
|
std::vector<std::string> getIndexes(EventTime start,
|
|
|
|
EventTime stop,
|
|
|
|
int list_key = 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Expire indexes and eventually records.
|
|
|
|
*
|
|
|
|
* @param list_type the string representation of list binning type.
|
|
|
|
* @param indexes complete set of 'index.step' indexes for the list_type.
|
|
|
|
* @param expirations of the indexes, the set to expire.
|
|
|
|
*
|
|
|
|
* @return status if the indexes and records were removed.
|
|
|
|
*/
|
|
|
|
Status expireIndexes(const std::string& list_type,
|
|
|
|
const std::vector<std::string>& indexes,
|
|
|
|
const std::vector<std::string>& expirations);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Add an EventID, EventTime pair to all matching list types.
|
|
|
|
*
|
|
|
|
* The list types are defined by time size. Based on the EventTime this pair
|
|
|
|
* is added to the list bin for each list type. If there are two list types:
|
|
|
|
* 60 seconds and 3600 seconds and `time` is 92, this pair will be added to
|
|
|
|
* list type 1 bin 4 and list type 2 bin 1.
|
|
|
|
*
|
|
|
|
* @param eid A unique EventID.
|
|
|
|
* @param time The time when this EventID%'s event occurred.
|
|
|
|
*
|
|
|
|
* @return Were the indexes recorded.
|
|
|
|
*/
|
2014-12-15 18:17:56 +00:00
|
|
|
Status recordEvent(EventID& eid, EventTime time);
|
2014-12-15 00:05:07 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @brief A single instance requirement for static callback facilities.
|
|
|
|
*
|
|
|
|
* The EventSubscriber constructor is NOT responsible for adding
|
|
|
|
* Subscription%s. Please use `init` for adding Subscription%s as all
|
|
|
|
* EventPublisher instances will have run `setUp` and initialized their run
|
|
|
|
* loops.
|
|
|
|
*/
|
2015-01-30 18:44:25 +00:00
|
|
|
EventSubscriberPlugin() {
|
2014-12-15 00:05:07 +00:00
|
|
|
expire_events_ = true;
|
|
|
|
expire_time_ = 0;
|
|
|
|
}
|
2015-02-01 11:32:18 +00:00
|
|
|
virtual ~EventSubscriberPlugin() {}
|
2014-12-15 00:05:07 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Suggested entrypoint for table generation.
|
|
|
|
*
|
|
|
|
* The EventSubscriber is a convention that removes a lot of boilerplate event
|
|
|
|
* subscriptioning and acting. The `genTable` static entrypoint is the
|
|
|
|
* suggested method for table specs.
|
|
|
|
*
|
|
|
|
* @return The query-time table data, retrieved from a backing store.
|
|
|
|
*/
|
2014-12-15 08:25:28 +00:00
|
|
|
virtual QueryData genTable(tables::QueryContext& context)
|
|
|
|
__attribute__((used)) {
|
|
|
|
return get(0, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// The string name identifying this EventSubscriber.
|
2015-02-01 11:32:18 +00:00
|
|
|
virtual EventSubscriberID name() const { return "subscriber"; }
|
2014-12-15 00:05:07 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/// Backing storage indexing namespace definition methods.
|
2015-02-01 11:32:18 +00:00
|
|
|
EventPublisherID dbNamespace() const { return type() + "." + name(); }
|
2014-12-18 04:10:51 +00:00
|
|
|
|
2014-12-15 00:05:07 +00:00
|
|
|
/// The string EventPublisher identifying this EventSubscriber.
|
2015-02-01 11:32:18 +00:00
|
|
|
virtual EventPublisherID type() const = 0;
|
2014-12-15 08:25:28 +00:00
|
|
|
|
2014-12-15 00:05:07 +00:00
|
|
|
/// Disable event expiration for this subscriber.
|
|
|
|
void doNotExpire() { expire_events_ = false; }
|
|
|
|
|
2015-02-01 11:32:18 +00:00
|
|
|
private:
|
|
|
|
EventSubscriberPlugin(EventSubscriberPlugin const&);
|
|
|
|
void operator=(EventSubscriberPlugin const&);
|
|
|
|
|
2014-12-15 00:05:07 +00:00
|
|
|
private:
|
|
|
|
/// Do not respond to periodic/scheduled/triggered event expiration requests.
|
|
|
|
bool expire_events_;
|
|
|
|
|
|
|
|
/// Events before the expire_time_ are invalid and will be purged.
|
|
|
|
EventTime expire_time_;
|
|
|
|
|
|
|
|
/// Lock used when incrementing the EventID database index.
|
|
|
|
boost::mutex event_id_lock_;
|
|
|
|
|
|
|
|
/// Lock used when recording an EventID and time into search bins.
|
|
|
|
boost::mutex event_record_lock_;
|
|
|
|
|
|
|
|
private:
|
|
|
|
FRIEND_TEST(EventsDatabaseTests, test_event_module_id);
|
|
|
|
FRIEND_TEST(EventsDatabaseTests, test_record_indexing);
|
|
|
|
FRIEND_TEST(EventsDatabaseTests, test_record_range);
|
|
|
|
FRIEND_TEST(EventsDatabaseTests, test_record_expiration);
|
|
|
|
};
|
|
|
|
|
2015-02-19 07:51:41 +00:00
|
|
|
/**
|
|
|
|
* @brief A factory for associating event generators to EventPublisherID%s.
|
|
|
|
*
|
|
|
|
* This factory both registers new event types and the subscriptions that use
|
|
|
|
* them. An EventPublisher is also a factory, the single event factory arbitates
|
|
|
|
* Subscription creatating and management for each associated EventPublisher.
|
|
|
|
*
|
|
|
|
* Since event types may be plugins, they are created using the factory.
|
|
|
|
* Since subscriptions may be configured/disabled they are also factory-managed.
|
|
|
|
*/
|
|
|
|
class EventFactory {
|
|
|
|
public:
|
|
|
|
/// Access to the EventFactory instance.
|
|
|
|
static EventFactory& getInstance();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Add an EventPublisher to the factory.
|
|
|
|
*
|
|
|
|
* The registration is mostly abstracted using osquery's registery.
|
|
|
|
*
|
|
|
|
* @param event_pub If for some reason the caller needs access to the
|
|
|
|
* EventPublisher instance they can register-by-instance.
|
|
|
|
*
|
|
|
|
* Access to the EventPublisher instance is not discouraged, but using the
|
|
|
|
* EventFactory `getEventPublisher` accessor is encouraged.
|
|
|
|
*/
|
|
|
|
static Status registerEventPublisher(const PluginRef& pub);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Add an EventSubscriber to the factory.
|
|
|
|
*
|
|
|
|
* The registration is mostly abstracted using osquery's registry.
|
|
|
|
*/
|
|
|
|
template <class T>
|
|
|
|
static Status registerEventSubscriber() {
|
|
|
|
auto sub = std::make_shared<T>();
|
|
|
|
return registerEventSubscriber(sub);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Add an EventSubscriber to the factory.
|
|
|
|
*
|
|
|
|
* The registration is mostly abstracted using osquery's registry.
|
|
|
|
*
|
|
|
|
* @param sub If the caller must access the EventSubscriber instance
|
|
|
|
* control may be passed to the registry.
|
|
|
|
*
|
|
|
|
* Access to the EventSubscriber instance outside of the within-instance
|
|
|
|
* table generation method and set of EventCallback%s is discouraged.
|
|
|
|
*/
|
|
|
|
static Status registerEventSubscriber(const PluginRef& sub);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Add a SubscriptionContext and EventCallback Subscription to an
|
|
|
|
*EventPublisher.
|
|
|
|
*
|
|
|
|
* Create a Subscription from a given SubscriptionContext and EventCallback
|
|
|
|
* and add that Subscription to the EventPublisher associated identifier.
|
|
|
|
*
|
|
|
|
* @param type_id The string for an EventPublisher receiving the Subscription.
|
|
|
|
* @param mc A SubscriptionContext related to the EventPublisher.
|
|
|
|
* @param cb When the EventPublisher fires an event the SubscriptionContext
|
|
|
|
* will be evaluated, if the event matches optional specifics in the context
|
|
|
|
* this callback function will be called. It should belong to an
|
|
|
|
* EventSubscription.
|
|
|
|
*
|
|
|
|
* @return Was the SubscriptionContext appropriate for the EventPublisher.
|
|
|
|
*/
|
|
|
|
static Status addSubscription(EventPublisherID& type_id,
|
|
|
|
const SubscriptionContextRef& mc,
|
|
|
|
EventCallback cb = 0,
|
|
|
|
void* user_data = nullptr);
|
|
|
|
|
|
|
|
/// Add a Subscription by templating the EventPublisher, using a
|
|
|
|
/// SubscriptionContext.
|
|
|
|
template <typename PUB>
|
|
|
|
static Status addSubscription(const SubscriptionContextRef& mc,
|
|
|
|
EventCallback cb = 0) {
|
|
|
|
return addSubscription(BaseEventPublisher::getType<PUB>(), mc, cb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Add a Subscription using a caller Subscription instance.
|
|
|
|
static Status addSubscription(EventPublisherID& type_id,
|
|
|
|
const SubscriptionRef& subscription);
|
|
|
|
|
|
|
|
/// Get the total number of Subscription%s across ALL EventPublisher%s.
|
|
|
|
static size_t numSubscriptions(EventPublisherID& type_id);
|
|
|
|
|
|
|
|
/// Get the number of EventPublishers.
|
|
|
|
static size_t numEventPublishers() {
|
|
|
|
return EventFactory::getInstance().event_pubs_.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Halt the EventPublisher run loop and call its `tearDown`.
|
|
|
|
*
|
|
|
|
* Any EventSubscriber%s with Subscription%s for this EventPublisher will
|
|
|
|
* become useless. osquery callers MUST deregister events.
|
|
|
|
* EventPublisher%s assume they can hook/trampoline, which requires cleanup.
|
|
|
|
*
|
|
|
|
* @param event_pub The string label for the EventPublisher.
|
|
|
|
*
|
|
|
|
* @return Did the EventPublisher deregister cleanly.
|
|
|
|
*/
|
|
|
|
static Status deregisterEventPublisher(const EventPublisherRef& pub);
|
|
|
|
|
|
|
|
/// Deregister an EventPublisher by EventPublisherID.
|
|
|
|
static Status deregisterEventPublisher(EventPublisherID& type_id);
|
|
|
|
|
|
|
|
/// Return an instance to a registered EventPublisher.
|
|
|
|
static EventPublisherRef getEventPublisher(EventPublisherID& pub);
|
|
|
|
|
|
|
|
/// Return an instance to a registered EventSubscriber.
|
|
|
|
static EventSubscriberRef getEventSubscriber(EventSubscriberID& pub);
|
|
|
|
|
|
|
|
static std::vector<std::string> publisherTypes();
|
|
|
|
static std::vector<std::string> subscriberNames();
|
|
|
|
|
|
|
|
public:
|
|
|
|
/// The dispatched event thread's entry-point (if needed).
|
|
|
|
static Status run(EventPublisherID& type_id);
|
|
|
|
|
|
|
|
/// An initializer's entry-point for spawning all event type run loops.
|
|
|
|
static void delay();
|
|
|
|
|
|
|
|
/// If a static EventPublisher callback wants to fire
|
|
|
|
template <typename PUB>
|
|
|
|
static void fire(const EventContextRef& ec) {
|
|
|
|
auto event_pub = getEventPublisher(BaseEventPublisher::getType<PUB>());
|
|
|
|
event_pub->fire(ec);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief End all EventPublisher run loops and call their `tearDown` methods.
|
|
|
|
*
|
|
|
|
* End is NOT the same as deregistration.
|
|
|
|
*
|
|
|
|
* @param should_end Reset the "is ending" state if False.
|
|
|
|
*/
|
|
|
|
static void end(bool join = false);
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// An EventFactory will exist for the lifetime of the application.
|
|
|
|
EventFactory() {}
|
|
|
|
EventFactory(EventFactory const&);
|
|
|
|
void operator=(EventFactory const&);
|
|
|
|
~EventFactory() {}
|
|
|
|
|
|
|
|
private:
|
|
|
|
/// Set of registered EventPublisher instances.
|
|
|
|
std::map<EventPublisherID, EventPublisherRef> event_pubs_;
|
|
|
|
|
|
|
|
/// Set of instantiated EventSubscriber subscriptions.
|
|
|
|
std::map<EventSubscriberID, EventSubscriberRef> event_subs_;
|
|
|
|
|
|
|
|
/// Set of running EventPublisher run loop threads.
|
|
|
|
std::vector<std::shared_ptr<boost::thread> > threads_;
|
|
|
|
};
|
|
|
|
|
2014-12-15 00:05:07 +00:00
|
|
|
/**
|
|
|
|
* @brief An interface binding Subscriptions, event response, and table
|
|
|
|
*generation.
|
|
|
|
*
|
|
|
|
* Use the EventSubscriber interface when adding event subscriptions and
|
|
|
|
* defining callin functions. The EventCallback is usually a member function
|
|
|
|
* for an EventSubscriber. The EventSubscriber interface includes a very
|
|
|
|
* important `add` method that abstracts the needed event to backing store
|
|
|
|
* interaction.
|
|
|
|
*
|
|
|
|
* Storing event data in the backing store must match a table spec for queries.
|
|
|
|
* Small overheads exist that help query-time indexing and lookups.
|
|
|
|
*/
|
|
|
|
template <class PUB>
|
2015-01-30 18:44:25 +00:00
|
|
|
class EventSubscriber : public EventSubscriberPlugin {
|
2014-12-15 00:05:07 +00:00
|
|
|
protected:
|
|
|
|
typedef typename PUB::SCRef SCRef;
|
|
|
|
typedef typename PUB::ECRef ECRef;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* @brief Add Subscription%s to the EventPublisher this module will act on.
|
|
|
|
*
|
|
|
|
* When the EventSubscriber%'s `init` method is called you are assured the
|
|
|
|
* EventPublisher has `setUp` and is ready to subscription for events.
|
|
|
|
*/
|
|
|
|
virtual void init() {}
|
|
|
|
|
2014-12-18 04:10:51 +00:00
|
|
|
/// Helper function to call the publisher's templated subscription generator.
|
2015-02-01 11:32:18 +00:00
|
|
|
SCRef createSubscriptionContext() const {
|
|
|
|
return PUB::createSubscriptionContext();
|
|
|
|
}
|
2014-12-15 06:17:38 +00:00
|
|
|
|
2014-12-18 04:10:51 +00:00
|
|
|
/**
|
|
|
|
* @brief Bind a registered EventSubscriber member function to a Subscription.
|
|
|
|
*
|
|
|
|
* @param entry A templated EventSubscriber member function.
|
|
|
|
* @param sc The subscription context.
|
|
|
|
*/
|
2014-12-15 06:17:38 +00:00
|
|
|
template <class T, typename C>
|
2015-02-18 02:04:15 +00:00
|
|
|
void subscribe(Status (T::*entry)(const std::shared_ptr<C>&, const void*),
|
|
|
|
const SubscriptionContextRef& sc,
|
|
|
|
void* user_data) {
|
2014-12-18 04:10:51 +00:00
|
|
|
// Up-cast the CRTP-style EventSubscriber to the caller.
|
2014-12-15 05:20:20 +00:00
|
|
|
auto self = dynamic_cast<T*>(this);
|
2014-12-18 04:10:51 +00:00
|
|
|
// Down-cast the pointer to the member function.
|
2014-12-15 06:17:38 +00:00
|
|
|
auto base_entry =
|
2015-02-18 02:04:15 +00:00
|
|
|
reinterpret_cast<Status (T::*)(const EventContextRef&, void const*)>(
|
|
|
|
entry);
|
2015-02-19 07:51:41 +00:00
|
|
|
// Create a callable through the member function using the instance of the
|
2014-12-18 04:10:51 +00:00
|
|
|
// EventSubscriber and a single parameter placeholder (the EventContext).
|
2015-02-18 02:04:15 +00:00
|
|
|
auto cb = std::bind(base_entry, self, _1, _2);
|
2014-12-18 04:10:51 +00:00
|
|
|
// Add a subscription using the callable and SubscriptionContext.
|
2015-02-18 02:04:15 +00:00
|
|
|
EventFactory::addSubscription(type(), sc, cb, user_data);
|
2014-12-15 05:20:20 +00:00
|
|
|
}
|
|
|
|
|
2014-12-18 04:10:51 +00:00
|
|
|
/// Helper EventPublisher string type accessor.
|
2015-02-01 11:32:18 +00:00
|
|
|
EventPublisherID type() const { return BaseEventPublisher::getType<PUB>(); }
|
2014-12-15 00:05:07 +00:00
|
|
|
|
|
|
|
private:
|
2014-12-15 05:20:20 +00:00
|
|
|
FRIEND_TEST(EventsTests, test_event_sub);
|
|
|
|
FRIEND_TEST(EventsTests, test_event_sub_subscribe);
|
|
|
|
FRIEND_TEST(EventsTests, test_event_sub_context);
|
2014-12-15 00:05:07 +00:00
|
|
|
};
|
2014-09-24 15:03:16 +00:00
|
|
|
|
2015-01-30 18:44:25 +00:00
|
|
|
/// Iterate the event publisher registry and create run loops for each using
|
|
|
|
/// the event factory.
|
|
|
|
void attachEvents();
|
2014-09-24 15:03:16 +00:00
|
|
|
|
2015-02-19 23:19:00 +00:00
|
|
|
/// Sleep in a boost::thread interruptable state.
|
|
|
|
void interruptableSleep(size_t milli);
|
|
|
|
|
2015-03-04 02:40:24 +00:00
|
|
|
CREATE_REGISTRY(EventPublisherPlugin, "event_publisher");
|
|
|
|
CREATE_LAZY_REGISTRY(EventSubscriberPlugin, "event_subscriber");
|
2014-09-24 18:25:05 +00:00
|
|
|
}
|