• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024 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 RS_PROFILER_NETWORK_H
17 #define RS_PROFILER_NETWORK_H
18 
19 #include <chrono>
20 #include <queue>
21 #include <mutex>
22 #include <string>
23 #include <vector>
24 #include <unordered_set>
25 
26 namespace OHOS::Rosen {
27 
28 class Packet;
29 class Socket;
30 class RSCaptureData;
31 enum class PackageID;
32 
33 class Network {
34 public:
35     static void Run();
36     static void Stop();
37     static void ForceShutdown();
38     static bool IsRunning();
39 
40     static void SendRdcPath(const std::string& path);
41     static void SendDclPath(const std::string& path);
42     static void SendMskpPath(const std::string& path);
43     static void SendBetaRecordPath(const std::string& path);
44 
45     static void SendSkp(const void* data, size_t size);
46     static void SendCaptureData(const RSCaptureData& data);
47     static void SendRSTreeDumpJSON(const std::string& jsonstr);
48     static void SendRSTreePerfNodeList(const std::unordered_set<uint64_t>& perfNodesList);
49     static void SendRSTreeSingleNodePerf(uint64_t id, uint64_t nanosec);
50 
51     static void SendBinary(const void* data, size_t size);
52     static void SendBinary(const std::vector<char>& data);
53     static void SendBinary(const std::string& data);
54     static void SendMessage(const std::string& message);
55 
56     static bool PopCommand(std::vector<std::string>& args);
57 
58     static void SetBlockBinary(bool blockFlag);
59 
60 private:
61     static void PushCommand(const std::vector<std::string>& args);
62     static void ResetCommandQueue();
63     static void ProcessCommand(const char* data, size_t size);
64     static void ProcessBinary(const std::vector<char>& data);
65     static void Receive(Socket& socket);
66     static void Send(Socket& socket);
67     static void SendPath(const std::string& path, PackageID id);
68     static void SendPacket(Packet& packet);
69     static void ResetSendQueue();
70     static void Shutdown(Socket*& socket);
71     static void Ping(const Socket& socket);
72     static void ResetPing();
73 
74 private:
75     static std::atomic<bool> isRunning_;
76     static std::atomic<bool> forceShutdown_;
77     static std::atomic<bool> blockBinary_;
78     static std::chrono::steady_clock::time_point ping_;
79 
80     static std::mutex incomingMutex_;
81     static std::queue<std::vector<std::string>> incoming_;
82 
83     static std::mutex outgoingMutex_;
84     static std::queue<std::vector<char>> outgoing_;
85 };
86 
87 } // namespace OHOS::Rosen
88 
89 #endif // RS_PROFILER_NETWORK_H