• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 namespace OHOS {
29 namespace HiviewDFX {
30 static constexpr HiLogLabel LABEL = { LOG_CORE, 0xD002D08, "HiView-QuerySysEventCallbackStub" };
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)31 int32_t QuerySysEventCallbackStub::OnRemoteRequest(uint32_t code, MessageParcel& data,
32     MessageParcel& reply, MessageOption& option)
33 {
34     std::u16string descripter = QuerySysEventCallbackStub::GetDescriptor();
35     std::u16string remoteDescripter = data.ReadInterfaceToken();
36     if (descripter != remoteDescripter) {
37         HiLog::Error(LABEL, "read descriptor failed.");
38         return ERR_INVALID_VALUE;
39     }
40     bool ret = false;
41     switch (code) {
42         case ON_QUERY: {
43             std::vector<std::u16string> sysEvent;
44             ret = AshMemUtils::ReadBulkData(data, sysEvent);
45             if (!ret) {
46                 HiLog::Error(LABEL, "parcel read sys event failed.");
47                 return ERR_FLATTEN_OBJECT;
48             }
49             std::vector<int64_t> seq;
50             ret = data.ReadInt64Vector(&seq);
51             if (!ret) {
52                 HiLog::Error(LABEL, "parcel read seq failed.");
53                 return ERR_FLATTEN_OBJECT;
54             }
55             OnQuery(sysEvent, seq);
56             return ERR_OK;
57         }
58         case ON_COMPLETE: {
59             int32_t reason = 0;
60             ret = data.ReadInt32(reason);
61             if (!ret) {
62                 HiLog::Error(LABEL, "parcel read reason failed.");
63                 return ERR_FLATTEN_OBJECT;
64             }
65             int32_t total = 0;
66             ret = data.ReadInt32(total);
67             if (!ret) {
68                 HiLog::Error(LABEL, "parcel read total failed.");
69                 return ERR_FLATTEN_OBJECT;
70             }
71             int64_t seq = 0;
72             ret = data.ReadInt64(seq);
73             if (!ret) {
74                 HiLog::Error(LABEL, "parcel read seq failed.");
75                 return ERR_FLATTEN_OBJECT;
76             }
77             OnComplete(reason, total, seq);
78             return ERR_OK;
79         }
80         default:
81             return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
82     }
83 }
84 } // namespace HiviewDFX
85 } // namespace OHOS
86