• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2 * Copyright (c) 2023 Shenzhen Kaihong Digital Industry Development 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 #include "napitest.h"
16 #include "napitest_middle.h"
17 #include "hilog/log.h"
18 static constexpr OHOS::HiviewDFX::HiLogLabel LABEL = {LOG_CORE, 0XD002E00, "NAPITESTNAPILayer"};
19 #define NAPITEST_LOGI(fmt, ...) OHOS::HiviewDFX::HiLog::Info(LABEL, \
20     	"%{public}s:%{public}d " fmt, __func__, __LINE__, ##__VA_ARGS__)
21 
22 namespace napitest {
23 namespace napitest_interface {
24 NodeISayHelloListener NodeISayHello::listener_ = {};
addSayHelloListener(NodeISayHelloListener & listener)25 bool NodeISayHello::addSayHelloListener(NodeISayHelloListener& listener)
26 {
27     NodeISayHello::listener_ = listener;
28     return true;
29 }
30 
removeSayHelloListener(NodeISayHelloListener & listener)31 bool NodeISayHello::removeSayHelloListener(NodeISayHelloListener& listener)
32 {
33     return true;
34 }
35 
registerCallbackfunc()36 bool NodeISayHello::registerCallbackfunc()
37 {
38     return true;
39 }
40 
41 // 供业务调用的回调接口
CallbackfuncCallback(NUMBER_TYPE_2 & wid)42 void NodeISayHello::CallbackfuncCallback(NUMBER_TYPE_2& wid)
43 {
44     std::string eventName = "Callbackfunc";
45     NodeISayHello_middle *ptr = new NodeISayHello_middle();
46     ptr->CallbackfuncCallbackMiddle(eventName,  wid);
47     delete ptr;
48 }
49 
unRegisterCallbackfunc()50 bool NodeISayHello::unRegisterCallbackfunc()
51 {
52     return true;
53 }
54 
sayHello(std::string & from,std::string & to,NUMBER_TYPE_9 & sayType)55 bool NodeISayHello::sayHello(std::string& from, std::string& to, NUMBER_TYPE_9& sayType)
56 {
57     NAPITEST_LOGI("NAPITEST_LOGI sayHello from = %s\r\n", from.c_str());
58     NAPITEST_LOGI("NAPITEST_LOGI sayHello to = %s\r\n", to.c_str());
59     NAPITEST_LOGI("NAPITEST_LOGI sayHello sayType = %d\r\n", sayType);
60     SayInfo info1;
61     info1.from = "js1";
62     uint32_t a = 992;
63     info1.fromId.emplace(a);
64     uint32_t b = 1014;
65     info1.toId.emplace(b);
66     info1.to = "native1";
67     info1.content = "hello1";
68     info1.saidTime = "123456789";
69     info1.isEnd = false;
70     SayInfo info2;
71     info2.from = "native";
72     uint32_t c = 101;
73     info2.fromId.emplace(c);
74     uint32_t d = 99;
75     info2.toId.emplace(d);
76     info2.to = "js";
77     info2.content = "hello";
78     info2.saidTime = "987654321";
79     info2.isEnd = true;
80     // 业务代码调用 onSayHelloStart callback
81     listener_.NodeISayHelloListener_onSayHelloStartCallback(info1);
82     // 业务代码调用 onSayHelloEnd callback
83     listener_.NodeISayHelloListener_onSayHelloEndCallback(info2);
84     return true;
85 }
86 
sayHi(std::string & from,std::string & to,NUMBER_TYPE_10 & sayType)87 bool NodeISayHello::sayHi(std::string& from, std::string& to, NUMBER_TYPE_10& sayType)
88 {
89     NAPITEST_LOGI("NAPITEST_LOGI sayHi from = %s\r\n", from.c_str());
90     NAPITEST_LOGI("NAPITEST_LOGI sayHi to = %s\r\n", to.c_str());
91     NAPITEST_LOGI("NAPITEST_LOGI sayHi sayType = %d\r\n", sayType);
92     NodeISayHello *ptr = new NodeISayHello();
93     uint32_t callbackNum = 50;
94     ptr->CallbackfuncCallback(callbackNum);
95     delete ptr;
96     return true;
97 }
98 
sayHelloWithResponse(std::string & from,std::string & to,NUMBER_TYPE_11 & sayType,uint32_t & outErrCode,AUTO_INTERFACE_5 & out)99 bool NodeISayHello::sayHelloWithResponse(std::string& from, std::string& to, NUMBER_TYPE_11& sayType,
100     uint32_t& outErrCode, AUTO_INTERFACE_5& out)
101 {
102     NAPITEST_LOGI("NAPITEST_LOGI sayHelloWithResponse from = %s\r\n", from.c_str());
103     NAPITEST_LOGI("NAPITEST_LOGI sayHelloWithResponse to = %s\r\n", to.c_str());
104     NAPITEST_LOGI("NAPITEST_LOGI sayHelloWithResponse sayType = %d\r\n", sayType);
105     out.errMsg = "";
106     out.response = "rec hello.";
107     out.result = 0;
108     return true;
109 }
110 
111 AUTO_INTERFACE_5 NodeISayHello::auto_interface_5OutRes = {};
auto_interface_5SetCbValue(NUMBER_TYPE_6 result,std::string errMsg,std::string response)112 void NodeISayHello::auto_interface_5SetCbValue(NUMBER_TYPE_6 result, std::string errMsg, std::string response)
113 {
114     NodeISayHello::auto_interface_5OutRes.result = result;
115     NodeISayHello::auto_interface_5OutRes.errMsg = errMsg;
116     NodeISayHello::auto_interface_5OutRes.response = response;
117     return;
118 }
119 
onSayHelloStart()120 bool NodeISayHelloListener::onSayHelloStart()
121 {
122     return true;
123 }
124 
125 // 供业务调用的回调接口
NodeISayHelloListener_onSayHelloStartCallback(SayInfo & info)126 void NodeISayHelloListener::NodeISayHelloListener_onSayHelloStartCallback(SayInfo& info)
127 {
128     std::string eventName = "NodeISayHelloListener_onSayHelloStart";
129     NodeISayHelloListener_middle *ptr = new NodeISayHelloListener_middle();
130     ptr->NodeISayHelloListener_onSayHelloStartCallbackMiddle(eventName,  info);
131     delete ptr;
132 }
133 
onSayHelloEnd()134 bool NodeISayHelloListener::onSayHelloEnd()
135 {
136     return true;
137 }
138 
139 // 供业务调用的回调接口
NodeISayHelloListener_onSayHelloEndCallback(SayInfo & info)140 void NodeISayHelloListener::NodeISayHelloListener_onSayHelloEndCallback(SayInfo& info)
141 {
142     std::string eventName = "NodeISayHelloListener_onSayHelloEnd";
143     NodeISayHelloListener_middle *ptr = new NodeISayHelloListener_middle();
144     ptr->NodeISayHelloListener_onSayHelloEndCallbackMiddle(eventName,  info);
145     delete ptr;
146 }
147 
funcTest(bool & v,std::string & out)148 bool funcTest(bool& v, std::string& out)
149 {
150     if (v) {
151         out = "ret is true";
152     } else {
153         out = "ret is false";
154     }
155     return true;
156 }
157 }
158 }
159