1 /*
2 * Copyright (c) 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 "publisher_listener_stub.h"
17
18 #include "constants.h"
19 #include "distributed_hardware_errno.h"
20 #include "distributed_hardware_log.h"
21
22 namespace OHOS {
23 namespace DistributedHardware {
PublisherListenerStub()24 PublisherListenerStub::PublisherListenerStub()
25 {
26 }
27
~PublisherListenerStub()28 PublisherListenerStub::~PublisherListenerStub()
29 {
30 }
31
OnRemoteRequest(uint32_t code,MessageParcel & data,MessageParcel & reply,MessageOption & option)32 int32_t PublisherListenerStub::OnRemoteRequest(
33 uint32_t code, MessageParcel &data, MessageParcel &reply, MessageOption &option)
34 {
35 if (data.ReadInterfaceToken() != GetDescriptor()) {
36 DHLOGE("PublisherListenerStub read valid token failed");
37 return ERR_INVALID_DATA;
38 }
39 IPublisherListener::Message msgCode = static_cast<IPublisherListener::Message>(code);
40 switch (msgCode) {
41 case IPublisherListener::Message::ON_MESSAGE: {
42 DHTopic topic = static_cast<DHTopic>(data.ReadUint32());
43 if (topic < DHTopic::TOPIC_MIN || topic > DHTopic::TOPIC_MAX) {
44 DHLOGE("Topic is invalid!");
45 return ERR_INVALID_DATA;
46 }
47 std::string message = data.ReadString();
48 if (message.empty() || message.size() > MAX_MESSAGE_LEN) {
49 DHLOGE("Message is invalid!");
50 return ERR_INVALID_DATA;
51 }
52 OnMessage(topic, message);
53 break;
54 }
55 default:
56 return IPCObjectStub::OnRemoteRequest(code, data, reply, option);
57 }
58
59 return DH_FWK_SUCCESS;
60 }
61 } // namespace DistributedHardware
62 } // namespace OHOS