1 /*
2  * Copyright (c) 2021-2022 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 "query_sys_event_callback_stub.h"
17 
18 #include <cstdint>
19 #include <string>
20 #include <vector>
21 
22 #include "ash_mem_utils.h"
23 #include "errors.h"
24 #include "hilog/log.h"
25 #include "ipc_object_stub.h"
26 #include "ipc_types.h"
27 
28 #undef LOG_DOMAIN
29 #define LOG_DOMAIN 0xD002D08
30 
31 #undef LOG_TAG
32 #define LOG_TAG "HISYSEVENT_CALLBACK_STUB"
33 
34 namespace OHOS {
35 namespace HiviewDFX {
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)36 int32_t QuerySysEventCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
37     MessageParcel& reply, MessageOption& option)
38 {
39     std::u16string descripter = QuerySysEventCallbackStub::GetDescriptor();
40     std::u16string remoteDescripter = data.ReadInterfaceToken();
41     if (descripter != remoteDescripter) {
42         HILOG_ERROR(LOG_CORE, "read descriptor failed.");
43         return ERR_INVALID_VALUE;
44     }
45     bool ret = false;
46     switch (code) {
47         case ON_QUERY: {
48             std::vector<std::u16string> sysEvent;
49             ret = AshMemUtils::ReadBulkData(data, sysEvent);
50             if (!ret) {
51                 HILOG_ERROR(LOG_CORE, "parcel read sys event failed.");
52                 return ERR_FLATTEN_OBJECT;
53             }
54             std::vector<int64_t> seq;
55             ret = data.ReadInt64Vector(&seq);
56             if (!ret) {
57                 HILOG_ERROR(LOG_CORE, "parcel read seq failed.");
58                 return ERR_FLATTEN_OBJECT;
59             }
60             OnQuery(sysEvent, seq);
61             return ERR_OK;
62         }
63         case ON_COMPLETE: {
64             int32_t reason = 0;
65             ret = data.ReadInt32(reason);
66             if (!ret) {
67                 HILOG_ERROR(LOG_CORE, "parcel read reason failed.");
68                 return ERR_FLATTEN_OBJECT;
69             }
70             int32_t total = 0;
71             ret = data.ReadInt32(total);
72             if (!ret) {
73                 HILOG_ERROR(LOG_CORE, "parcel read total failed.");
74                 return ERR_FLATTEN_OBJECT;
75             }
76             int64_t seq = 0;
77             ret = data.ReadInt64(seq);
78             if (!ret) {
79                 HILOG_ERROR(LOG_CORE, "parcel read seq failed.");
80                 return ERR_FLATTEN_OBJECT;
81             }
82             OnComplete(reason, total, seq);
83             return ERR_OK;
84         }
85         default:
86             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
87     }
88 }
89 } // namespace HiviewDFX
90 } // namespace OHOS
91