mirror of
https://github.com/valitydev/osquery-1.git
synced 2024-11-06 17:45:22 +00:00
95cd57a576
Summary: There is unnecessary redundancy of how error message now is created. It could be with string argument: return createError(ConversionError::InvalidArgument, "Wrong string representation of boolean ", prop_exp.takeError()) << boost::io::quoted(from); And it could be without it: return createError(ConversionError::InvalidArgument, prop_exp.takeError()) << "Wrong string representation of boolean " << boost::io::quoted(from); So, my suggestion is to make it uniform - use only second option and form error string only with operator<<. This diff introduce function overload without message within argument list and some usage examples. If everyone ok with it, I'll remove all cases of 3 args form usage in next diff. Reviewed By: mkareta Differential Revision: D14405326 fbshipit-source-id: 47074de1f078e512c95518439557adadcf83cbd3
48 lines
1.3 KiB
C++
48 lines
1.3 KiB
C++
/**
|
|
* Copyright (c) 2018-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed in accordance with the terms specified in
|
|
* 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, ret.takeError())
|
|
<< "Calling subscribe() on publisher '" << it->second->name()
|
|
<< "' for subscription from request from '" << sub->subscriber()
|
|
<< "' returned an error.";
|
|
}
|
|
} 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
|