void ChildTerminated(int sig_no) {
LOG(INFO) << "sig_no : " << sig_no;
- wrt_ipc->SendMessage("CloseDBusConnection", "");
wrt_ipc.reset();
child_created = false;
// not touch here.
started_apps.erase(command_value);
}
- if (wrt_ipc->HasDbusOwner(kWrtDbusName)) {
+ if (wrt_ipc && wrt_ipc->HasDbusOwner(kWrtDbusName)) {
wrt_ipc->SendMessage(command_key.c_str(), command_value.c_str());
} else {
command_queue.push(std::make_pair(command_key, command_value));
}
void InterProcessCommunication::Message::CloseDBusConnection() const {
- dbus_connection_close(connection_);
+ if (connection_) {
+ dbus_connection_close(connection_);
+ }
}
void InterProcessCommunication::Message::Reply(const char* argument) const {
+ if (!connection_) {
+ LOG(ERROR) << "connection_ is not valid";
+ return;
+ }
DBusMessage* reply = dbus_message_new_method_return(message_);
dbus_message_append_args(reply, DBUS_TYPE_STRING, &argument, DBUS_TYPE_INVALID);
dbus_connection_send(connection_, reply, nullptr);
}
InterProcessCommunication::~InterProcessCommunication() {
- dbus_connection_close(connection_);
- dbus_connection_unref(connection_);
+ if (connection_) {
+ dbus_connection_close(connection_);
+ dbus_connection_unref(connection_);
+ connection_ = nullptr;
+ }
}
// static
std::string member = dbus_message_get_member(message);
auto* ipc = reinterpret_cast<InterProcessCommunication*>(user_data);
+ if (!ipc || !ipc->connection_) {
+ LOG(ERROR) << "ipc or connection_ is not valid";
+ return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+ }
auto iterator = ipc->message_handlers_.find(member);
if (iterator != ipc->message_handlers_.end()) {
DBusError error;
}
DBusMessage* InterProcessCommunication::InternalSendMessage(const char* receiver, const char* type, const char* argument, bool need_reply) {
+ if (!connection_) {
+ LOG(ERROR) << "connection_ is not valid";
+ return nullptr;
+ }
DBusMessage* message = dbus_message_new_method_call(receiver, WRT_DBUS_PATH, WRT_DBUS_NAME, type);
if (!message) {
LOG(ERROR) << "Fail to create dbus message";
}
bool InterProcessCommunication::HasDbusOwner(const char* dbus_name) {
+ if (!connection_) {
+ LOG(ERROR) << "connection_ is not valid";
+ return false;
+ }
+
DBusError err;
dbus_error_init(&err);