2 * Copyright (c) 2011 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.
16 #ifndef WRTDEVICEAPIS_VCONFKEY_H_
17 #define WRTDEVICEAPIS_VCONFKEY_H_
21 #include <dpl/noncopyable.h>
22 #include <dpl/mutex.h>
25 namespace WrtDeviceApis {
27 typedef void (*KeyChangeCallback)(const Node*, void*);
29 class Key : private DPL::Noncopyable
33 * Creates vconf key wrapper.
34 * @param name Key name or NULL (default).
36 explicit Key(const char* name = NULL);
42 * @return Value of the key.
43 * @throw ConversionException If unable to get value.
48 * Sets boolean value for this key.
49 * @param value Value to set.
50 * @throw PlatformException If unable to perform the request.
52 void setValue(bool value);
56 * @return Value of the key.
57 * @throw ConversionException If unable to get value.
62 * Sets integer value for this key.
63 * @param value Value to set.
64 * @throw PlatformException If unable to perform the request.
66 void setValue(int value);
70 * @return Value of the key.
71 * @throw ConversionException If unable to get value.
73 double getDouble() const;
76 * Sets double value for this key.
77 * @param value Value to set.
78 * @throw PlatformException If unable to perform the request.
80 void setValue(double value);
84 * @return Value of the key.
85 * @throw ConversionException If unable to get value.
87 std::string getString() const;
90 * Sets string value for this key.
91 * @param value Value to set.
92 * @throw PlatformException If unable to perform the request.
94 void setValue(const std::string& value);
97 * Sets c-string value for this key.
98 * @param value Value to set.
99 * @throw PlatformException If unable to perform the request.
101 void setValue(const char* value);
104 * Attaches on key value change callback.
105 * @param callback Callback function.
106 * @param data User data.
107 * @return True if callback has been successfully attached, false otherwsie.
108 * @remarks Does NOT take ownership over user data.
109 * @remarks Creating two independent keys then attaching the same callback to
110 * each and detaching it from one of them causes disconnection of
111 * this callback from vconf engine.
113 bool attachCallback(KeyChangeCallback callback,
117 * Detaches on key value change callback.
119 void detachCallback();
122 * Resets this object to wrap other key around.
123 * @param name Key name or NULL (default).
125 void reset(const char* name = NULL);
129 * Callback set to platform.
131 * @param data User data.
133 static void callback(keynode_t* node,
137 std::string m_name; ///< Key name.
138 KeyChangeCallback m_callback; ///< Callback.
139 void* m_callbackData; ///< Callback user data.
140 DPL::Mutex m_mtx; ///< Synchronize access to callback.
144 #endif /* WRTDEVICEAPIS_VCONFKEY_H_ */