TIVI-1924: Initial commit of IVI settings daemon.
[profile/ivi/settings-daemon.git] / tests / test_setting.cpp
1 /**
2  * @file test_setting.cpp
3  *
4  * @brief Settings daemon test plugin.
5  *
6  * @author Ossama Othman @<ossama.othman@@intel.com@>
7  *
8  * @copyright @par
9  * Copyright 2013 Intel Corporation All Rights Reserved.
10  * @par
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public
13  * License as published by the Free Software Foundation;
14  * version 2.1 of the License.
15  * @par
16  * This library is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
19  * Lesser General Public License for more details.
20  * @par
21  * You should have received a copy of the GNU Lesser General Public
22  * License along with this library; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor,
24  * Boston, MA  02110-1301  USA
25  */
26
27 #include "test_setting_api.hpp"
28 #include "test_setting.hpp"
29 #include <settingsd/response_callback.hpp>
30 #include <settingsd/registrar.hpp>
31
32 #include <memory>
33 #include <iostream>
34
35
36 test_setting::test_setting()
37 {
38 }
39
40 test_setting::~test_setting()
41 {
42 }
43
44 std::string const &
45 test_setting::id() const
46 {
47   static std::string const name("test_setting");
48   return name;
49 }
50
51 void
52 test_setting::handle_request(std::string request,
53                              ivi::settings::response_callback response)
54 {
55   std::cout << "test_setting received request:\n"
56             << request << std::endl;
57
58   if (response.type() != id()) {
59     response.send_error("Response type mismatch.  Got \""
60                         + response.type()
61                         + "\". Expected \""
62                         + id()
63                         + "\".");
64     return;
65   }
66
67   // Nothing to add to successful response.
68   response.send_response(
69     [](JsonBuilder * /* builder */) {});
70 }
71
72 // -----------------------------------------------------------------------
73
74 /// Plugin factory/registration function.
75 extern "C" TEST_SETTING_API bool
76 register_settings(ivi::settings::registrar & r)
77 {
78   std::unique_ptr<ivi::settings::plugin> test(new test_setting);
79
80   return r.register_setting(std::move(test));
81 }
82
83
84
85 // Local Variables:
86 // mode:c++
87 // c-basic-offset:2
88 // indent-tabs-mode: nil
89 // End: