• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef RPC_RPC_H
17 #define RPC_RPC_H
18 
19 #include <functional>
20 #include <mutex>
21 #include "trace_streamer_selector.h"
22 namespace SysTuning {
23 namespace TraceStreamer {
24 class RpcServer {
25 public:
26     using ResultCallBack = std::function<void(const std::string /* result */, int)>;
27 
28     using SendDataCallBack = std::function<void(const char*, int, int)>;
29     // In order to bind HTTP, maintain a unified interface, even if some parameters are useless
30     bool ParseData(const uint8_t* data, size_t len, ResultCallBack resultCallBack);
31     bool ParseDataOver(const uint8_t* data, size_t len, ResultCallBack resultCallBack);
32     bool SqlOperate(const uint8_t* data, size_t len, ResultCallBack resultCallBack);
33     bool SqlQuery(const uint8_t* data, size_t len, ResultCallBack resultCallBack);
34     bool Reset(const uint8_t* data, size_t len, ResultCallBack resultCallBack);
35     void CancelSqlQuery();
36 
37     // only for wasm, no callback
38     int WasmSqlQuery(const uint8_t* data, size_t len, uint8_t* out, int outLen);
39     int WasmSqlQueryWithCallback(const uint8_t* data, size_t len, ResultCallBack callback) const;
40     int UpdateTraceTime(const uint8_t* data, int len);
41     int TraceStreamer_Init_ThirdParty_Config(const uint8_t* data, int len);
42     std::map<int, std::string> g_thirdPartyConfig;
43 private:
44     std::unique_ptr<TraceStreamerSelector> ts_ = std::make_unique<TraceStreamerSelector>();
45     size_t lenParseData_ = 0;
46 };
47 } // namespace TraceStreamer
48 } // namespace SysTuning
49 #endif // RPC_RPC_H
50