implementation_update("tizen/policy@updatePolicy")
examples([
"select * from policy where name = 'bluetooth'",
- "update policy set value = 1 where name = 'bluetooth'",
+ "update policy set value = 'I/1' where name = 'bluetooth'",
])
auto names = context.constraints["name"].getAll(EQUALS);
for (const auto& name : names) {
auto ret = vist::policy::API::Get(name);
- int value = ret;
Row r;
r["name"] = TEXT(name);
- r["value"] = TEXT(value);
+ r["value"] = TEXT(ret.dump());
results.emplace_back(std::move(r));
}
} else { /// select *;
auto policies = vist::policy::API::GetAll();
for (auto& policy : policies) {
- int value = policy.second;
-
Row r;
+ INFO(VIST) << "***";
r["name"] = TEXT(policy.first);
- r["value"] = TEXT(value);
+ r["value"] = TEXT(policy.second.dump());
results.emplace_back(std::move(r));
}
throw std::runtime_error("Wrong request format.");
std::string name = document[0].GetString();
- int value = std::stoi(document[1].GetString());
+ std::string dumpedValue = document[1].GetString();
- vist::policy::API::Admin::Set(name, vist::policy::PolicyValue(value));
+ vist::policy::API::Admin::Set(name, vist::policy::PolicyValue(dumpedValue, true));
Row r;
r["status"] = "success";
namespace vist {
namespace schema {
+template <typename T>
struct Policy {
std::string name;
- std::string value;
+ T value;
};
} // namesapce schema
}
TEST(VirtualTableTests, policy_table) {
- VirtualTable<Policy> table;
+ VirtualTable<Policy<int>> table;
EXPECT_TRUE(table.size() > 0);
for(const auto& row : table) {
- Policy policy = { row[&Policy::name], row[&Policy::value] };
+ Policy<int> policy = { row[&Policy<int>::name], row[&Policy<int>::value] };
INFO(VIST_CLIENT) << "[Test] Policy table:";
INFO(VIST_CLIENT) << "\t name: " << policy.name;
#include <vist/client/schema/time.hpp>
#include <vist/exception.hpp>
+#include <vist/stringfy.hpp>
#include <vist/logger.hpp>
#include <vist/query-builder.hpp>
make_column("parent", &Processes::parent));
auto policy = make_table("policy",
- make_column("name", &Policy::name),
- make_column("value", &Policy::value));
+ make_column("name", &Policy<int>::name),
+ make_column("value", &Policy<int>::value));
auto metaDB = make_database("db", time, processes, policy);
return Member();
}
+ if (std::is_same<T, Policy<int>>::value && key == "value")
+ return static_cast<Member>(Stringfy::Restore(value));
+
try {
return boost::lexical_cast<Member>(value);
} catch (...) {
}
template <typename T>
-template<typename Struct, typename Member>
+template <typename Struct, typename Member>
Member VirtualRow<T>::operator[](Member Struct::*field) const
{
return this->at(field);
template std::string VirtualRow<Processes>::at(std::string Processes::*) const;
template std::string VirtualRow<Processes>::operator[](std::string Processes::*) const;
-template class VirtualTable<Policy>;
-template class VirtualRow<Policy>;
-template std::string VirtualRow<Policy>::at(std::string Policy::*) const;
-template std::string VirtualRow<Policy>::operator[](std::string Policy::*) const;
+template class VirtualTable<Policy<int>>;
+template class VirtualRow<Policy<int>>;
+/// name column
+template std::string VirtualRow<Policy<int>>::at(std::string Policy<int>::*) const;
+template std::string VirtualRow<Policy<int>>::operator[](std::string Policy<int>::*) const;
+/// value<T> column
+template int VirtualRow<Policy<int>>::at(int Policy<int>::*) const;
+template int VirtualRow<Policy<int>>::operator[](int Policy<int>::*) const;
} // namespace vist
std::string statement = "SELECT * FROM policy WHERE name = 'bluetooth'";
auto rows = Vist::Query(statement);
/// Initial policy value
- EXPECT_EQ(rows[0]["value"], std::to_string(1));
+ EXPECT_EQ(rows[0]["value"], "I/1");
- statement = "UPDATE policy SET value = '3' WHERE name = 'bluetooth'";
+ statement = "UPDATE policy SET value = 'I/3' WHERE name = 'bluetooth'";
rows = Vist::Query(statement);
EXPECT_EQ(rows.size(), 0);
statement = "SELECT * FROM policy WHERE name = 'bluetooth'";
rows = Vist::Query(statement);
- EXPECT_EQ(rows[0]["value"], std::to_string(3));
+ EXPECT_EQ(rows[0]["value"], "I/3");
policy::API::Admin::Disenroll("admin");
}