From: Ossama Othman Date: Sun, 13 Oct 2013 04:43:42 +0000 (-0700) Subject: [smart_ptr] Rename to ivi::settings::unique_ptr. X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=52a582988c671863569e0bc57ec92801deb6036c;p=profile%2Fivi%2Fsettings-daemon.git [smart_ptr] Rename to ivi::settings::unique_ptr. The name "smart_ptr" in the ivi::settings namespace does not convey the actual semantics. Rename to "unique_ptr" to better reflect its C++11 std::unique_ptr<> style of behavior. Change-Id: I0af30c6e3db88e08e0dcefe77206af1b3d4a255d Signed-off-by: Ossama Othman --- diff --git a/include/settingsd/Makefile.am b/include/settingsd/Makefile.am index 8b5f5e4..0d32b7b 100644 --- a/include/settingsd/Makefile.am +++ b/include/settingsd/Makefile.am @@ -27,5 +27,5 @@ pkginclude_HEADERS = \ response_callback.hpp \ glib_traits.hpp \ json_glib_traits.hpp \ - smart_ptr.hpp \ + unique_ptr.hpp \ dbus_signal_callback.hpp diff --git a/include/settingsd/event_callback.hpp b/include/settingsd/event_callback.hpp index 24b3371..910082a 100644 --- a/include/settingsd/event_callback.hpp +++ b/include/settingsd/event_callback.hpp @@ -84,12 +84,12 @@ namespace ivi * The appropriate "header" information will be prepended to the * event. */ - smart_ptr begin_event(); + unique_ptr begin_event(); /** * End the JSON formatted event to the Settings app request. */ - void end_event(smart_ptr const & builder); + void end_event(unique_ptr const & builder); private: diff --git a/include/settingsd/response_callback.hpp b/include/settingsd/response_callback.hpp index 5646c8f..02936ef 100644 --- a/include/settingsd/response_callback.hpp +++ b/include/settingsd/response_callback.hpp @@ -115,12 +115,12 @@ namespace ivi * * @param[in] result @c "succeeded" or @c "failed" */ - smart_ptr begin_response(char const * result); + unique_ptr begin_response(char const * result); /** * End the JSON formatted response to the Settings app request. */ - void end_response(smart_ptr const & builder); + void end_response(unique_ptr const & builder); private: diff --git a/include/settingsd/send_callback.hpp b/include/settingsd/send_callback.hpp index 2a47ae7..e0af875 100644 --- a/include/settingsd/send_callback.hpp +++ b/include/settingsd/send_callback.hpp @@ -31,7 +31,7 @@ #define IVI_SETTINGS_SEND_CALLBACK_HPP #include -#include +#include #include @@ -72,7 +72,7 @@ namespace ivi * pre-marshalled (in-memory) payload. */ bool send_payload(char const * send_type, - smart_ptr const & builder); + unique_ptr const & builder); /** * Check if the WebSocket instance @a wsi corresponds to this diff --git a/include/settingsd/smart_ptr.hpp b/include/settingsd/unique_ptr.hpp similarity index 76% rename from include/settingsd/smart_ptr.hpp rename to include/settingsd/unique_ptr.hpp index d03aaef..de6d3fd 100644 --- a/include/settingsd/smart_ptr.hpp +++ b/include/settingsd/unique_ptr.hpp @@ -1,7 +1,7 @@ /** - * @file smart_ptr.hpp + * @file unique_ptr.hpp * - * @brief C++11 style smart pointer for use by settings plug-ins. + * @brief C++11 style @c unique_ptr for use by settings plug-ins. * * @author Ossama Othman @ * @@ -24,8 +24,8 @@ * Boston, MA 02110-1301 USA */ -#ifndef IVI_SETTINGS_SMART_PTR_HPP -#define IVI_SETTINGS_SMART_PTR_HPP +#ifndef IVI_SETTINGS_UNIQUE_PTR_HPP +#define IVI_SETTINGS_UNIQUE_PTR_HPP #include @@ -35,22 +35,22 @@ namespace ivi namespace settings { /** - * @typedef smart_ptr + * @typedef unique_ptr * - * @brief C++11 style smart pointer for use by settings plug-ins. + * @brief C++11 style unique pointer for use by settings plug-ins. * - * This type alias exposes a C++11-style smart pointer interface + * This type alias exposes a C++11-style @c unique_ptr interface * to allow RAII based handling of resources provided by third * party libraries, such as Glib. Core functionality is * implemented in traits that this type alias leverages. */ - template using smart_ptr = + template using unique_ptr = ::std::unique_ptr::delete_functor>; } } -#endif /* IVI_SETTINGS_SMART_PTR_HPP */ +#endif /* IVI_SETTINGS_UNIQUE_PTR_HPP */ // Local Variables: diff --git a/lib/event_callback.cpp b/lib/event_callback.cpp index 5ec7189..12cc69c 100644 --- a/lib/event_callback.cpp +++ b/lib/event_callback.cpp @@ -26,7 +26,7 @@ #include #include -#include +#include #include "manager.hpp" @@ -39,7 +39,7 @@ bool ivi::settings::event_callback::send_event( std::function event_builder) { - smart_ptr const builder = begin_event(); + unique_ptr const builder = begin_event(); // Append settings type-specific JSON formatted events. event_builder(builder.get()); @@ -49,11 +49,11 @@ ivi::settings::event_callback::send_event( return manager_.send_event(builder); } -ivi::settings::smart_ptr +ivi::settings::unique_ptr ivi::settings::event_callback::begin_event() { // Construct JSON event string. - smart_ptr safe_builder(json_builder_new()); + unique_ptr safe_builder(json_builder_new()); JsonBuilder * const builder = safe_builder.get(); json_builder_begin_object(builder); @@ -66,7 +66,7 @@ ivi::settings::event_callback::begin_event() void ivi::settings::event_callback::end_event( - ivi::settings::smart_ptr const & builder) + ivi::settings::unique_ptr const & builder) { json_builder_end_object(builder.get()); } diff --git a/lib/manager.cpp b/lib/manager.cpp index 22c431f..5ca8d2b 100644 --- a/lib/manager.cpp +++ b/lib/manager.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include @@ -137,11 +137,11 @@ ivi::settings::manager::dispatch(std::string request, return; } - smart_ptr const parser(json_parser_new()); + unique_ptr const parser(json_parser_new()); json_parser_load_from_data(parser.get(), request.c_str(), -1, nullptr); JsonReader * const reader = json_reader_new(json_parser_get_root(parser.get())); - smart_ptr const safe_reader(reader); + unique_ptr const safe_reader(reader); // Retrieve setting name and transcation ID from the JSON request // string. @@ -210,7 +210,7 @@ ivi::settings::manager::unsubscribe_client(libwebsocket * wsi) bool ivi::settings::manager::send_event( - smart_ptr const & builder) + unique_ptr const & builder) { bool success = true; diff --git a/lib/manager.hpp b/lib/manager.hpp index 373e097..aea12fd 100644 --- a/lib/manager.hpp +++ b/lib/manager.hpp @@ -103,7 +103,7 @@ namespace ivi * * @return @c true on success. */ - bool send_event(smart_ptr const & builder); + bool send_event(unique_ptr const & builder); private: diff --git a/lib/response_callback.cpp b/lib/response_callback.cpp index 4d2ef40..24bf616 100644 --- a/lib/response_callback.cpp +++ b/lib/response_callback.cpp @@ -26,7 +26,7 @@ #include #include -#include +#include ivi::settings::response_callback::response_callback( @@ -52,7 +52,7 @@ bool ivi::settings::response_callback::send_response( std::function response_builder) { - smart_ptr const builder = begin_response("succeeded"); + unique_ptr const builder = begin_response("succeeded"); // Append successful Settings app results to the JSON formatted // response. @@ -75,7 +75,7 @@ ivi::settings::response_callback::send_response( bool ivi::settings::response_callback::send_error(std::string error_message) { - smart_ptr builder = begin_response("failed"); + unique_ptr builder = begin_response("failed"); json_builder_set_member_name(builder.get(), "reason");; json_builder_add_string_value(builder.get(), error_message.c_str()); @@ -107,11 +107,11 @@ ivi::settings::response_callback::add_string_value( json_builder_add_string_value(builder, value.c_str()); } -ivi::settings::smart_ptr +ivi::settings::unique_ptr ivi::settings::response_callback::begin_response(char const * result) { // Construct JSON response. - smart_ptr safe_builder(json_builder_new()); + unique_ptr safe_builder(json_builder_new()); JsonBuilder * const builder = safe_builder.get(); json_builder_begin_object(builder); @@ -127,7 +127,7 @@ ivi::settings::response_callback::begin_response(char const * result) void ivi::settings::response_callback::end_response( - ivi::settings::smart_ptr const & builder) + ivi::settings::unique_ptr const & builder) { json_builder_end_object(builder.get()); } diff --git a/lib/send_callback.cpp b/lib/send_callback.cpp index 50453ad..9330f8e 100644 --- a/lib/send_callback.cpp +++ b/lib/send_callback.cpp @@ -27,7 +27,7 @@ #include #include #include -#include +#include #include #include @@ -56,16 +56,16 @@ ivi::settings::send_callback::operator=(send_callback const & other) bool ivi::settings::send_callback::send_payload( char const * send_type, - smart_ptr const & builder) + unique_ptr const & builder) { - smart_ptr const generator(json_generator_new()); - smart_ptr const root(json_builder_get_root(builder.get())); + unique_ptr const generator(json_generator_new()); + unique_ptr const root(json_builder_get_root(builder.get())); json_generator_set_root(generator.get(), root.get()); gchar * const data = json_generator_to_data(generator.get(), nullptr); - smart_ptr safe_data(data); + unique_ptr safe_data(data); if (data == nullptr) { g_critical("Unable to generate JSON formatted %s payload:\n", diff --git a/plugins/connman/clock.cpp b/plugins/connman/clock.cpp index 3cd8c49..8d739cd 100644 --- a/plugins/connman/clock.cpp +++ b/plugins/connman/clock.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include #include #include @@ -56,13 +56,13 @@ void ivi::settings::clock::handle_request(std::string request, response_callback response) { - smart_ptr const parser(json_parser_new()); + unique_ptr const parser(json_parser_new()); json_parser_load_from_data(parser.get(), request.c_str(), -1, nullptr); JsonReader * const reader = json_reader_new(json_parser_get_root(parser.get())); - smart_ptr safe_reader(reader); + unique_ptr safe_reader(reader); char const * name = nullptr; if (json_reader_read_member(reader, "name")) { @@ -91,7 +91,7 @@ ivi::settings::clock::handle_request(std::string request, "Unrecognized " + id() + " request name: " + name); } - smart_ptr safe_error(error); + unique_ptr safe_error(error); if (success) { @@ -196,7 +196,7 @@ ivi::settings::clock::set_updates(char const * name, ? "" : updates)); } else { - smart_ptr const current_value(get_property(name, error)); + unique_ptr const current_value(get_property(name, error)); if (current_value != nullptr) { char const * value = @@ -235,7 +235,7 @@ ivi::settings::clock::is_updates_auto(char const * name, return; } - smart_ptr const current_value(get_property(name, error)); + unique_ptr const current_value(get_property(name, error)); if (current_value != nullptr) { char const * value = @@ -258,7 +258,7 @@ ivi::settings::clock::set_property(char const * name, response_callback /* response */, GError *& error) { - smart_ptr const ret( + unique_ptr const ret( connman_.set_property(name, value, error)); return ret.get() != nullptr; @@ -270,7 +270,7 @@ ivi::settings::clock::get_property(char const * property, { constexpr gint const timeout = 5000; // milliseconds - smart_ptr const dictionary( + unique_ptr const dictionary( g_dbus_proxy_call_sync(connman_.proxy(), "GetProperties", nullptr, // No parameters @@ -279,18 +279,18 @@ ivi::settings::clock::get_property(char const * property, nullptr, // Not cancellable &error)); - smart_ptr value; + unique_ptr value; if (dictionary != nullptr) { GVariantIter * i = nullptr; g_variant_get(dictionary.get(), "(a{sv})", &i); - smart_ptr const iter(i); + unique_ptr const iter(i); gchar * pname = nullptr; GVariant * pvalue = nullptr; while (g_variant_iter_next(i, "{sv}", &pname, &pvalue)) { - smart_ptr const name(pname); + unique_ptr const name(pname); value.reset(pvalue); // Check if this is the property we want. diff --git a/plugins/connman/connman.cpp b/plugins/connman/connman.cpp index 2367310..d0a827e 100644 --- a/plugins/connman/connman.cpp +++ b/plugins/connman/connman.cpp @@ -27,7 +27,7 @@ #include "connman.hpp" #include -#include +#include #include #include @@ -56,7 +56,7 @@ ivi::settings::connman::connman(char const * interface, nullptr, // GCancellable &error); - smart_ptr safe_error(error); + unique_ptr safe_error(error); if (proxy_ == nullptr) { g_printerr("Unable to create D-Bus proxy for (\"%s\", \"%s\"): %s\n", diff --git a/plugins/connman/connman_manager.cpp b/plugins/connman/connman_manager.cpp index a6449d7..cda4ee7 100644 --- a/plugins/connman/connman_manager.cpp +++ b/plugins/connman/connman_manager.cpp @@ -28,7 +28,7 @@ #include #include -#include +#include #include @@ -76,7 +76,7 @@ ivi::settings::connman_manager::get_properties( { constexpr gint const timeout = 5000; // milliseconds - smart_ptr const dictionary( + unique_ptr const dictionary( g_dbus_proxy_call_sync(connman_.proxy(), "GetTechnologies", nullptr, // No parameters @@ -88,14 +88,14 @@ ivi::settings::connman_manager::get_properties( if (dictionary != nullptr) { GVariantIter * i = nullptr; g_variant_get(dictionary.get(), "(a(oa{sv}))", &i); - smart_ptr const safe_i(i); + unique_ptr const safe_i(i); - for (smart_ptr child(g_variant_iter_next_value(i)); + for (unique_ptr child(g_variant_iter_next_value(i)); child != nullptr; child.reset(g_variant_iter_next_value(i))) { // The object path is the first tuple element. - smart_ptr const tmp( + unique_ptr const tmp( g_variant_get_child_value(child.get(), 0)); char const * object = diff --git a/plugins/connman/service.cpp b/plugins/connman/service.cpp index 968dd2d..1f7bf82 100644 --- a/plugins/connman/service.cpp +++ b/plugins/connman/service.cpp @@ -27,7 +27,7 @@ #include "service.hpp" #include -#include +#include #include #include @@ -60,7 +60,7 @@ ivi::settings::service::call_method(char const * name, constexpr gint const timeout = 10000; // milliseconds GError * error = nullptr; - smart_ptr const ret( + unique_ptr const ret( g_dbus_proxy_call_sync(connman_.proxy(), name, // "Connect", "Disconect", ... nullptr, // No parameters @@ -69,7 +69,7 @@ ivi::settings::service::call_method(char const * name, nullptr, // Not cancellable &error)); - smart_ptr safe_error; + unique_ptr safe_error; if (ret != nullptr) { // Nothing to add to successful response. diff --git a/plugins/connman/technology.cpp b/plugins/connman/technology.cpp index 325b165..92a25c0 100644 --- a/plugins/connman/technology.cpp +++ b/plugins/connman/technology.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include @@ -54,10 +54,10 @@ void ivi::settings::technology::handle_request(std::string request, response_callback response) { - smart_ptr const parser(json_parser_new()); + unique_ptr const parser(json_parser_new()); json_parser_load_from_data(parser.get(), request.c_str(), -1, nullptr); - smart_ptr const safe_reader( + unique_ptr const safe_reader( json_reader_new(json_parser_get_root(parser.get()))); JsonReader * const reader = safe_reader.get(); @@ -108,7 +108,7 @@ ivi::settings::technology::get_powered(JsonReader * reader, return; } - smart_ptr const property( + unique_ptr const property( get_property("Powered", G_VARIANT_TYPE_BOOLEAN, response)); if (property != nullptr) { @@ -140,12 +140,12 @@ ivi::settings::technology::set_powered(JsonReader * reader, GError * error = nullptr; - smart_ptr ret( + unique_ptr ret( connman_.set_property(name, g_variant_new_boolean(enable), error)); - smart_ptr safe_error(error); + unique_ptr safe_error(error); if (ret != nullptr) { // Nothing to add to successful response. @@ -180,7 +180,7 @@ ivi::settings::technology::scan(JsonReader * reader, constexpr gint const timeout = 10000; // milliseconds GError * error = nullptr; - smart_ptr const ret( + unique_ptr const ret( g_dbus_proxy_call_sync(connman_.proxy(), "Scan", nullptr, // No parameters @@ -189,7 +189,7 @@ ivi::settings::technology::scan(JsonReader * reader, nullptr, // Not cancellable &error)); - smart_ptr safe_error(error); + unique_ptr safe_error(error); if (ret != nullptr) { send_services(response, error); @@ -246,7 +246,7 @@ void ivi::settings::technology::send_services(response_callback response, GError *& error) { - smart_ptr const services(manager_.get_services(error)); + unique_ptr const services(manager_.get_services(error)); if (services != nullptr) { response.send_response( @@ -274,12 +274,12 @@ ivi::settings::technology::get_property(char const * name, { GError * error = nullptr; - smart_ptr const properties( + unique_ptr const properties( manager_.get_properties(technology_, error)); - smart_ptr safe_error(error); + unique_ptr safe_error(error); - smart_ptr property; + unique_ptr property; if (properties != nullptr) { property.reset( g_variant_lookup_value(properties.get(), name, type)); diff --git a/src/daemon.cpp b/src/daemon.cpp index 18cf872..071d596 100644 --- a/src/daemon.cpp +++ b/src/daemon.cpp @@ -29,7 +29,7 @@ #include "websocket_server.hpp" #include -#include +#include #include #include @@ -59,7 +59,7 @@ main(int argc, char * argv[]) // Glib related events, including GDbus related signal handlers, // will handled in this (main) thread. - settings::smart_ptr const loop(g_main_loop_new(nullptr, false)); + settings::unique_ptr const loop(g_main_loop_new(nullptr, false)); g_main_loop_run(loop.get()); } catch (std::exception & e) {