osquery-1/osquery/ev2/manager.cpp
Filipe Manco 438a6e1464 Basic ev2 framework (#5401)
Summary:
Pull Request resolved: https://github.com/facebook/osquery/pull/5401

Extremely rough implementation of the basic componenets to get things going.

Blueprint issue #5158 .

Reviewed By: akindyakov

Differential Revision: D13779295

fbshipit-source-id: c7373794e8152ffea8a7c5d97f0c937bf97a2a0a
2019-01-29 09:30:20 -08:00

50 lines
1.4 KiB
C++

/**
* Copyright (c) 2018-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed as defined on the LICENSE file found in the
* root directory of this source tree.
*/
#include <osquery/ev2/manager.h>
#include <osquery/utils/expected/expected.h>
#include <mutex>
namespace osquery {
namespace ev2 {
ExpectedSuccess<EventManager::Error> EventManager::bind(
std::shared_ptr<Subscription> sub) {
std::unique_lock<std::mutex> lock(mutex_);
auto it = publishers_.find(sub->pubType());
if (it != publishers_.end()) {
auto ret = it->second->subscribe(std::move(sub));
if (ret.isError()) {
return createError(Error::PublisherError,
"Calling subscribe() on publisher '" +
it->second->name() +
"' for subscription from request from '" +
sub->subscriber() + "' returned an error.",
ret.takeError());
}
} else {
return createError(Error::UnknownPublisher,
"No registered publisher for bind request from '" +
sub->subscriber() + "'");
}
return Success();
}
void EventManager::registerPublisher(std::shared_ptr<Publisher> pub) {
std::unique_lock<std::mutex> lock(mutex_);
auto& r = *pub.get();
publishers_[typeid(r)] = std::move(pub);
}
} // namespace ev2
} // namespace osquery