class Archive final {
public:
template<typename Front, typename... Rest>
- void pack(const Front& front, const Rest&... rest);
+ void pack(const Front& front, const Rest& ... rest);
inline void pack(void) {}
template<typename Front, typename... Rest>
- void unpack(Front& front, Rest&... rest);
+ void unpack(Front& front, Rest& ... rest);
inline void unpack(void) {}
template<typename... Ts>
// serialize method
template<typename T, IsFundamental<T> = 0>
- Archive& operator<<(const T& value);
+ Archive & operator<<(const T& value);
template<typename T, IsArchival<T> = 0>
- Archive& operator<<(const T& object);
+ Archive & operator<<(const T& object);
template<typename T>
Archive& operator<<(const std::vector<T>& values);
template<typename K, typename V>
// deserialize method
template<typename T, IsFundamental<T> = 0>
- Archive& operator>>(T& value);
+ Archive & operator>>(T& value);
template<typename T, IsArchival<T> = 0>
- Archive& operator>>(T& object);
+ Archive & operator>>(T& object);
template<typename T>
Archive& operator>>(std::vector<T>& values);
template<typename K, typename V>
};
template<typename Front, typename... Rest>
-void Archive::pack(const Front& front, const Rest&... rest)
+void Archive::pack(const Front& front, const Rest& ... rest)
{
*this << front;
this->pack(rest...);
}
template<typename Front, typename... Rest>
-void Archive::unpack(Front& front, Rest&... rest)
+void Archive::unpack(Front& front, Rest& ... rest)
{
*this >> front;
this->unpack(rest...);
#include <vist/rmi/remote.hpp>
namespace {
- const std::string SOCK_ADDR = "/tmp/.vist";
+const std::string SOCK_ADDR = "/tmp/.vist";
} // anonymous namespace
namespace vist {
VirtualTable<Policy<int>> table;
EXPECT_TRUE(table.size() > 0);
- for(const auto& row : table) {
+ for (const auto& row : table) {
Policy<int> policy = { row[&Policy<int>::name], row[&Policy<int>::value] };
INFO(VIST_CLIENT) << "[Test] Policy<int> table:";
VirtualTable<Policy<std::string>> table;
EXPECT_TRUE(table.size() > 0);
- for(const auto& row : table) {
+ for (const auto& row : table) {
Policy<std::string> policy = {
row[&Policy<std::string>::name],
row[&Policy<std::string>::value]
using namespace vist::schema;
Table policyInt { "policy", Column("name", &Policy<int>::name),
- Column("value", &Policy<int>::value) };
+ Column("value", &Policy<int>::value) };
Table policyStr { "policy", Column("name", &Policy<std::string>::name),
- Column("value", &Policy<std::string>::value) };
+ Column("value", &Policy<std::string>::value) };
Database metaDB { "db", policyInt, policyStr };
template<typename Struct, typename Member>
Member operator[](Member Struct::*) const;
- inline std::size_t size() const { return data.size(); }
+ inline std::size_t size() const
+ {
+ return data.size();
+ }
private:
KeyValuePair data;
using Iter = typename std::vector<VirtualRow<T>>::iterator;
using CIter = typename std::vector<VirtualRow<T>>::const_iterator;
- inline Iter begin() { return rows.begin(); }
- inline CIter begin() const { return rows.cbegin(); }
- inline Iter end() { return rows.end(); }
- inline CIter end() const { return rows.end(); }
+ inline Iter begin()
+ {
+ return rows.begin();
+ }
+ inline CIter begin() const
+ {
+ return rows.cbegin();
+ }
+ inline Iter end()
+ {
+ return rows.end();
+ }
+ inline CIter end() const
+ {
+ return rows.end();
+ }
- inline std::size_t size() const { return rows.size(); }
+ inline std::size_t size() const
+ {
+ return rows.size();
+ }
template<typename Struct, typename Member>
VirtualRow<T>& filter(Member Struct::*field, const std::string& name)
bool raised = false;
try {
Process::GetIdentifier(-1);
- } catch(...) {
+ } catch (...) {
raised = true;
}
try {
strip(origin, '[', ']');
EXPECT_TRUE(false);
- } catch(...) {
+ } catch (...) {
EXPECT_TRUE(true);
}
}
TEST(ThreadPoolTests, once)
{
int count = 0;
- auto task = [&count]{ count++; };
+ auto task = [&count] { count++; };
ThreadPool worker(5);
worker.submit(task);
TEST(ThreadPoolTests, multiple)
{
int count = 0;
- auto task = [&count]{ count++; };
+ auto task = [&count] { count++; };
ThreadPool worker(5);
std::size_t repeat = 10;
ThreadPool::ThreadPool(std::size_t threads)
{
for (std::size_t i = 0; i < threads; i++) {
- workers.emplace_back([this] {
- while (true) {
+ workers.emplace_back([this] {
+ while (true)
+ {
std::function<void()> task;
__BEGIN_CRITICAL__
- condition.wait(lock, [this]{ return stop || !tasks.empty();});
+ condition.wait(lock, [this] { return stop || !tasks.empty();});
if (stop && tasks.empty()) {
return;
}
condition.notify_all();
- for (std::thread &worker: workers) {
+ for (std::thread& worker : workers) {
if (worker.joinable()) {
worker.join();
}
const char* Column::getText() const
{
- return reinterpret_cast<const char *>(sqlite3_column_text(statement, index));
+ return reinterpret_cast<const char*>(sqlite3_column_text(statement, index));
}
const void* Column::getBlob() const
return getDouble();
}
- operator const char*() const
+ operator const char* () const
{
return getText();
}
- operator const void*() const
+ operator const void* () const
{
return getBlob();
}
if (integrityCheck) {
bool verified = false;
- sqlite3_stmt *integrity = NULL;
- if (::sqlite3_prepare_v2(handle, "PRAGMA integrity_check;", -1, &integrity, NULL) == SQLITE_OK ) {
+ sqlite3_stmt* integrity = NULL;
+ if (::sqlite3_prepare_v2(handle, "PRAGMA integrity_check;", -1, &integrity, NULL) == SQLITE_OK) {
while (::sqlite3_step(integrity) == SQLITE_ROW) {
- const unsigned char *result = ::sqlite3_column_text(integrity, 0);
- if (result && ::strcmp((const char *)result, (const char *)"ok") == 0) {
+ const unsigned char* result = ::sqlite3_column_text(integrity, 0);
+ if (result && ::strcmp((const char*)result, (const char*)"ok") == 0) {
verified = true;
break;
}
bool raised = false;
try {
- const char *str = "PACKAGE";
- void *blob = (void *)str;
+ const char* str = "PACKAGE";
+ void* blob = (void*)str;
double user = 5001;
sqlite3_int64 used = 1;
std::string key = "test key";
std::string query = "INSERT INTO CLIENT VALUES (NULL, :PKG, :KEY, :IS_USED, :USER)";
try {
- const char *str = "PACKAGE";
- void *blob = (void *)str;
+ const char* str = "PACKAGE";
+ void* blob = (void*)str;
double user = 5001;
sqlite3_int64 used = 1;
std::string key = "test key";
try {
database::Connection db(TEST_DB_PATH);
int loop = 500;
- while (loop--)
- {
+ while (loop--) {
database::Statement(db, query).exec();
}
} catch (const vist::Exception<ErrCode>& e) {
database::Connection db(TEST_DB_PATH);
db.transactionBegin();
int loop = 500;
- while (loop--)
- {
+ while (loop--) {
database::Statement(db, query).exec();
}
db.transactionEnd();
database::Connection db(TEST_DB_PATH);
db.exec("BEGIN TRANSACTION;");
int loop = 500;
- while (loop--)
- {
+ while (loop--) {
database::Statement(db, query).exec();
}
db.exec("END TRANSACTION;");
using Self = Exception<ErrCode>;
- Exception(ErrCode ec, const char *file,
- const char *function, unsigned int line) noexcept : ec(ec)
+ Exception(ErrCode ec, const char* file,
+ const char* function, unsigned int line) noexcept : ec(ec)
{
std::stringstream ss;
ss << "[" << file << ":" << line << " " << function << "()]"
namespace {
template<std::size_t N, std::size_t... S>
-struct SequenceExpansion : SequenceExpansion<N-1, N-1, S...> {};
+struct SequenceExpansion : SequenceExpansion < N - 1, N - 1, S... > {};
template<std::size_t... S>
-struct SequenceExpansion<0, S...> { using Type = IndexSequence<S...>; };
+struct SequenceExpansion<0, S...> {
+ using Type = IndexSequence<S...>;
+};
template<>
-struct SequenceExpansion<0> { using Type = EmptySequence; };
+struct SequenceExpansion<0> {
+ using Type = EmptySequence;
+};
} // anonymous namespace
void push(const Type& data)
{
auto value = std::make_shared<Value>();
- if constexpr (std::is_same_v<Type, Array> || std::is_same_v<Type, Object>) {
+ if constexpr(std::is_same_v<Type, Array> || std::is_same_v<Type, Object>) {
auto real = std::make_shared<Type>();
*real = data;
value->leaf = real;
- } else if constexpr (std::is_same_v<Type, Null>) {
+ } else if constexpr(std::is_same_v<Type, Null>) {
value->leaf = std::make_shared<Null>();
} else {
*value = data;
/*
* Usable JSON header-only library.
* - Applied design pattern: Composite pattern
- * - Component structure: Value
+ * - Component structure: Value
* - Leaf structure: Int, String, Bool, Null
* - Composite structure: Array, Object
*/
* Json json;
* json["name"] = "sangwan";
* json["age"] = 99;
- *
+ *
* // Get json value
* std::string name = json["name"];
* int age = json["age"];
{
auto value = std::make_shared<Value>();
auto composite = std::make_shared<CompositeType>();
- if constexpr (std::is_same_v<CompositeType, Array>)
+ if constexpr(std::is_same_v<CompositeType, Array>)
composite->buffer = std::move(child.buffer);
- else if constexpr (std::is_same_v<CompositeType, Object>)
+ else if constexpr(std::is_same_v<CompositeType, Object>)
composite->pairs = std::move(child.pairs);
else
static_assert(dependent_false<CompositeType>::value, "Only Composite type supported.");
if (!this->exist(key))
throw std::runtime_error("Not exist key.");
- if constexpr (std::is_same_v<CompositeType, Array> ||
- std::is_same_v<CompositeType, Object>) {
+ if constexpr(std::is_same_v<CompositeType, Array> ||
+ std::is_same_v<CompositeType, Object>) {
if (auto downcast = std::dynamic_pointer_cast<CompositeType>(this->pairs[key]->leaf);
downcast == nullptr)
throw std::runtime_error(key + "Mismatched type.");
try {
static_cast<std::string>(json["int"]);
EXPECT_TRUE(false);
- } catch(...) {
+ } catch (...) {
EXPECT_TRUE(true);
}
}
try {
static_cast<int>(json["string"]);
EXPECT_TRUE(false);
- } catch(...) {
+ } catch (...) {
EXPECT_TRUE(true);
}
}
document.push("constraints", constraints);
EXPECT_EQ(document.serialize(), "{ \"constraints\": [ { \"affinity\": \"TEXT\", "
- "\"name\": \"test_int\", "
- "\"list\": [ { \"expr\": \"2\", \"op\": 2 } ] } ] }");
+ "\"name\": \"test_int\", "
+ "\"list\": [ { \"expr\": \"2\", \"op\": 2 } ] } ] }");
}
{
// "string": "root value" }
auto serialized = json.serialize();
EXPECT_EQ(serialized, "{ \"array\": [ 3, \"array value\" ], "
- "\"object\": { \"string\": \"child value\", \"int\": 2 }, "
- "\"int\": 1, "
- "\"string\": \"root value\" }");
+ "\"object\": { \"string\": \"child value\", \"int\": 2 }, "
+ "\"int\": 1, "
+ "\"string\": \"root value\" }");
Json restore;
restore.deserialize(serialized);
inline std::vector<std::string> canonicalize(std::vector<std::string>& tokens)
{
std::vector<std::string> result;
- auto rearrange = [&](std::vector<std::string>::iterator& iter, char first, char last) {
+ auto rearrange = [&](std::vector<std::string>::iterator & iter, char first, char last) {
if ((*iter).find(first) == std::string::npos)
return false;
throw std::invalid_argument("Dumped value cannot empty.");
switch (dumped[0]) {
- case '{' : this->convert<Object>(); break;
- case '[' : this->convert<Array>(); break;
- case '"': this->convert<String>(); break;
- case 'n': this->convert<Null>(); break;
- case 't': // fall through
- case 'f' : this->convert<Bool>(); break;
- default : {
- if (dumped.find(".") == std::string::npos)
- this->convert<Int>();
- else
- this->convert<Double>();
- }
+ case '{' :
+ this->convert<Object>();
+ break;
+ case '[' :
+ this->convert<Array>();
+ break;
+ case '"':
+ this->convert<String>();
+ break;
+ case 'n':
+ this->convert<Null>();
+ break;
+ case 't': // fall through
+ case 'f' :
+ this->convert<Bool>();
+ break;
+ default : {
+ if (dumped.find(".") == std::string::npos)
+ this->convert<Int>();
+ else
+ this->convert<Double>();
+ }
}
this->leaf->deserialize(dumped);
template <typename Type>
Value& operator=(const Type& data)
{
- if constexpr (std::is_same_v<Type, int>)
+ if constexpr(std::is_same_v<Type, int>)
this->leaf = std::make_shared<Int>(data);
- else if constexpr (std::is_same_v<Type, double>)
+ else if constexpr(std::is_same_v<Type, double>)
this->leaf = std::make_shared<Double>(data);
- else if constexpr (std::is_same_v<typename std::decay<Type>::type, std::string> ||
- std::is_same_v<typename std::decay<Type>::type, char*>)
+ else if constexpr(std::is_same_v<typename std::decay<Type>::type, std::string> ||
+ std::is_same_v<typename std::decay<Type>::type, char*>)
this->leaf = std::make_shared<String>(data);
- else if constexpr (std::is_same_v<Type, bool>)
+ else if constexpr(std::is_same_v<Type, bool>)
this->leaf = std::make_shared<Bool>(data);
- else if constexpr (std::is_same_v<Type, std::nullptr_t>)
+ else if constexpr(std::is_same_v<Type, std::nullptr_t>)
this->leaf = std::make_shared<Null>();
else
static_assert(dependent_false<Type>::value, "Not supported type.");
if (dumped[0] != '"' || dumped[dumped.size() - 1] != '"')
throw std::invalid_argument("Wrong format.");
- this->data = dumped.substr(1, dumped.size() -2);
+ this->data = dumped.substr(1, dumped.size() - 2);
}
operator std::string() override
using Klass = K;
using Return = R;
using Parameters = std::tuple<remove_cv_ref_t<Ps>...>;
- using Pointer = Return (Klass::*)(Ps...);
+ using Pointer = Return(Klass::*)(Ps...);
auto get(void) noexcept -> const Pointer&;
explicit Function(Pointer pointer);
template<typename RR, typename KK, typename... PPs>
- friend Function<RR, KK, PPs...> make_function(RR (KK::* member)(PPs...));
+ friend Function<RR, KK, PPs...> make_function(RR(KK::* member)(PPs...));
Pointer pointer;
};
}
template<typename R, typename K, typename... Ps>
-Function<R, K, Ps...> make_function(R (K::* member)(Ps...))
+Function<R, K, Ps...> make_function(R(K::* member)(Ps...))
{
constexpr bool notVoid = !(std::is_same<R, void>::value);
static_assert(notVoid, "Return type cannot be void.");
struct AbstractFunctor {
template<typename R, typename...Args>
- R invoke(Args&&... args);
+ R invoke(Args&& ... args);
inline Archive invoke(Archive& archive);
protected:
explicit Functor(Klass& instance, MemFunc memFunc);
template<typename... Args>
- auto operator()(Args&&... args) -> typename MemFunc::Return;
+ auto operator()(Args&& ... args) -> typename MemFunc::Return;
inline auto operator()(Archive& archive) -> typename MemFunc::Return;
protected:
};
template<typename R, typename...Args>
-R AbstractFunctor::invoke(Args&&... args)
+R AbstractFunctor::invoke(Args&& ... args)
{
Archive parameters;
parameters.pack(std::forward<Args>(args)...);
template<typename R, typename K, typename... Ps>
template<typename... Args>
-auto Functor<R, K, Ps...>::operator()(Args&&... args) -> typename MemFunc::Return
+auto Functor<R, K, Ps...>::operator()(Args&& ... args) -> typename MemFunc::Return
{
const Invokable& invokable = this->memFunc.get();
return invokable(this->instance, std::forward<Args>(args)...);
}
template<typename R, typename K, typename... Ps>
-Functor<R, K, Ps...> make_functor(K& instance, R (K::* member)(Ps...))
+Functor<R, K, Ps...> make_functor(K& instance, R(K::* member)(Ps...))
{
return Functor<R, K, Ps...>(instance, make_function(member));
}
template<typename R, typename K, typename... Ps>
std::shared_ptr<Functor<R, K, Ps...>> make_functor_ptr(K& instance,
- R (K::* member)(Ps...))
+ R(K::* member)(Ps...))
{
return std::make_shared<Functor<R, K, Ps...>>(instance, make_function(member));
}
return false;
}
-// void impossible(void) {}
+ // void impossible(void) {}
std::string name;
};
auto fooSetName = make_functor(foo, &Foo::setName);
auto fooGetName = make_functor(foo, &Foo::getName);
auto fooEcho = make_functor(foo, &Foo::echo);
-// auto fooImp = make_functor(foo, &Foo::impossible);
+ // auto fooImp = make_functor(foo, &Foo::impossible);
std::string input = "Foo name";
bool ret = true;
#ifndef __FILENAME__
#define __FILENAME__ \
-(::strrchr(__FILE__, '/') ? ::strrchr(__FILE__, '/') + 1 : __FILE__)
+ (::strrchr(__FILE__, '/') ? ::strrchr(__FILE__, '/') + 1 : __FILE__)
#endif
#define LOG(level, tag) vist::LogStream(LOGCAT(vist::LogLevel::level, #tag))
DEFINE_string(query, "", "Query statement to execute.");
-int main(int argc, char *argv[]) try {
+int main(int argc, char* argv[]) try
+{
gflags::SetUsageMessage("ViST default admin program.");
gflags::ParseCommandLineFlags(&argc, &argv, true);
std::cout << "Total " << rows.size() << "-rows." << std::endl;
}
return EXIT_SUCCESS;
-} catch(const Exception<ErrCode>& e) {
+} catch (const Exception<ErrCode>& e)
+{
std::cout << "Failed message: " << e.what() << std::endl;
return EXIT_FAILURE;
-} catch(const std::exception& e) {
+} catch (const std::exception& e)
+{
std::cout << "Failed message: " << e.what() << std::endl;
return EXIT_FAILURE;
}
using namespace vist;
-int main() try {
+int main() try
+{
#ifdef TIZEN
LogStream::Init(std::make_shared<Dlog>());
#endif
Vistd::Instance().Start();
return EXIT_SUCCESS;
-} catch(const Exception<ErrCode>& e) {
+} catch (const Exception<ErrCode>& e)
+{
ERROR(VIST) << "Failed while daemon is running." << e.what();
return EXIT_FAILURE;
-} catch(const std::exception& e) {
+} catch (const std::exception& e)
+{
ERROR(VIST) << "Failed while daemon is running." << e.what();
return EXIT_FAILURE;
}
#include <gtest/gtest.h>
-int main(int argc, char* argv[]) {
+int main(int argc, char* argv[])
+{
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
#include <vist/logger.hpp>
namespace {
- std::mutex mutex;
+std::mutex mutex;
} // anonymous namespace
namespace vist {
{
auto& notifier = Notification::instance();
- auto callback = [](const Row& row) {
+ auto callback = [](const Row & row) {
INFO(VIST) << "NotifyCallback called:";
for (const auto& r : row)
INFO(VIST) << "\t" << r.first << " : " << r.second;
{
auto& notifier = Notification::instance();
- auto callback = [](const Row& row) {
+ auto callback = [](const Row & row) {
INFO(VIST) << "NotifyCallback called:";
for (const auto& r : row)
INFO(VIST) << "\t" << r.first << " : " << r.second;
auto& notifier = Notification::instance();
int called = 0;
- auto callback = [&](const Row& row) {
+ auto callback = [&](const Row & row) {
INFO(VIST) << "NotifyCallback called:";
for (const auto& r : row)
INFO(VIST) << "\t" << r.first << " : " << r.second;
DECLARE_TABLE(AdminTable, "ADMIN", Admin::Name, Admin::Activated);
DECLARE_TABLE(PolicyManagedTable, "POLICY_MANAGED", PolicyManaged::Admin,
- PolicyManaged::Policy,
- PolicyManaged::Value);
+ PolicyManaged::Policy,
+ PolicyManaged::Value);
DECLARE_TABLE(PolicyDefinitionTable, "POLICY_DEFINITION", PolicyDefinition::Name,
- PolicyDefinition::Ivalue);
+ PolicyDefinition::Ivalue);
} // namespace schema
} // namespace policy
PluginLoader::PluginLoader(const std::string& path, int flag)
: handle(::dlopen(path.c_str(), flag), [](void*)->int{return 0;})
-// Cleaning object after dlclose() makes SEGFAULT.
-// TODO: Sync dynamic loading's life-cycle with program.(PluginManager)
-// : handle(::dlopen(path.c_str(), flag), ::dlclose)
+ // Cleaning object after dlclose() makes SEGFAULT.
+ // TODO: Sync dynamic loading's life-cycle with program.(PluginManager)
+ // : handle(::dlopen(path.c_str(), flag), ::dlclose)
{
if (handle == nullptr)
THROW(ErrCode::LogicError) << "Failed to open: " << path;
auto provider = this->policies[name];
auto iter = std::find_if(this->providers.begin(), this->providers.end(),
- [&provider](const std::unique_ptr<PolicyProvider>& p) {
- return p->getName() == provider;
- });
+ [&provider](const std::unique_ptr<PolicyProvider>& p) {
+ return p->getName() == provider;
+ });
if (iter == this->providers.end())
THROW(ErrCode::RuntimeError) << "Not exist provider[" << provider
<< "] about policy: " << name;
}
/// Make admin deactivated as default.
- Admin admin = {name , 0};
+ Admin admin = {name, 0};
std::string query = schema::AdminTable.insert(Admin::Name = admin.name,
Admin::Activated = admin.activated);
DEBUG(VIST) << "Activate admin: " << admin;
std::string query = schema::AdminTable.update(Admin::Activated = static_cast<int>(state))
- .where(Admin::Name == admin);
+ .where(Admin::Name == admin);
database::Statement stmt(*this->database, query);
if (!stmt.exec())
THROW(ErrCode::RuntimeError) << stmt.getErrorMessage();
this->admins[admin].activated = state;
- INFO(VIST) << "Admin[" << admin << "]'s activated value is set: " << state;
+ INFO(VIST) << "Admin[" << admin << "]'s activated value is set: " << state;
}
bool PolicyStorage::isActivated(const std::string& admin)
THROW(ErrCode::LogicError) << "Not exist policy: " << policy;
std::string query = schema::PolicyManagedTable.update(PolicyManaged::Value = value.dump())
- .where(PolicyManaged::Admin == admin &&
- PolicyManaged::Policy == policy);
+ .where(PolicyManaged::Admin == admin &&
+ PolicyManaged::Policy == policy);
database::Statement stmt(*this->database, query);
if (!stmt.exec())
THROW(ErrCode::RuntimeError) << stmt.getErrorMessage();
namespace vist {
namespace policy {
-TEST(PolicyCoreTests, policy_loader) {
+TEST(PolicyCoreTests, policy_loader)
+{
auto& manager = PolicyManager::Instance();
EXPECT_TRUE(manager.providers.size() > 0);
EXPECT_TRUE(manager.policies.size() > 0);
}
-TEST(PolicyCoreTests, policy_set_get_int) {
+TEST(PolicyCoreTests, policy_set_get_int)
+{
auto& manager = PolicyManager::Instance();
manager.enroll("testAdmin");
manager.set("sample-int-policy", PolicyValue(5), "testAdmin");
manager.disenroll("testAdmin1");
}
-TEST(PolicyCoreTests, policy_set_get_str) {
+TEST(PolicyCoreTests, policy_set_get_str)
+{
auto& manager = PolicyManager::Instance();
manager.enroll("testAdmin");
manager.set("sample-str-policy", PolicyValue("AAA"), "testAdmin");
manager.disenroll("testAdmin1");
}
-TEST(PolicyCoreTests, policy_get_all) {
+TEST(PolicyCoreTests, policy_get_all)
+{
auto& manager = PolicyManager::Instance();
auto policies = manager.getAll();
EXPECT_TRUE(policies.size() > 0);
}
-TEST(PolicyCoreTests, policy_get_policy) {
+TEST(PolicyCoreTests, policy_get_policy)
+{
auto& manager = PolicyManager::Instance();
const auto& policy = manager.getPolicy("sample-int-policy");
EXPECT_EQ(policy->getName(), "sample-int-policy");
EXPECT_TRUE(raised);
}
-TEST(PolicyCoreTests, admin) {
+TEST(PolicyCoreTests, admin)
+{
auto& manager = PolicyManager::Instance();
manager.enroll("testAdmin");
manager.disenroll("testAdmin");
}
-TEST(PolicyCoreTests, is_activated) {
+TEST(PolicyCoreTests, is_activated)
+{
auto& manager = PolicyManager::Instance();
manager.enroll("testAdmin1");
manager.enroll("testAdmin2");
private:
static std::string canonicalize(std::string&& s)
{
- { /// rtrim
- auto predicate = [](unsigned char c){ return std::isspace(c) || c == '\0'; };
+ {
+ /// rtrim
+ auto predicate = [](unsigned char c) {
+ return std::isspace(c) || c == '\0';
+ };
auto base = std::find_if(s.begin(), s.end(), predicate);
s.erase(base, s.end());
}
- { /// ltrim
- auto predicate = [](unsigned char c){ return c == '/'; };
+ {
+ /// ltrim
+ auto predicate = [](unsigned char c) {
+ return c == '/';
+ };
auto base = std::find_if(s.rbegin(), s.rend(), predicate).base();
s.erase(s.begin(), base);
}
class Crud {
public:
template<typename... ColumnTypes>
- T& select(ColumnTypes&&... cts);
+ T& select(ColumnTypes&& ... cts);
template<typename TableType>
T& selectAll(void);
T& selectAll(void);
template<typename... AssginExpressions>
- T& update(AssginExpressions&&... expression);
+ T& update(AssginExpressions&& ... expression);
template<typename... ColumnTypes>
- T& insert(ColumnTypes&&... cts);
+ T& insert(ColumnTypes&& ... cts);
template<typename... ColumnTypes>
- T& remove(ColumnTypes&&... cts);
+ T& remove(ColumnTypes&& ... cts);
template<typename Expr>
T& where(Expr expr);
private:
template<typename L, typename R>
- std::string processWhere(And<L,R>& expr);
+ std::string processWhere(And<L, R>& expr);
template<typename L, typename R>
- std::string processWhere(Or<L,R>& expr);
+ std::string processWhere(Or<L, R>& expr);
template<typename Expr>
std::string processWhere(const Expr& expr);
template<typename T>
template<typename... ColumnTypes>
-T& Crud<T>::select(ColumnTypes&&... cts)
+T& Crud<T>::select(ColumnTypes&& ... cts)
{
static_cast<T*>(this)->cache.clear();
template<typename T>
template<typename... AssginExpressions>
-T& Crud<T>::update(AssginExpressions&&... expression)
+T& Crud<T>::update(AssginExpressions&& ... expression)
{
static_cast<T*>(this)->cache.clear();
ss << "UPDATE " << static_cast<T*>(this)->name << " ";
ss << "SET ";
- auto closure = [&ss, this](const auto&... iter) {
+ auto closure = [&ss, this](const auto & ... iter) {
(static_cast<void>( /// Make fold expression possible
- (ss << static_cast<T*>(this)->getColumnName(iter.l) /// Column name
- << " " << static_cast<std::string>(iter) << " " /// Assign operator
- << iter.r << ", ") /// Value
- ), ...); /// Process fold expression
+ (ss << static_cast<T*>(this)->getColumnName(iter.l) /// Column name
+ << " " << static_cast<std::string>(iter) << " " /// Assign operator
+ << iter.r << ", ") /// Value
+ ), ...); /// Process fold expression
};
std::apply(closure, std::tuple(expression...));
template<typename T>
template<typename... ColumnTypes>
-T& Crud<T>::insert(ColumnTypes&&... expression)
+T& Crud<T>::insert(ColumnTypes&& ... expression)
{
static_cast<T*>(this)->cache.clear();
std::string query;
- {
+ {
std::stringstream ss;
ss << "INSERT INTO " << static_cast<T*>(this)->name << " (";
- auto onColumn = [&ss, this](const auto&... iter) {
+ auto onColumn = [&ss, this](const auto & ... iter) {
(static_cast<void>( /// Make fold expression possible
- (ss << static_cast<T*>(this)->getColumnName(iter.l) << ", ") /// Column name
- ), ...); /// Process fold expression
+ (ss << static_cast<T*>(this)->getColumnName(iter.l) << ", ") /// Column name
+ ), ...); /// Process fold expression
};
std::apply(onColumn, std::tuple(expression...));
{
std::stringstream ss;
- auto onValue = [&ss](const auto&... iter) {
+ auto onValue = [&ss](const auto & ... iter) {
(static_cast<void>((ss << iter.r) << ", "), ...); /// Process fold expression
};
std::apply(onValue, std::tuple(expression...));
template<typename T>
template<typename... ColumnTypes>
-T& Crud<T>::remove(ColumnTypes&&... cts)
+T& Crud<T>::remove(ColumnTypes&& ... cts)
{
static_cast<T*>(this)->cache.clear();
template<typename T>
template<typename L, typename R>
-std::string Crud<T>::processWhere(And<L,R>& expr)
+std::string Crud<T>::processWhere(And<L, R>& expr)
{
std::stringstream ss;
ss << this->processWhere(expr.l) << " ";
template<typename T>
template<typename L, typename R>
-std::string Crud<T>::processWhere(Or<L,R>& expr)
+std::string Crud<T>::processWhere(Or<L, R>& expr)
{
std::stringstream ss;
ss << this->processWhere(expr.l) << " ";
std::vector<std::string> getTableNames(Cs&& ...columns) const noexcept;
template<typename Table>
std::string getTableName(Table&& table) const noexcept;
- template<typename... Cs>
+ template<typename... Cs>
std::vector<std::string> getColumnNames(Cs&& ...columns) const noexcept;
template<typename Column>
std::string getColumnName(Column&& column) const noexcept;
{
std::set<std::string> names;
- auto predicate = [this, &names](const auto& column) {
+ auto predicate = [this, &names](const auto & column) {
using ColumnType = std::remove_reference_t<decltype(column)>;
using TableType = typename ColumnType::Table;
auto name = this->getTableName(TableType());
if (!name.empty())
- names.emplace(name);
+ names.emplace(name);
};
- auto closure = [&predicate](const auto&... iter) {
+ auto closure = [&predicate](const auto & ... iter) {
(predicate(iter), ...);
};
std::vector<std::string> Database<Tables...>::getColumnNames(Cs&& ...columns) const noexcept
{
std::vector<std::string> names;
- auto predicate = [this, &names](const auto& column) {
+ auto predicate = [this, &names](const auto & column) {
auto name = this->getColumnName(column);
if (!name.empty())
names.emplace_back(name);
};
- auto closure = [&predicate](const auto&... iter) {
+ auto closure = [&predicate](const auto & ... iter) {
(predicate(iter), ...);
};
std::string Database<Tables...>::getTableName(Table&& table) const noexcept
{
std::string name;
- auto predicate = [&name, &table](const auto& type) {
+ auto predicate = [&name, &table](const auto & type) {
if (type.compare(table))
name = type.name;
};
- auto closure = [&predicate](const auto&... iter) {
+ auto closure = [&predicate](const auto & ... iter) {
(predicate(iter), ...);
};
TableType table;
std::string name;
- auto predicate = [&name, &table, &column](const auto& iter) {
+ auto predicate = [&name, &table, &column](const auto & iter) {
if (iter.compare(table)) {
auto cname = iter.getColumnName(column);
name = iter.name + "." + cname;
}
};
- auto closure = [&predicate](const auto&... iter) {
+ auto closure = [&predicate](const auto & ... iter) {
(predicate(iter), ...);
};
}
};
-template<typename L,
- typename R,
- typename = typename std::enable_if_t<is_expression<L>::value &&
- is_expression<R>::value>>
+template < typename L,
+ typename R,
+ typename = typename std::enable_if_t < is_expression<L>::value &&
+ is_expression<R>::value >>
And<L, R> operator&&(const L& l, const R& r)
{
return {l, r};
}
-template<typename L,
- typename R,
- typename = typename std::enable_if_t<is_expression<L>::value &&
- is_expression<R>::value>>
+template < typename L,
+ typename R,
+ typename = typename std::enable_if_t < is_expression<L>::value &&
+ is_expression<R>::value >>
Or<L, R> operator||(const L& l, const R& r)
{
return {l, r};
#pragma once
-#include "column.hpp"
-#include "database.hpp"
-#include "table.hpp"
+#include "column.hpp"
+#include "database.hpp"
+#include "table.hpp"
#define DECLARE_COLUMN(instance, name, type) \
inline static vist::tsqb::Column instance = { name, type }
std::vector<std::string> Table<Columns...>::getColumnNames(Cs&& ...columns) const noexcept
{
std::vector<std::string> names;
- auto predicate = [this, &names](const auto& type) {
+ auto predicate = [this, &names](const auto & type) {
auto name = this->getColumnName(type);
if (!name.empty())
names.emplace_back(name);
};
- auto closure = [&predicate](const auto&... iter) {
+ auto closure = [&predicate](const auto & ... iter) {
(predicate(iter), ...);
};
std::vector<std::string> Table<Columns...>::getColumnNames(void) const noexcept
{
std::vector<std::string> names;
- auto closure = [&names](const auto&... iter) {
+ auto closure = [&names](const auto & ... iter) {
(names.push_back(iter.name), ...);
};
std::string Table<Columns...>::getColumnName(Column&& column) const noexcept
{
std::string name;
- auto predicate = [&name, &column](const auto& iter) {
- if (type::cast_compare(column.type, iter.type))
+ auto predicate = [&name, &column](const auto & iter) {
+ if (type::cast_compare(column.type, iter.type))
name = iter.name;
};
- auto closure = [&predicate](const auto&... iter) {
+ auto closure = [&predicate](const auto & ... iter) {
(predicate(iter), ...);
};
};
DECLARE_TABLE(AdminTable, "admin", Admin::Id, Admin::Pkg,
- Admin::Uid, Admin::Key, Admin::Removable);
+ Admin::Uid, Admin::Key, Admin::Removable);
DECLARE_TABLE(ManagedPolicyTable, "managed_policy", ManagedPolicy::Id,
- ManagedPolicy::Aid,
- ManagedPolicy::Pid,
- ManagedPolicy::Value);
+ ManagedPolicy::Aid,
+ ManagedPolicy::Pid,
+ ManagedPolicy::Value);
DECLARE_TABLE(PolicyDefinitionTable, "policy_definition", PolicyDefinition::Id,
- PolicyDefinition::Scope,
- PolicyDefinition::Name,
- PolicyDefinition::Ivalue);
+ PolicyDefinition::Scope,
+ PolicyDefinition::Name,
+ PolicyDefinition::Ivalue);
DECLARE_DATABASE(DPM, "dpm", AdminTable, ManagedPolicyTable, PolicyDefinitionTable);
TEST(QueryBuilderTsqbTests, SELECT_WHERE)
{
std::string select1 = AdminTable.select(Admin::Uid, Admin::Key)
- .where(Admin::Id > 3);
+ .where(Admin::Id > 3);
std::string select2 = AdminTable.selectAll().where(Admin::Uid > 3);
std::string select3 = AdminTable.selectAll().where(Admin::Uid > 3 && Admin::Pkg == "dpm");
std::string select4 = AdminTable.selectAll().where(Admin::Uid > 3 || Admin::Pkg == "dpm");
std::string update1 = AdminTable.update(Admin::Id = id, Admin::Pkg = "pkg",
Admin::Uid = uid, Admin::Key = "key");
std::string update2 = AdminTable.update(Admin::Key = "key")
- .where((Admin::Uid == uid) && (Admin::Id == id));
+ .where((Admin::Uid == uid) && (Admin::Id == id));
std::string update3 = AdminTable.update(Admin::Key = "key", Admin::Pkg = "pkg")
- .where((Admin::Uid == 0) && (Admin::Id == 1));
+ .where((Admin::Uid == 0) && (Admin::Id == 1));
EXPECT_EQ(update1, "UPDATE admin SET id = 1, pkg = 'pkg', uid = 0, key = 'key'");
EXPECT_EQ(update2, "UPDATE admin SET key = 'key' WHERE uid = 0 AND id = 1");
Admin::Key = key);
EXPECT_EQ(insert1, "INSERT INTO admin (id, pkg, uid, key) "
- "VALUES (0, 'pkg', 1, 'key')");
+ "VALUES (0, 'pkg', 1, 'key')");
EXPECT_EQ(insert2, "INSERT INTO admin (id, pkg, key) "
- "VALUES (0, 'pkg', 'key')");
+ "VALUES (0, 'pkg', 'key')");
}
TEST(QueryBuilderTsqbTests, TYPE_SAFE)
{
-/*
- * Below cause complie error since expression types are dismatch.
-
- std::string type_unsafe1 = admin.selectAll().where(Admin::Uid > "dpm");
- std::string type_unsafe2 = admin.selectAll().where(Admin::Uid == "dpm");
- std::string type_unsafe3 = admin.selectAll().where(Admin::Pkg == 3);
- int pkg = 3;
- std::string type_unsafe4 = admin.selectAll().where(Admin::Pkg) < pkg);
- std::string type_unsafe5 = admin.remove().where(Admin::Pkg) == "dpm" &&
- Admin::Uid) == "dpm");
-*/
+ /*
+ * Below cause complie error since expression types are dismatch.
+
+ std::string type_unsafe1 = admin.selectAll().where(Admin::Uid > "dpm");
+ std::string type_unsafe2 = admin.selectAll().where(Admin::Uid == "dpm");
+ std::string type_unsafe3 = admin.selectAll().where(Admin::Pkg == 3);
+ int pkg = 3;
+ std::string type_unsafe4 = admin.selectAll().where(Admin::Pkg) < pkg);
+ std::string type_unsafe5 = admin.remove().where(Admin::Pkg) == "dpm" &&
+ Admin::Uid) == "dpm");
+ */
}
TEST(QueryBuilderTsqbTests, MULTI_SELECT)
ManagedPolicy::Id, ManagedPolicy::Value);
std::string multiSelect2 = DPM.select(Admin::Uid, Admin::Key,
ManagedPolicy::Id, ManagedPolicy::Value)
- .where((Admin::Uid > 0) && (ManagedPolicy::Id == 3));
+ .where((Admin::Uid > 0) && (ManagedPolicy::Id == 3));
EXPECT_EQ(multiSelect1, "SELECT admin.uid, admin.key, managed_policy.id, "
- "managed_policy.value FROM admin, managed_policy");
+ "managed_policy.value FROM admin, managed_policy");
EXPECT_EQ(multiSelect2, "SELECT admin.uid, admin.key, managed_policy.id, "
- "managed_policy.value FROM admin, managed_policy "
- "WHERE admin.uid > 0 AND managed_policy.id = 3");
+ "managed_policy.value FROM admin, managed_policy "
+ "WHERE admin.uid > 0 AND managed_policy.id = 3");
}
DECLARE_TABLE(table1, "table1", Table1::Column1, Table1::Column2, Table1::Column3);
DECLARE_TABLE(table2, "table2", Table2::Column1,
- Table2::Column2,
- Table2::Column3,
- Table2::Column4,
- Table2::Column5);
+ Table2::Column2,
+ Table2::Column3,
+ Table2::Column4,
+ Table2::Column5);
DECLARE_DATABASE(database, "database", table1, table2);
inline std::string rtrim(std::string&& s)
{
- auto predicate = [](unsigned char c){ return !std::isspace(c); };
+ auto predicate = [](unsigned char c) {
+ return !std::isspace(c);
+ };
auto base = std::find_if(s.rbegin(), s.rend(), predicate).base();
s.erase(base, s.end());
return s;
Result(ErrCode ec) : ec(std::move(ec)), isError(true) {}
Result() = delete;
- inline bool ok() { return !isError; }
- inline bool err() { return isError; }
+ inline bool ok()
+ {
+ return !isError;
+ }
+ inline bool err()
+ {
+ return isError;
+ }
/// TBD: Consider to return rvalue.
- inline Value& get() { return value; }
- inline ErrCode getErrCode() { return ec; }
+ inline Value& get()
+ {
+ return value;
+ }
+ inline ErrCode getErrCode()
+ {
+ return ec;
+ }
private:
Value value;
public:
explicit Impl(Gateway& gateway, const std::string& path, Gateway::ServiceType type)
{
- auto dispatcher = [&gateway](auto& message) -> Message {
+ auto dispatcher = [&gateway](auto & message) -> Message {
std::string function = message.signature;
auto iter = gateway.functorMap.find(function);
if (iter == gateway.functorMap.end())
this->dispatch(nfds);
}
-void Mainloop::dispatch(int size) {
+void Mainloop::dispatch(int size)
+{
for (int i = 0; i < size; i++) {
auto handler = this->getHandler(this->events[i].data.fd);
auto onEvent = handler.first;
DEBUG(VIST) << "New session is accepted: fd[" << connection->getFd() << "]";
/// process task per thread
- this->worker.submit([this, connection, task]{
- auto onRead = [connection, task]() {
+ this->worker.submit([this, connection, task] {
+ auto onRead = [connection, task]()
+ {
Server::peer.reset(new Credentials(Credentials::Peer(connection->getFd())));
DEBUG(VIST) << "Read event occured: pid[" << Server::peer->pid << "]";
}
};
- auto onClose = [this, connection]() {
+ auto onClose = [this, connection]()
+ {
DEBUG(VIST) << "Connection closed. fd: " << connection->getFd();
this->mainloop.removeHandler(connection->getFd());
};
};
template<typename T>
-void Socket::send(const T *buffer, const std::size_t size) const
+void Socket::send(const T* buffer, const std::size_t size) const
{
std::size_t written = 0;
while (written < size) {
}
template<typename T>
-void Socket::recv(T *buffer, const std::size_t size) const
+void Socket::recv(T* buffer, const std::size_t size) const
{
std::size_t readen = 0;
while (readen < size) {
};
mainloop.addHandler(socket.getFd(), std::move(onAccept));
- auto serverThread = std::thread([&]() { mainloop.run(); });
+ auto serverThread = std::thread([&]() {
+ mainloop.run();
+ });
// client-side
Connection conn(sockPath);
};
mainloop.addHandler(socket.getFd(), std::move(onAccept));
- auto server = std::thread([&]() { mainloop.run(); });
+ auto server = std::thread([&]() {
+ mainloop.run();
+ });
// Send input to server.
Socket connected = Socket::connect(sockPath);
/// Set timeout to stop
mainloop.addHandler(socket.getFd(), std::move(onAccept));
- auto server = std::thread([&]() { mainloop.run(1000); });
+ auto server = std::thread([&]() {
+ mainloop.run(1000);
+ });
auto task = [&]() {
// Send input to server.
{
std::string sockPath = "@vist-test.sock";
- auto task = [&](Message& message) -> Message {
+ auto task = [&](Message & message) -> Message {
EXPECT_EQ(message.signature, requestSignature);
int recv1;
server.run();
});
- { /// Client configuration
+ {
+ /// Client configuration
auto clientClosure = [&]() {
Client client(sockPath);
TEST(ServerClientTests, peer_pid)
{
std::string sockPath = "@vist-test.sock";
- auto task = [](Message& message) -> Message {
+ auto task = [](Message & message) -> Message {
EXPECT_EQ(message.signature, requestSignature);
auto peer = Server::GetPeerCredentials();
server.run();
});
- { /// Client configuration
+ {
+ /// Client configuration
auto clientClosure = [&]() {
Client client(sockPath);
Message::Message(unsigned int type, const std::string& signature) :
header({0, type, signature.size()}),
- signature(signature)
+ signature(signature)
{
this->enclose(signature);
}
Message& operator=(Message&&) = default;
template<typename... Args>
- void enclose(Args&&... args);
+ void enclose(Args&& ... args);
template<typename... Args>
- void disclose(Args&... args);
+ void disclose(Args& ... args);
bool success() const noexcept;
bool error() const noexcept;
};
template<typename... Args>
-void Message::enclose(Args&&... args)
+void Message::enclose(Args&& ... args)
{
this->buffer.pack(std::forward<Args>(args)...);
header.length = this->buffer.size();
}
template<typename... Args>
-void Message::disclose(Args&... args)
+void Message::disclose(Args& ... args)
{
this->buffer.unpack(args...);
}
Remote& operator=(Remote&&) = default;
template<typename R, typename... Args>
- R invoke(const std::string& name, Args&&... args);
+ R invoke(const std::string& name, Args&& ... args);
struct Method {
Remote& remote;
std::string name;
template<typename R, typename... Args>
- R invoke(Args&&... args)
+ R invoke(Args&& ... args)
{
return remote.invoke<R>(name, std::forward<Args>(args)...);
}
};
template<typename R, typename... Args>
-R Remote::invoke(const std::string& method, Args&&... args)
+R Remote::invoke(const std::string& method, Args&& ... args)
{
Message message(Message::Type::MethodCall, method);
message.enclose(std::forward<Args>(args)...);
namespace vist {
namespace schema {
- struct Bluetooth {
- int state;
- int desktopConnectivity;
- int pairing;
- int tethering;
+struct Bluetooth {
+ int state;
+ int desktopConnectivity;
+ int pairing;
+ int tethering;
- DECLARE_COLUMN(State, "state", &Bluetooth::state);
- DECLARE_COLUMN(DesktopConnectivity, "desktopConnectivity", &Bluetooth::desktopConnectivity);
- DECLARE_COLUMN(Pairing, "pairing", &Bluetooth::pairing);
- DECLARE_COLUMN(Tethering, "tethering", &Bluetooth::tethering);
- };
+ DECLARE_COLUMN(State, "state", &Bluetooth::state);
+ DECLARE_COLUMN(DesktopConnectivity, "desktopConnectivity", &Bluetooth::desktopConnectivity);
+ DECLARE_COLUMN(Pairing, "pairing", &Bluetooth::pairing);
+ DECLARE_COLUMN(Tethering, "tethering", &Bluetooth::tethering);
+};
- DECLARE_TABLE(BluetoothTable, "bluetooth", Bluetooth::State,
- Bluetooth::DesktopConnectivity,
- Bluetooth::Pairing,
- Bluetooth::Tethering);
+DECLARE_TABLE(BluetoothTable, "bluetooth", Bluetooth::State,
+ Bluetooth::DesktopConnectivity,
+ Bluetooth::Pairing,
+ Bluetooth::Tethering);
} // namesapce schema
} // namesapce vist
template <typename T>
struct Policy {
- std::string name;
+ std::string name;
T value;
};
virtual void onChanged(const PolicyValue& value) = 0;
- const std::string& getName() const noexcept { return name; }
- PolicyValue& getInitial() noexcept { return initial; }
+ const std::string& getName() const noexcept
+ {
+ return name;
+ }
+ PolicyValue& getInitial() noexcept
+ {
+ return initial;
+ }
protected:
std::string name;
class PolicyProvider {
public:
- using FactoryType = PolicyProvider* (*)();
+ using FactoryType = PolicyProvider * (*)();
explicit PolicyProvider(std::string name) noexcept : name(std::move(name)) {}
virtual ~PolicyProvider() = default;
policies[policy->getName()] = policy;
}
- inline const std::string& getName() const noexcept { return name; }
+ inline const std::string& getName() const noexcept
+ {
+ return name;
+ }
static const std::string& getFactoryName() noexcept
{
static std::string name = "PolicyFactory";
return name;
}
- inline std::size_t size() const noexcept { return policies.size(); }
+ inline std::size_t size() const noexcept
+ {
+ return policies.size();
+ }
private:
std::string name;
#include <exception>
namespace {
- int g_value = -1;
+int g_value = -1;
} // anonymous namespace
using namespace vist;
#include <osquery/sql.h>
namespace {
- const std::string SOCK_ADDR = "/tmp/.vist";
+const std::string SOCK_ADDR = "/tmp/.vist";
} // anonymous namespace
namespace vist {
if (copied.size() < 2 || copied[0] != begin || copied[copied.size() - 1] != end)
throw std::invalid_argument("Wrong format.");
- return copied.substr(1, copied.size() -2);
+ return copied.substr(1, copied.size() - 2);
}
inline std::size_t count(const std::string& str, char ch)
{ "state", "bluetooth" },
{ "desktopConnectivity", "bluetooth-desktop-connectivity" },
{ "pairing", "bluetooth-pairing" },
- { "tethering", "bluetooth-tethering"} };
+ { "tethering", "bluetooth-tethering"}
+};
void setPolicy(const std::string& name, int value)
{
};
}
-TableRows BluetoothTable::generate(QueryContext&) try {
+TableRows BluetoothTable::generate(QueryContext&) try
+{
INFO(VIST) << "Select query about bluetooth table.";
QueryData results;
Row row;
- for (const auto&[schemaName, policyName]: ALIAS) {
+ for (const auto&[schemaName, policyName] : ALIAS) {
int value = vist::policy::API::Get(policyName);
row[schemaName] = std::to_string(value);
}
results.emplace_back(std::move(row));
return osquery::tableRowsFromQueryData(std::move(results));
-} catch (const vist::Exception<ErrCode>& e) {
+} catch (const vist::Exception<ErrCode>& e)
+{
ERROR(VIST) << "Failed to query: " << e.what();
Row r;
return osquery::tableRowsFromQueryData({ r });
-} catch (...) {
+} catch (...)
+{
ERROR(VIST) << "Failed to query with unknown exception.";
Row r;
return osquery::tableRowsFromQueryData({ r });
}
-QueryData BluetoothTable::update(QueryContext&, const PluginRequest& request) try {
+QueryData BluetoothTable::update(QueryContext&, const PluginRequest& request) try
+{
INFO(VIST) << "Update query about bluetooth table.";
if (request.count("json_values") == 0)
throw std::runtime_error("Wrong request format. Not found json value.");
Row r;
r["status"] = "success";
return { r };
-} catch (const vist::Exception<ErrCode>& e) {
+} catch (const vist::Exception<ErrCode>& e)
+{
ERROR(VIST) << "Failed to query: " << e.what();
Row r;
return { r };
-} catch (...) {
+} catch (...)
+{
ERROR(VIST) << "Failed to query with unknown exception.";
Row r;
return { r };
}
return osquery::tableRowsFromQueryData(std::move(results));
-} catch (const vist::Exception<ErrCode>& e) {
+} catch (const vist::Exception<ErrCode>& e)
+{
ERROR(VIST) << "Failed to query: " << e.what();
Row r;
return osquery::tableRowsFromQueryData({ r });
-} catch (...) {
+} catch (...)
+{
ERROR(VIST) << "Failed to query with unknown exception.";
Row r;
return osquery::tableRowsFromQueryData({ r });
Row r;
r["status"] = "success";
return { r };
-} catch (const vist::Exception<ErrCode>& e) {
+} catch (const vist::Exception<ErrCode>& e)
+{
ERROR(VIST) << "Failed to query: " << e.what();
Row r;
return { r };
-} catch (...) {
+} catch (...)
+{
ERROR(VIST) << "Failed to query with unknown exception.";
Row r;
return { r };
Row r;
r["status"] = "success";
return { r };
-} catch (const vist::Exception<ErrCode>& e) {
+} catch (const vist::Exception<ErrCode>& e)
+{
ERROR(VIST) << "Failed to query: " << e.what();
Row r;
return { r };
-} catch (...) {
+} catch (...)
+{
ERROR(VIST) << "Failed to query with unknown exception.";
Row r;
return { r };
Row r;
r["status"] = "success";
return { r };
-} catch (const vist::Exception<ErrCode>& e) {
+} catch (const vist::Exception<ErrCode>& e)
+{
ERROR(VIST) << "Failed to query: " << e.what();
Row r;
return { r };
-} catch (...) {
+} catch (...)
+{
ERROR(VIST) << "Failed to query with unknown exception.";
Row r;
return { r };
}
return osquery::tableRowsFromQueryData(std::move(results));
-} catch (const vist::Exception<ErrCode>& e) {
+} catch (const vist::Exception<ErrCode>& e)
+{
ERROR(VIST) << "Failed to query: " << e.what();
Row r;
return osquery::tableRowsFromQueryData({ r });
-} catch (...) {
+} catch (...)
+{
ERROR(VIST) << "Failed to query with unknown exception.";
Row r;
return osquery::tableRowsFromQueryData({ r });
Row r;
r["status"] = "success";
return { r };
-} catch (const vist::Exception<ErrCode>& e) {
+} catch (const vist::Exception<ErrCode>& e)
+{
ERROR(VIST) << "Failed to query: " << e.what();
Row r;
return { r };
-} catch (...) {
+} catch (...)
+{
ERROR(VIST) << "Failed to query with unknown exception.";
Row r;
return { r };
using Task = std::function<void()>;
/// Execute task() once until predicate() is true.
- static void ExecOnce(Task task, Predicate predicate, unsigned int seconds) {
+ static void ExecOnce(Task task, Predicate predicate, unsigned int seconds)
+ {
auto worker = std::thread([task, predicate, seconds]() {
while (1) {
std::this_thread::sleep_for(std::chrono::seconds(seconds));