-static int AppComCreate(const char* endpoint,
- aul_app_com_permission_h permission, app_com_cb callback, void* user_data,
- bool sync, aul_app_com_connection_h* connection) {
- if (endpoint == nullptr || callback == nullptr || connection == nullptr) {
- _E("Invalid parameter");
- return AUL_R_EINVAL;
- }
-
- if (!aul_is_initialized()) {
- if (aul_launch_init(nullptr, nullptr) < 0)
- return AUL_R_ENOINIT;
- }
-
- tizen_base::Bundle b;
- b.Add(AUL_K_COM_ENDPOINT, endpoint);
-
- if (permission) {
- auto* handle = static_cast<AppComPermission*>(permission);
- auto option = handle->GetPropagationOption();
- if (option) {
- auto* p = reinterpret_cast<unsigned char*>(&option);
- std::vector<unsigned char> bytes;
- std::copy(p, p + sizeof(option), std::back_inserter(bytes));
- b.Add(AUL_K_COM_PROPAGATE, bytes);
- }
-
- if (!handle->GetPrivilege().empty())
- b.Add(AUL_K_COM_PRIVILEGE, handle->GetPrivilege());
- }
-
- int ret;
- if (sync) {
- ret = app_send_cmd(AUL_UTIL_PID, APP_COM_CREATE, b.GetHandle());
- } else {
- ret = app_send_cmd_with_noreply(AUL_UTIL_PID, APP_COM_CREATE,
- b.GetHandle());
- }
-
- if (ret == 0) {
- *connection = static_cast<aul_app_com_connection_h>(
- context.AddConnection(endpoint, callback, user_data));
- }
-
- return ret;
-}
-