* limitations under the License.
*/
+#include "debug-port-internal.hh"
+
+#include <bundle_internal.h>
#include <parcel.hh>
#include <sys/socket.h>
#include <sys/types.h>
#include <utility>
-#include "debug-port-internal.hh"
#include "log-private.hh"
#undef RPC_DTOR
namespace internal {
namespace {
-const char PATH_RPC_PORT_UTIL_SOCK[] = "/run/aul/daemons/.rpc-port-util-sock";
+
+constexpr const char PATH_RPC_PORT_UTIL_SOCK[] =
+ "/run/aul/daemons/.rpc-port-util-sock";
+constexpr const char ENDPOINT_RPC_PORT_DEBUG[] = "org.tizen.rpcport.debug";
+constexpr const char KEY_PORT_NAME[] = "__K_PORT_NAME__";
RPC_DTOR void DebugPortDtor() {
DebugPort::GetInst()->Dispose();
if (disposed_)
return;
+ if (conn_) {
+ aul_app_com_leave(conn_);
+ conn_ = nullptr;
+ }
+
Unwatch();
JoinThread();
disposed_ = true;
return s;
}
- return {};
+ return nullptr;
+}
+
+std::shared_ptr<DebugPort::Session> DebugPort::FindSession(
+ const std::string& port_name) {
+ std::lock_guard<std::recursive_mutex> lock(GetMutex());
+ for (auto& s : sessions_) {
+ if (s->GetPortName() == port_name)
+ return s;
+ }
+
+ return nullptr;
}
int DebugPort::Send(int port, bool is_read, uint32_t seq,
const void* buf, unsigned int size) {
std::lock_guard<std::recursive_mutex> lock(GetMutex());
+ if (!IsConnected())
+ return 0;
+
auto session = FindSession(port);
- if (session.get() == nullptr) {
+ if (session == nullptr) {
_E("Failed to find session. port(%d)", port);
return -1;
}
}
void DebugPort::Init() {
- CreateThread();
+ aul_app_com_create_async(ENDPOINT_RPC_PORT_DEBUG, nullptr, AppComCb, this,
+ &conn_);
+ if (conn_ == nullptr)
+ return;
+
+ do {
+ int fd = Connect();
+ if (fd < 0)
+ break;
+
+ port_.reset(new Port(fd, "Debug"));
+ if (Watch(fd) < 0)
+ break;
+
+ SetConnectionStatus(true);
+ _W("Connected");
+ CreateThread();
+ } while (0);
+
disposed_ = false;
}
break;
}
- if (!IsConnected()) {
- int fd = Connect();
- if (fd < 0)
- continue;
-
- {
- std::lock_guard<std::recursive_mutex> lock(GetMutex());
- port_.reset(new Port(fd, "Debug"));
- int ret = Watch(fd);
- if (ret < 0)
- continue;
-
- SetConnectionStatus(true);
- _W("Connected");
- }
- }
+ if (!IsConnected())
+ continue;
int ret = port_->Write(reinterpret_cast<void*>(&len), sizeof(len));
if (ret < 0) {
}
}
+int DebugPort::AppComCb(const char* endpoint, aul_app_com_result_e result,
+ bundle* envelope, void* user_data) {
+ const char* val = bundle_get_val(envelope, KEY_PORT_NAME);
+ if (val == nullptr)
+ return -1;
+
+ auto* handle = static_cast<DebugPort*>(user_data);
+ std::string port_name(val);
+ if (port_name.empty() || handle->FindSession(port_name) != nullptr) {
+ auto* handle = static_cast<DebugPort*>(user_data);
+ int fd = handle->Connect();
+ if (fd < 0)
+ return -1;
+
+ std::lock_guard<std::recursive_mutex> lock(handle->GetMutex());
+ handle->port_.reset(new Port(fd, "Debug"));
+ int ret = handle->Watch(fd);
+ if (ret < 0)
+ return -1;
+
+ handle->SetConnectionStatus(true);
+ _W("Connected");
+ handle->CreateThread();
+ }
+
+ return 0;
+}
+
} // namespace internal
} // namespace rpc_port
#ifndef DEBUG_PORT_INTERNAL_HH_
#define DEBUG_PORT_INTERNAL_HH_
+#include <aul_app_com.h>
#include <gio/gio.h>
#include <glib.h>
#include <parcel.hh>
void JoinThread();
std::shared_ptr<DebugPort::Session> FindSession(int port);
+ std::shared_ptr<DebugPort::Session> FindSession(const std::string& port_name);
static gboolean OnDebugPortDisconnectedCb(GIOChannel* io,
GIOCondition cond, gpointer data);
+ static int AppComCb(const char* endpoint, aul_app_com_result_e result,
+ bundle* envelope, void* user_data);
private:
bool disposed_ = true;
std::atomic<bool> is_running_;
SharedQueue<std::shared_ptr<tizen_base::Parcel>> queue_;
mutable std::recursive_mutex rec_mutex_;
+ aul_app_com_connection_h conn_ = nullptr;
};
} // namespace internal
* limitations under the License.
*/
+#include <aul_app_com.h>
#include <glib.h>
+#include <bundle_cpp.h>
+
#include "debug-port.hh"
#include "log-private.hh"
#include "options.hh"
namespace {
+constexpr const char ENDPOINT_RPC_PORT_DEBUG[] = "org.tizen.rpcport.debug";
+constexpr const char KEY_PORT_NAME[] = "__K_PORT_NAME__";
+
class MainLoop {
public:
MainLoop() {
GMainLoop* loop_;
};
+void SendEvent(const std::string& port_name) {
+ tizen_base::Bundle envelope { { KEY_PORT_NAME, port_name } };
+ aul_app_com_send(ENDPOINT_RPC_PORT_DEBUG, envelope.GetHandle());
+}
+
} // namespace
int main(int argc, char** argv) {
}
DebugPort debug_port(options->GetPortName(), options->GetPid());
+ SendEvent(options->GetPortName());
MainLoop loop;
loop.Run();
return 0;