2 * Copyright (c) 2020-present Samsung Electronics Co., Ltd All Rights Reserved
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License
20 #include <vist/exception.hpp>
21 #include <vist/logger.hpp>
22 #include <vist/policy/api.hpp>
23 #include <vist/table/builder.hpp>
24 #include <vist/table/parser.hpp>
25 #include <vist/table/util.hpp>
27 extern "C" vist::table::DynamicTable* DynamicTableFactory()
29 return new vist::table::BluetoothTable;
37 void setPolicy(const std::string& name, int value)
39 vist::policy::API::Admin::Set(name, vist::policy::PolicyValue(value));
42 std::string getPolicy(const std::string& name)
44 int value = vist::policy::API::Get(name);
45 return std::to_string(value);
48 } // anonymous namespace
50 void BluetoothTable::init()
52 Builder::table<BluetoothTable>("bluetooth");
54 using namespace vist::policy;
55 auto provider = std::make_shared<BluetoothProvider>("bluetooth");
56 provider->add(std::make_shared<BluetoothProvider::State>());
57 provider->add(std::make_shared<BluetoothProvider::DesktopConnectivity>());
58 provider->add(std::make_shared<BluetoothProvider::Pairing>());
59 provider->add(std::make_shared<BluetoothProvider::Tethering>());
61 policy::API::Admin::AddProvider(provider);
63 INFO(VIST_PLUGIN) << "Bluetooth plugin loaded.";
66 TableColumns BluetoothTable::columns() const
68 // Define Virtual table's schema (column)
69 using namespace schema;
71 Builder::column<int>(Bluetooth::State.name),
72 Builder::column<int>(Bluetooth::DesktopConnectivity.name),
73 Builder::column<int>(Bluetooth::Pairing.name),
74 Builder::column<int>(Bluetooth::Tethering.name)
78 QueryData BluetoothTable::select(QueryContext&)
80 TABLE_EXCEPTION_GUARD_START
82 INFO(VIST) << "Select query about bluetooth table.";
84 using namespace schema;
85 using namespace policy;
86 // Policy name format: bluetooth-xxx
87 // Virtual table column name formant: xxx
89 row[Bluetooth::State.name] = getPolicy(GetPolicyName(Bluetooth::State));
90 row[Bluetooth::DesktopConnectivity.name] =
91 getPolicy(GetPolicyName(Bluetooth::DesktopConnectivity));
92 row[Bluetooth::Pairing.name] = getPolicy(GetPolicyName(Bluetooth::Pairing));
93 row[Bluetooth::Tethering.name] = getPolicy(GetPolicyName(Bluetooth::Tethering));
96 results.emplace_back(std::move(row));
100 TABLE_EXCEPTION_GUARD_END
103 QueryData BluetoothTable::update(QueryContext&, const PluginRequest& request)
105 TABLE_EXCEPTION_GUARD_START
107 INFO(VIST) << "Update query about bluetooth table.";
109 using namespace schema;
110 using namespace policy;
111 setPolicy(GetPolicyName(Bluetooth::State), Parser::column<int>(request, 0));
112 setPolicy(GetPolicyName(Bluetooth::DesktopConnectivity), Parser::column<int>(request, 1));
113 setPolicy(GetPolicyName(Bluetooth::Pairing), Parser::column<int>(request, 2));
114 setPolicy(GetPolicyName(Bluetooth::Tethering), Parser::column<int>(request, 3));
118 TABLE_EXCEPTION_GUARD_END