1 /*
2 * Copyright (c) 2021 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 "wasm_func.h"
17 #include <cstdio>
18 #include <emscripten.h>
19 #include "rpc_server.h"
20 namespace SysTuning {
21 namespace TraceStreamer {
22 RpcServer g_wasmTraceStreamer;
23 extern "C" {
24 // return 0 while ok, -1 while failed
TraceStreamerParseData(const uint8_t * data,int dataLen)25 EMSCRIPTEN_KEEPALIVE int TraceStreamerParseData(const uint8_t* data, int dataLen)
26 {
27 if (g_wasmTraceStreamer.ParseData(data, dataLen, nullptr)) {
28 return 0;
29 }
30 return -1;
31 }
TraceStreamerParseDataOver()32 EMSCRIPTEN_KEEPALIVE int TraceStreamerParseDataOver()
33 {
34 if (g_wasmTraceStreamer.ParseDataOver(nullptr, 0, nullptr)) {
35 return 0;
36 }
37 return -1;
38 }
TraceStreamerSqlOperate(const uint8_t * sql,int sqlLen)39 EMSCRIPTEN_KEEPALIVE int TraceStreamerSqlOperate(const uint8_t* sql, int sqlLen)
40 {
41 if (g_wasmTraceStreamer.SqlOperate(sql, sqlLen, nullptr)) {
42 return 0;
43 }
44 return -1;
45 }
TraceStreamerReset()46 EMSCRIPTEN_KEEPALIVE int TraceStreamerReset()
47 {
48 g_wasmTraceStreamer.Reset(nullptr, 0, nullptr);
49 return 0;
50 }
51 // return the length of result, -1 while failed
TraceStreamerSqlQuery(const uint8_t * sql,int sqlLen,uint8_t * out,int outLen)52 EMSCRIPTEN_KEEPALIVE int TraceStreamerSqlQuery(const uint8_t* sql, int sqlLen, uint8_t* out, int outLen)
53 {
54 return g_wasmTraceStreamer.WasmSqlQuery(sql, sqlLen, out, outLen);
55 }
56 } // extern "C"
57 } // namespace TraceStreamer
58 } // namespace SysTuning
59