1 /*
2  * Copyright (c) 2024 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "oaid_remote_config_observer_proxy.h"
17 #include "oaid_iremote_config_observer.h"
18 #include "oaid_common.h"
19 
20 namespace OHOS {
21 namespace Cloud {
ControlConfigObserverProxy(const sptr<IRemoteObject> &impl)22 ControlConfigObserverProxy::ControlConfigObserverProxy(const sptr<IRemoteObject> &impl)
23     : IRemoteProxy<IRemoteConfigObserver>(impl)
24 {}
25 
WriteInterfaceToken(MessageParcel &data)26 bool ControlConfigObserverProxy::WriteInterfaceToken(MessageParcel &data)
27 {
28     if (!data.WriteInterfaceToken(ControlConfigObserverProxy::GetDescriptor())) {
29         OAID_HILOGI(OAID_MODULE_CLIENT, "write interface token failed");
30         return false;
31     }
32     return true;
33 }
34 
OnOaidUpdated(const std::string &value)35 void ControlConfigObserverProxy::OnOaidUpdated(const std::string &value)
36 {
37     MessageParcel data;
38     MessageParcel reply;
39     MessageOption option(MessageOption::TF_ASYNC);
40     if (!data.WriteInterfaceToken(GetDescriptor())) {
41         OAID_HILOGI(OAID_MODULE_CLIENT, "WriteInterfaceToken data fail");
42         return;
43     }
44     sptr<IRemoteObject> remote = Remote();
45     if (remote == nullptr) {
46         OAID_HILOGI(OAID_MODULE_CLIENT, "remote is null");
47         return;
48     }
49     if (!data.WriteString(value)) {
50         OAID_HILOGI(OAID_MODULE_CLIENT, "WriteString failed.");
51         return;
52     }
53     int ret = remote->SendRequest(static_cast<uint32_t>(RegisterObserverCode::OnOaidUpdated), data, reply, option);
54     if (ret != ERR_OK) {
55         OAID_HILOGI(OAID_MODULE_CLIENT, "OnOaidUpdated failed, error code: %{public}d", ret);
56     }
57 }
58 }  // namespace Cloud
59 }  // namespace OHOS