From 1977d5bf7a092aabe45afc24c9b3c9724f48e792 Mon Sep 17 00:00:00 2001 From: Junghoon Park Date: Fri, 20 Apr 2018 10:07:24 +0900 Subject: [PATCH] Comply with google coding rule - Except for some header files regarding c API Change-Id: I6acc664c093de3d257dad34c78a30f1dccc977ef Signed-off-by: Junghoon Park --- doc/rpc-port_doc.h | 6 +++--- src/ac-internal.cc | 22 ++++++++++++++-------- src/ac-internal.h | 9 +++++---- src/fdbroker-internal.cc | 22 +++++++++++++--------- src/fdbroker-internal.h | 7 ++++--- src/parcel-internal.cc | 2 +- src/parcel-internal.h | 2 +- src/proxy-internal.cc | 8 ++++---- src/proxy-internal.h | 4 ++-- src/rpc-port-parcel.cc | 1 - src/rpc-port.cc | 15 ++++++++------- src/stub-internal.cc | 15 ++++++++------- src/stub-internal.h | 4 ++-- tools/check-coding-style | 28 ++++++++++++++++++++++++++++ unit_tests/src/main.cc | 2 +- unit_tests/src/rpc_port_parcel_test.cc | 5 ++--- unit_tests/src/rpc_port_test.cc | 2 -- 17 files changed, 96 insertions(+), 58 deletions(-) create mode 100755 tools/check-coding-style diff --git a/doc/rpc-port_doc.h b/doc/rpc-port_doc.h index a035269..aeb4e5f 100644 --- a/doc/rpc-port_doc.h +++ b/doc/rpc-port_doc.h @@ -14,8 +14,8 @@ * limitations under the License. */ -#ifndef __RPC_PORT_DOC_H__ -#define __RPC_PORT_DOC_H__ +#ifndef DOC_RPC_PORT_DOC_H_ +#define DOC_RPC_PORT_DOC_H_ /** @@ -42,4 +42,4 @@ */ -#endif /* __RPC_PORT_DOC_H__ */ +#endif // DOC_RPC_PORT_DOC_H_ diff --git a/src/ac-internal.cc b/src/ac-internal.cc index 97f47af..f2e728b 100644 --- a/src/ac-internal.cc +++ b/src/ac-internal.cc @@ -45,7 +45,7 @@ void AccessController::SetTrusted(const bool trusted) { trusted_ = trusted; } -int AccessController::CheckPrivilege(Cynara& c) { +int AccessController::CheckPrivilege(const Cynara& c) { for (auto& privilege : privileges_) { if (c.Check(privilege) != 0) { return -1; @@ -66,13 +66,15 @@ int AccessController::CheckTrusted(const char* sender_appid) { LOGD("CheckCertificate : %s :: %s", appid_.c_str(), sender_appid); pkgmgrinfo_cert_compare_result_type_e res; - int ret = pkgmgrinfo_pkginfo_compare_usr_app_cert_info(appid_.c_str(), sender_appid, getuid(), &res); + int ret = pkgmgrinfo_pkginfo_compare_usr_app_cert_info(appid_.c_str(), + sender_appid, getuid(), &res); if (ret < 0) { LOGE("CheckCertificate() Failed"); return -1; } if (res != PMINFO_CERT_COMPARE_MATCH) { - LOGE("CheckCertificate() Failed : MESSAGE_PORT_ERROR_CERTIFICATE_NOT_MATCH"); + LOGE("CheckCertificate() Failed : " \ + "MESSAGE_PORT_ERROR_CERTIFICATE_NOT_MATCH"); return -1; } @@ -123,7 +125,8 @@ AccessController::Cynara::~Cynara() { cynara_finish(cynara_); } -int AccessController::Cynara::FetchCredsFromDBus(GDBusConnection* connection, const char* sender) { +int AccessController::Cynara::FetchCredsFromDBus(GDBusConnection* connection, + const char* sender) { int ret; if (client_) { @@ -136,13 +139,15 @@ int AccessController::Cynara::FetchCredsFromDBus(GDBusConnection* connection, co user_ = nullptr; } - ret = cynara_creds_gdbus_get_user(connection, sender, USER_METHOD_DEFAULT, &user_); + ret = cynara_creds_gdbus_get_user(connection, sender, USER_METHOD_DEFAULT, + &user_); if (ret != CYNARA_API_SUCCESS) { LOGE("cynara_creds_gdbus_get_user() is failed : %d", ret); return -1; } - ret = cynara_creds_gdbus_get_client(connection, sender, CLIENT_METHOD_DEFAULT, &client_); + ret = cynara_creds_gdbus_get_client(connection, sender, CLIENT_METHOD_DEFAULT, + &client_); if (ret != CYNARA_API_SUCCESS) { LOGE("cynara_creds_gdbus_get_client() is failed : %d", ret); return -1; @@ -152,9 +157,10 @@ int AccessController::Cynara::FetchCredsFromDBus(GDBusConnection* connection, co return 0; } -int AccessController::Cynara::Check(const std::string& privilege) { +int AccessController::Cynara::Check(const std::string& privilege) const { LOGD("check privilege %s", privilege.c_str()); - if (cynara_check(cynara_, client_, "", user_, privilege.c_str()) != CYNARA_API_ACCESS_ALLOWED) { + if (cynara_check(cynara_, client_, "", user_, privilege.c_str()) != + CYNARA_API_ACCESS_ALLOWED) { LOGD("cynara_check() is not allowed : %s", privilege.c_str()); return -1; } diff --git a/src/ac-internal.h b/src/ac-internal.h index 9a9ae63..d11d33b 100644 --- a/src/ac-internal.h +++ b/src/ac-internal.h @@ -31,12 +31,13 @@ namespace internal { class AccessController { public: - AccessController(bool trusted = false) : trusted_(trusted) {} + explicit AccessController(bool trusted = false) : trusted_(trusted) {} virtual ~AccessController(); void AddPrivilege(const std::string& privilege); void SetTrusted(const bool trusted); - int Check(GDBusConnection *connection, const char *sender, const char* sender_appid); + int Check(GDBusConnection *connection, const char *sender, + const char* sender_appid); private: class Cynara { @@ -45,7 +46,7 @@ class AccessController { ~Cynara(); int FetchCredsFromDBus(GDBusConnection *connection, const char *sender); - int Check(const std::string& privilege); + int Check(const std::string& privilege) const; private: cynara *cynara_; @@ -55,7 +56,7 @@ class AccessController { int SetCache(const std::string& sender); int CheckTrusted(const char *sender_appid); - int CheckPrivilege(Cynara& c); + int CheckPrivilege(const Cynara& c); private: std::vector privileges_; diff --git a/src/fdbroker-internal.cc b/src/fdbroker-internal.cc index edbd33f..f8de05b 100644 --- a/src/fdbroker-internal.cc +++ b/src/fdbroker-internal.cc @@ -261,9 +261,9 @@ int FdBroker::Send(const std::string& target_appid, } g_dbus_message_set_unix_fd_list(msg, fd_list.GetRaw()); - reply = g_dbus_connection_send_message_with_reply_sync(DBusConnectionManager::GetInst().GetConnection(), - msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, 500, - nullptr, nullptr, &err); + reply = g_dbus_connection_send_message_with_reply_sync( + DBusConnectionManager::GetInst().GetConnection(), + msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, 500, nullptr, nullptr, &err); if (reply == nullptr) { LOGE("No reply. error = %s", err->message); g_error_free(err); @@ -284,7 +284,7 @@ int FdBroker::Send(const std::string& target_appid, LOGE("Access Denied[sender_appid : %s]", sender_appid); g_object_unref(msg); g_object_unref(reply); - return -1; + return -1; } LOGD("[Reply : %d]", ret); @@ -329,8 +329,10 @@ void FdBroker::OnReceiveDbusMethod(GDBusConnection *conn, int sender_pid; sender_pid = broker->GetSenderPid(conn, sender); - if (aul_app_get_appid_bypid(sender_pid, sender_appid, sizeof(sender_appid)) < 0) { - g_dbus_method_invocation_return_value(invocation, g_variant_new("(i)", ret)); + if (aul_app_get_appid_bypid(sender_pid, sender_appid, + sizeof(sender_appid)) < 0) { + g_dbus_method_invocation_return_value(invocation, + g_variant_new("(i)", ret)); return; } @@ -352,7 +354,8 @@ int FdBroker::GetOwnerId(const std::string& interface_name) { DBUS_PATH_DBUS, DBUS_INTERFACE_DBUS, "RequestName", - g_variant_new("(su)", interface_name.c_str(), G_BUS_NAME_OWNER_FLAGS_NONE), + g_variant_new("(su)", interface_name.c_str(), + G_BUS_NAME_OWNER_FLAGS_NONE), G_VARIANT_TYPE("(u)"), G_DBUS_CALL_FLAGS_NONE, -1, @@ -390,8 +393,9 @@ int FdBroker::GetSenderPid(GDBusConnection *connection, const gchar *sender) { GVariant *body; int pid = 0; - msg = g_dbus_message_new_method_call("org.freedesktop.DBus", "/org/freedesktop/DBus", - "org.freedesktop.DBus", "GetConnectionUnixProcessID"); + msg = g_dbus_message_new_method_call("org.freedesktop.DBus", + "/org/freedesktop/DBus", "org.freedesktop.DBus", + "GetConnectionUnixProcessID"); if (!msg) { LOGE("Can't allocate new method call"); goto out; diff --git a/src/fdbroker-internal.h b/src/fdbroker-internal.h index 9237118..3dd43d6 100644 --- a/src/fdbroker-internal.h +++ b/src/fdbroker-internal.h @@ -48,7 +48,7 @@ class FdBroker { virtual void OnPortRejected(const std::string& appid) = 0; }; - FdBroker(bool mock = false) : mock_(mock) {} + explicit FdBroker(bool mock = false) : mock_(mock) {} ~FdBroker(); static void Dispose() { @@ -111,7 +111,7 @@ class FdBroker { RECEIVER = 1 }; - SocketPair(bool mock = false); + explicit SocketPair(bool mock = false); ~SocketPair(); int Request(); @@ -147,7 +147,8 @@ class FdBroker { int GetOwnerId(const std::string& interface_name); int GetSenderPid(GDBusConnection *connection, const gchar *sender); int RegisterDbusInterface(const std::string& port_name); - void ReceiveMessage(const char* sender_appid, GDBusMethodInvocation* invocation); + void ReceiveMessage(const char* sender_appid, + GDBusMethodInvocation* invocation); std::string GetInterfaceName(const std::string& target_appid, const std::string& port_name); static void OnNameAppeared(GDBusConnection *connection, diff --git a/src/parcel-internal.cc b/src/parcel-internal.cc index e09b614..e568f90 100644 --- a/src/parcel-internal.cc +++ b/src/parcel-internal.cc @@ -128,4 +128,4 @@ const std::vector& Parcel::GetRaw() { return data_; } -} // namespace rpc_port \ No newline at end of file +} // namespace rpc_port diff --git a/src/parcel-internal.h b/src/parcel-internal.h index c729a49..6fc314a 100644 --- a/src/parcel-internal.h +++ b/src/parcel-internal.h @@ -78,4 +78,4 @@ class Parcel { } // namespace rpc_port -#endif // PARCEL_INTERNAL_H_ \ No newline at end of file +#endif // PARCEL_INTERNAL_H_ diff --git a/src/proxy-internal.cc b/src/proxy-internal.cc index 93a212e..84038eb 100644 --- a/src/proxy-internal.cc +++ b/src/proxy-internal.cc @@ -98,9 +98,9 @@ int Proxy::Watch(int fd) { return -1; } - src_= g_io_add_watch(gioc_, - (GIOCondition)(G_IO_IN), - OnDataReceived, this); + src_ = g_io_add_watch(gioc_, + (GIOCondition)(G_IO_IN), + OnDataReceived, this); if (src_ == 0) { LOGE("fail to add watch on socket"); g_source_remove(disconn_src_); @@ -135,7 +135,7 @@ void Proxy::OnPortAppeared(const std::string& appid, } port_.reset(new Port(fd, port_name)); - listener_->OnConnected(appid, *port_); + listener_->OnConnected(appid, port_.get()); Watch(fd); } diff --git a/src/proxy-internal.h b/src/proxy-internal.h index 3721371..876bc43 100644 --- a/src/proxy-internal.h +++ b/src/proxy-internal.h @@ -32,12 +32,12 @@ namespace internal { class Proxy : public FdBroker::IEventWatcher { public: - Proxy(bool mock = false); + explicit Proxy(bool mock = false); virtual ~Proxy(); class IEventListener { public: - virtual void OnConnected(const std::string& endpoint, Port& port) = 0; + virtual void OnConnected(const std::string& endpoint, Port* port) = 0; virtual void OnDisconnected(const std::string& endpoint) = 0; virtual void OnRejected(const std::string& endpoint) = 0; virtual void OnReceived(const std::string& endpoint) = 0; diff --git a/src/rpc-port-parcel.cc b/src/rpc-port-parcel.cc index 5ede077..8888579 100755 --- a/src/rpc-port-parcel.cc +++ b/src/rpc-port-parcel.cc @@ -227,7 +227,6 @@ RPC_API int rpc_port_parcel_write(rpc_port_parcel_h h, } RPC_API int rpc_port_parcel_read_byte(rpc_port_parcel_h h, char* b) { - if (h == nullptr) return RPC_PORT_ERROR_INVALID_PARAMETER; diff --git a/src/rpc-port.cc b/src/rpc-port.cc index bc56034..958e378 100755 --- a/src/rpc-port.cc +++ b/src/rpc-port.cc @@ -42,7 +42,7 @@ class Event { class ProxyExt : public Proxy, public Proxy::IEventListener { public: - ProxyExt(bool mock = false) : Proxy(mock) {} + explicit ProxyExt(bool mock = false) : Proxy(mock) {} virtual ~ProxyExt() = default; void AddConnectedEventListener(rpc_port_proxy_connected_event_cb cb, @@ -69,9 +69,9 @@ class ProxyExt : public Proxy, public Proxy::IEventListener { new Event(cb, user_data)); } - void OnConnected(const std::string& endpoint, Port& port) override { + void OnConnected(const std::string& endpoint, Port* port) override { for (auto& ev : connected_events_) { - ev->cb_(endpoint.c_str(), GetPortName().c_str(), &port, + ev->cb_(endpoint.c_str(), GetPortName().c_str(), port, ev->user_data_); } } @@ -112,11 +112,12 @@ class ProxyExt : public Proxy, public Proxy::IEventListener { class StubExt : public Stub, public Stub::IEventListener { public: - StubExt(const std::string& port, bool mock = false) : Stub(port, mock) {} + explicit StubExt(const std::string& port, bool mock = false) + : Stub(port, mock) {} virtual ~StubExt() = default; void AddConnectedEventListener(rpc_port_stub_connected_event_cb cb, - void* user_data) { + void* user_data) { connected_events_.emplace_back( new Event(cb, user_data)); } @@ -148,9 +149,9 @@ class StubExt : public Stub, public Stub::IEventListener { } int OnReceived(const std::string& sender, - const std::string& instance, Port& port) override { + const std::string& instance, Port* port) override { for (auto& ev : received_events_) { - int ret = ev->cb_(sender.c_str(), instance.c_str(), &port, + int ret = ev->cb_(sender.c_str(), instance.c_str(), port, ev->user_data_); if (ret != 0) return -1; diff --git a/src/stub-internal.cc b/src/stub-internal.cc index cbd09ab..a20d125 100644 --- a/src/stub-internal.cc +++ b/src/stub-internal.cc @@ -79,7 +79,8 @@ gboolean Stub::OnDataReceived(GIOChannel *gio, GIOCondition cond, return FALSE; } - int ret = stub->listener_->OnReceived(p->GetId(), p->GetInstance(), *p); + int ret = stub->listener_->OnReceived(p->GetId(), p->GetInstance(), + p.get()); if (ret != 0) { LOGW("Invalid protocol"); @@ -155,9 +156,9 @@ int Stub::AcceptedPort::Watch() { return -1; } - disconn_src_= g_io_add_watch(gioc_, - (GIOCondition)(G_IO_ERR | G_IO_HUP | G_IO_NVAL), - Stub::OnSocketDisconnected, parent_); + disconn_src_ = g_io_add_watch(gioc_, + (GIOCondition)(G_IO_ERR | G_IO_HUP | G_IO_NVAL), + Stub::OnSocketDisconnected, parent_); if (disconn_src_ == 0) { LOGE("fail to add watch on socket"); g_io_channel_unref(gioc_); @@ -165,9 +166,9 @@ int Stub::AcceptedPort::Watch() { return -1; } - src_= g_io_add_watch(gioc_, - (GIOCondition)(G_IO_IN), - Stub::OnDataReceived, parent_); + src_ = g_io_add_watch(gioc_, + (GIOCondition)(G_IO_IN), + Stub::OnDataReceived, parent_); if (src_ == 0) { LOGE("fail to add watch on socket"); g_source_remove(disconn_src_); diff --git a/src/stub-internal.h b/src/stub-internal.h index ba66bfe..8883805 100644 --- a/src/stub-internal.h +++ b/src/stub-internal.h @@ -40,10 +40,10 @@ class Stub : private FdBroker::IEventListener { virtual void OnDisconnected(const std::string& sender, const std::string& instance) = 0; virtual int OnReceived(const std::string& sender, - const std::string& instance, Port& port) = 0; + const std::string& instance, Port* port) = 0; }; - Stub(const std::string& port_name, bool mock = false); + explicit Stub(const std::string& port_name, bool mock = false); virtual ~Stub(); int Listen(IEventListener* ev); diff --git a/tools/check-coding-style b/tools/check-coding-style new file mode 100755 index 0000000..fd60481 --- /dev/null +++ b/tools/check-coding-style @@ -0,0 +1,28 @@ +#!/bin/bash +# Copyright (c) 2014 Samsung Electronics Co., Ltd All Rights Reserved +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +if [ ! `which cpplint.py` ]; then + echo -e "\nPlease make sure cpplint.py is in your PATH. It is part of depot_tools inside Chromium repository." + exit 1 +fi + +OLDPWD=$PWD +BASE=`dirname $0` +cd $BASE/.. + +# filters +FILTERS="-readability/streams,-build/c++11" + +cpplint.py --root=src --filter="$FILTERS" $(find . \( -name '*.h' -o -name '*.cc' \) ) +RET=$? + +JS_RET_VAL=$? +cd $OLDPWD + +if [ "x$RET" == "x0" ]; then + exit 0 +else + exit 1 +fi diff --git a/unit_tests/src/main.cc b/unit_tests/src/main.cc index 52756d2..fcdb392 100644 --- a/unit_tests/src/main.cc +++ b/unit_tests/src/main.cc @@ -17,7 +17,7 @@ #include #include -int main(int argc, char** argv){ +int main(int argc, char** argv) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); } diff --git a/unit_tests/src/rpc_port_parcel_test.cc b/unit_tests/src/rpc_port_parcel_test.cc index fba0b95..8e89d22 100644 --- a/unit_tests/src/rpc_port_parcel_test.cc +++ b/unit_tests/src/rpc_port_parcel_test.cc @@ -22,13 +22,12 @@ #include "rpc-port-parcel.h" -using namespace std; using ::testing::AtLeast; namespace { class CStringHolder { public: - CStringHolder(char* ptr) noexcept + explicit CStringHolder(char* ptr) noexcept : ptr_(ptr) {} ~CStringHolder() { if (ptr_) @@ -42,7 +41,7 @@ class CStringHolder { private: char* ptr_; }; -} +} // namespace class ParcelTest : public ::testing::Test { public: diff --git a/unit_tests/src/rpc_port_test.cc b/unit_tests/src/rpc_port_test.cc index 5d8686e..11d6eaf 100644 --- a/unit_tests/src/rpc_port_test.cc +++ b/unit_tests/src/rpc_port_test.cc @@ -23,7 +23,6 @@ #include "rpc-port-internal.h" -using namespace std; using ::testing::AtLeast; class RpcPortBase : public ::testing::Test { @@ -84,7 +83,6 @@ class RpcPortBase : public ::testing::Test { private: static GMainLoop* mainloop_; - }; GMainLoop* RpcPortBase::mainloop_ = nullptr; -- 2.7.4