#include <cynara-error.h>
#include <cynara-creds-gdbus.h>
-#include "ac-internal.h"
+#include "ac-internal.hh"
#include "log-private.hh"
namespace rpc_port {
void AddPrivilege(std::string privilege);
void SetTrusted(const bool trusted);
- int Check(GDBusConnection *connection, const char *sender,
+ int Check(GDBusConnection* connection, const char* sender,
const char* sender_appid);
private:
class Cynara {
public:
- Cynara();
- ~Cynara();
+ Cynara();
+ ~Cynara();
- int FetchCredsFromDBus(GDBusConnection *connection, const char *sender);
- int Check(const std::string& privilege) const;
+ int FetchCredsFromDBus(GDBusConnection* connection, const char* sender);
+ int Check(const std::string& privilege) const;
private:
- std::unique_ptr<cynara, decltype(cynara_finish)*> cynara_;
- std::unique_ptr<char, decltype(std::free)*> client_;
- std::unique_ptr<char, decltype(std::free)*> user_;
+ std::unique_ptr<cynara, decltype(cynara_finish)*> cynara_;
+ std::unique_ptr<char, decltype(std::free)*> client_;
+ std::unique_ptr<char, decltype(std::free)*> user_;
};
int SetCache(const std::string& sender);
- int CheckTrusted(const char *sender_appid);
+ int CheckTrusted(const char* sender_appid);
int CheckPrivilege(const Cynara& c);
private:
#include "debug-port-internal.hh"
#include "log-private.hh"
-#include "parcel-internal.h"
+#include "parcel-internal.hh"
namespace rpc_port {
namespace internal {
-static const char PATH_RPC_PORT_UTIL_SOCK[] =
- "/run/aul/daemons/.rpc-port-util-sock";
-static const char RPC_PORT_SIGNAL_PATH[] = "/Org/Tizen/RPC/Port/Signal";
-static const char RPC_PORT_SIGNAL_INTERFACE[] = "org.tizen.rpc.port.signal";
-static const char RPC_PORT_SIGNAL_DEBUG[] = "Debug";
-static const char RPC_PORT_SIGNAL_NEW[] = "New";
+namespace {
+const char PATH_RPC_PORT_UTIL_SOCK[] = "/run/aul/daemons/.rpc-port-util-sock";
+const char RPC_PORT_SIGNAL_PATH[] = "/Org/Tizen/RPC/Port/Signal";
+const char RPC_PORT_SIGNAL_INTERFACE[] = "org.tizen.rpc.port.signal";
+const char RPC_PORT_SIGNAL_DEBUG[] = "Debug";
+const char RPC_PORT_SIGNAL_NEW[] = "New";
+} // namespace
DebugPort::~DebugPort() {
if (!disposed_)
int main_port, int delegate_port) {
std::lock_guard<std::recursive_mutex> lock(GetMutex());
sessions_.emplace_back(
- new DebugPort::Session(
- port_name, destination, main_port, delegate_port));
+ new DebugPort::Session(std::move(port_name), std::move(destination),
+ main_port, delegate_port));
}
void DebugPort::RemoveSession(int port) {
std::lock_guard<std::recursive_mutex> lock(GetMutex());
- auto iter = sessions_.begin();
- while (iter != sessions_.end()) {
- if ((*iter)->GetMainPort() == port ||
- (*iter)->GetDelegatePort() == port) {
- _W("Remove session. port(%d)", port);
- iter = sessions_.erase(iter);
- break;
- }
-
- ++iter;
+ auto iter = std::find_if(sessions_.begin(), sessions_.end(),
+ [port](std::shared_ptr<DebugPort::Session>& sess) -> bool {
+ return sess->GetMainPort() == port || sess->GetDelegatePort() == port;
+ });
+
+ if (iter != sessions_.end()) {
+ _W("Remove session. port(%d)", port);
+ iter = sessions_.erase(iter);
}
}
#include <string>
#include <thread>
-#include "parcel-internal.h"
-#include "port-internal.h"
+#include "parcel-internal.hh"
+#include "port-internal.hh"
#include "shared-queue-internal.hh"
namespace rpc_port {
#include <algorithm>
-#include "fdbroker-internal.h"
+#include "fdbroker-internal.hh"
#include "log-private.hh"
#define EILLEGALACCESS 127
}
int FdBroker::FdList::Add(int fd) {
- GError *err = nullptr;
+ GError* err = nullptr;
g_unix_fd_list_append(fd_list_, fd, &err);
close(fd);
const std::string& port_name,
int (*fds)[2]) {
std::string interface_name = GetInterfaceName(target_appid, port_name);
- GDBusMessage *msg;
+ GDBusMessage* msg;
SocketPair main_sock_pair(mock_);
SocketPair delegate_sock_pair(mock_);
FdList fd_list;
free(returned_fds);
}
-void FdBroker::OnReceiveDbusMethod(GDBusConnection *conn,
- const gchar *sender, const gchar *object_path,
- const gchar *iface_name, const gchar *method_name,
- GVariant *parameters, GDBusMethodInvocation *invocation,
+void FdBroker::OnReceiveDbusMethod(GDBusConnection* conn,
+ const gchar* sender, const gchar* object_path,
+ const gchar* iface_name, const gchar* method_name,
+ GVariant* parameters, GDBusMethodInvocation* invocation,
gpointer user_data) {
auto* ptr = static_cast<std::weak_ptr<FdBroker>*>(user_data);
auto broker = ptr->lock();
int FdBroker::GetOwnerId(const std::string& interface_name) {
int owner_id = 0;
- GError *error = NULL;
+ GError* error = NULL;
GVariant* result = g_dbus_connection_call_sync(
DBusConnectionManager::GetInst().GetConnection(),
return owner_id;
}
-int FdBroker::GetSenderPid(GDBusConnection *connection, const gchar *sender) {
- GDBusMessage *msg = NULL;
- GDBusMessage *reply = NULL;
- GError *err = NULL;
- GVariant *body;
+int FdBroker::GetSenderPid(GDBusConnection* connection, const gchar* sender) {
+ GDBusMessage* msg = NULL;
+ GDBusMessage* reply = NULL;
+ GError* err = NULL;
+ GVariant* body;
int pid = 0;
msg = g_dbus_message_new_method_call("org.freedesktop.DBus",
return ac_;
}
-void FdBroker::OnNameAppeared(GDBusConnection *connection,
- const gchar *name,
- const gchar *name_owner,
+void FdBroker::OnNameAppeared(GDBusConnection* connection,
+ const gchar* name,
+ const gchar* name_owner,
gpointer user_data) {
auto* ptr = static_cast<std::weak_ptr<FdBroker>*>(user_data);
auto broker = ptr->lock();
broker->watcher_->OnPortAppeared();
}
-void FdBroker::OnNameVanished(GDBusConnection *connection,
- const gchar *name,
+void FdBroker::OnNameVanished(GDBusConnection* connection,
+ const gchar* name,
gpointer user_data) {
auto* ptr = static_cast<std::weak_ptr<FdBroker>*>(user_data);
auto broker = ptr->lock();
#include <thread>
#include <list>
-#include "ac-internal.h"
+#include "ac-internal.hh"
#include "rpc-port.h"
namespace rpc_port {
};
private:
- static void OnReceiveDbusMethod(GDBusConnection *conn, const gchar *sender,
- const gchar *object_path,
- const gchar *iface_name,
- const gchar *method_name,
- GVariant *parameters,
- GDBusMethodInvocation *invocation,
+ static void OnReceiveDbusMethod(GDBusConnection* conn, const gchar* sender,
+ const gchar* object_path,
+ const gchar* iface_name,
+ const gchar* method_name,
+ GVariant* parameters,
+ GDBusMethodInvocation* invocation,
gpointer user_data);
int GetOwnerId(const std::string& interface_name);
- int GetSenderPid(GDBusConnection *connection, const gchar *sender);
+ int GetSenderPid(GDBusConnection* connection, const gchar* sender);
int RegisterDbusInterface(const std::string& port_name);
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,
- const gchar *name,
- const gchar *name_owner,
+ static void OnNameAppeared(GDBusConnection* connection,
+ const gchar* name,
+ const gchar* name_owner,
gpointer user_data);
- static void OnNameVanished(GDBusConnection *connection,
- const gchar *name,
+ static void OnNameVanished(GDBusConnection* connection,
+ const gchar* name,
gpointer user_data);
static void OnResultReceived(GObject* source_object,
GAsyncResult* res,
*/
#include <cstring>
-#include "parcel-internal.h"
+#include "parcel-internal.hh"
namespace rpc_port {
}
// LCOV_EXCL_STOP
+template<typename T>
+void Parcel::Write(T d) {
+ unsigned char* p = reinterpret_cast<unsigned char*>(&d);
+
+ std::copy(p, p + sizeof(T), std::back_inserter(data_));
+}
+
+template<typename T>
+T Parcel::Read() {
+ T d = 0;
+ unsigned char* p = reinterpret_cast<unsigned char*>(&d);
+
+ if (reader_ + sizeof(T) > data_.size())
+ return d;
+ std::copy(&data_[reader_], &data_[reader_] + sizeof(T), p);
+ reader_ += sizeof(T);
+ return d;
+}
+
+
} // namespace rpc_port
private:
template<typename T>
- void Write(T d) {
- unsigned char* p = reinterpret_cast<unsigned char*>(&d);
-
- std::copy(p, p + sizeof(T), std::back_inserter(data_));
- }
+ void Write(T d);
template<typename T>
- T Read() {
- T d = 0;
- unsigned char* p = reinterpret_cast<unsigned char*>(&d);
-
- if (reader_ + sizeof(T) > data_.size())
- return d;
- std::copy(&data_[reader_], &data_[reader_] + sizeof(T), p);
- reader_ += sizeof(T);
- return d;
- }
+ T Read();
private:
std::vector<unsigned char> data_;
#include <glib-unix.h>
#include "log-private.hh"
-#include "port-internal.h"
+#include "port-internal.hh"
#include "rpc-port.h"
#define MAX_CNT 100
}
private:
- class DelayMessage {
- public:
- DelayMessage(const char* msg, int start_index, int size);
- ~DelayMessage() = default;
- void SetIndex(int index);
- int GetSize();
- int GetOriginalSize();
- char* GetMessage();
-
- private:
- std::vector<unsigned char> message_;
- int index_;
- int size_;
- };
-
- enum PortStatus {
- PORT_STATUS_ERROR_NONE,
- PORT_STATUS_ERROR_IO_ERROR,
- PORT_STATUS_ERROR_RESOURCE_UNAVAILABLE
+ class DelayMessage {
+ public:
+ DelayMessage(const char* msg, int start_index, int size);
+ ~DelayMessage() = default;
+ void SetIndex(int index);
+ int GetSize();
+ int GetOriginalSize();
+ char* GetMessage();
+
+ private:
+ std::vector<unsigned char> message_;
+ int index_;
+ int size_;
+ };
+
+ enum PortStatus {
+ PORT_STATUS_ERROR_NONE,
+ PORT_STATUS_ERROR_IO_ERROR,
+ PORT_STATUS_ERROR_RESOURCE_UNAVAILABLE
};
int PushDelayedMessage(std::shared_ptr<DelayMessage> dm);
#include "debug-port-internal.hh"
#include "log-private.hh"
-#include "proxy-internal.h"
+#include "proxy-internal.hh"
#define EILLEGALACCESS 127
_D("Proxy::~Proxy");
}
-gboolean Proxy::OnSocketDisconnected(GIOChannel *gio, GIOCondition cond,
+gboolean Proxy::OnSocketDisconnected(GIOChannel* gio, GIOCondition cond,
gpointer data) {
Proxy* proxy = static_cast<Proxy*>(data);
IEventListener* listener = proxy->listener_;
return FALSE;
}
-gboolean Proxy::OnDataReceived(GIOChannel *gio, GIOCondition cond,
+gboolean Proxy::OnDataReceived(GIOChannel* gio, GIOCondition cond,
gpointer data) {
Proxy* proxy = static_cast<Proxy*>(data);
int fd = g_io_channel_unix_get_fd(gio);
#include <string>
#include <memory>
-#include "fdbroker-internal.h"
-#include "port-internal.h"
+#include "fdbroker-internal.hh"
+#include "port-internal.hh"
namespace rpc_port {
namespace internal {
};
private:
- static gboolean OnSocketDisconnected(GIOChannel *gio, GIOCondition cond,
+ static gboolean OnSocketDisconnected(GIOChannel* gio, GIOCondition cond,
gpointer data);
- static gboolean OnDataReceived(GIOChannel *gio, GIOCondition cond,
+ static gboolean OnDataReceived(GIOChannel* gio, GIOCondition cond,
gpointer data);
static gboolean DbusNameTimeout(gpointer user_data);
void OnPortAppeared() override;
#include "rpc-port-parcel.h"
-#include "parcel-internal.h"
-#include "port-internal.h"
+#include "parcel-internal.hh"
+#include "port-internal.hh"
#define MAX_PARCEL_SIZE (1024 * 1024 * 10)
}
Parcel* p = new Parcel(buf, len);
- delete[] buf;
+ delete[] buf;
*h = p;
return RPC_PORT_ERROR_NONE;
// LCOV_EXCL_STOP
// LCOV_EXCL_START
-RPC_API int rpc_port_parcel_to_array(rpc_port_parcel_h h, void **array,
- unsigned int *size) {
+RPC_API int rpc_port_parcel_to_array(rpc_port_parcel_h h, void** array,
+ unsigned int* size) {
if (h == nullptr || !array || !size)
return RPC_PORT_ERROR_INVALID_PARAMETER;
// LCOV_EXCL_STOP
// LCOV_EXCL_START
-RPC_API int rpc_port_parcel_from_array(rpc_port_parcel_h h, const void *array,
+RPC_API int rpc_port_parcel_from_array(rpc_port_parcel_h h, const void* array,
unsigned int size) {
if (h == nullptr || !array || size == 0)
return RPC_PORT_ERROR_INVALID_PARAMETER;
#include <thread>
#include "log-private.hh"
-#include "port-internal.h"
-#include "proxy-internal.h"
+#include "port-internal.hh"
+#include "proxy-internal.hh"
#include "rpc-port.h"
-#include "stub-internal.h"
+#include "stub-internal.hh"
#undef RPC_API
#define RPC_API extern "C" __attribute__((visibility("default")))
// LCOV_EXCL_STOP
RPC_API int rpc_port_proxy_add_connected_event_cb(rpc_port_proxy_h h,
- rpc_port_proxy_connected_event_cb cb, void *user_data) {
+ rpc_port_proxy_connected_event_cb cb, void* user_data) {
if (h == nullptr || cb == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
}
RPC_API int rpc_port_stub_get_port(rpc_port_stub_h h,
- rpc_port_port_type_e type, const char *instance, rpc_port_h* port) {
+ rpc_port_port_type_e type, const char* instance, rpc_port_h* port) {
if (h == nullptr || port == nullptr || instance == nullptr)
return RPC_PORT_ERROR_INVALID_PARAMETER;
#include "debug-port-internal.hh"
#include "log-private.hh"
-#include "stub-internal.h"
+#include "stub-internal.hh"
namespace rpc_port {
namespace internal {
}
}
-gboolean Stub::OnDataReceived(GIOChannel *gio, GIOCondition cond,
+gboolean Stub::OnDataReceived(GIOChannel* gio, GIOCondition cond,
gpointer data) {
Stub* stub = static_cast<Stub*>(data);
int fd = g_io_channel_unix_get_fd(gio);
return TRUE;
}
-gboolean Stub::OnSocketDisconnected(GIOChannel *gio, GIOCondition cond,
+gboolean Stub::OnSocketDisconnected(GIOChannel* gio, GIOCondition cond,
gpointer data) {
Stub* stub = static_cast<Stub*>(data);
int fd = g_io_channel_unix_get_fd(gio);
#include <memory>
#include "debug-port-internal.hh"
-#include "fdbroker-internal.h"
-#include "port-internal.h"
+#include "fdbroker-internal.hh"
+#include "port-internal.hh"
namespace rpc_port {
namespace internal {
bool is_delegate_ = false;
};
- static gboolean OnDataReceived(GIOChannel *gio, GIOCondition cond,
+ static gboolean OnDataReceived(GIOChannel* gio, GIOCondition cond,
gpointer data);
- static gboolean OnSocketDisconnected(GIOChannel *gio, GIOCondition cond,
+ static gboolean OnSocketDisconnected(GIOChannel* gio, GIOCondition cond,
gpointer data);
void OnFdReceived(const std::string& sender, int fds[2]) override;