• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) Huawei Technologies Co., Ltd. 2024. All rights reserved.
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 NETWORK_PROFILER_SOCKET_CLIENT
17 #define NETWORK_PROFILER_SOCKET_CLIENT
18 
19 #include "service_base.h"
20 #include "network_profiler_write.h"
21 #include "unix_socket_client.h"
22 
23 namespace OHOS::Developtools::Profiler {
24 class NetworkProfiler;
25 class NetworkProfilerSocketClient : public ServiceBase {
26 public:
27     NetworkProfilerSocketClient(int pid, NetworkProfiler* profiler, void (*disableHookCallback)());
28     ~NetworkProfilerSocketClient();
29     bool Connect(const std::string addrname, void (*disableHookCallback)());
30     bool ProtocolProc(SocketContext &context, uint32_t pnum, const int8_t *buf, const uint32_t size) override;
GetSmbFd()31     int GetSmbFd()
32     {
33         return smbFd_;
34     }
GetEventFd()35     int GetEventFd()
36     {
37         return eventFd_;
38     }
39     void Flush();
40     bool SendNetworkProfilerData(const void* data, size_t size, const void* payload, size_t payloadSize);
41     void DisableHook();
42     bool PeerIsConnected();
ClientConnectState()43     bool ClientConnectState()
44     {
45         return unixSocketClient_ == nullptr ? false : true;
46     }
Reset()47     void Reset()
48     {
49         writer_ = nullptr;
50     }
51 
52 private:
53     std::shared_ptr<UnixSocketClient> unixSocketClient_{nullptr};
54     int smbFd_{0};
55     int eventFd_{0};
56     int pid_{0};
57     std::shared_ptr<NetworkProfilerWriter> writer_{nullptr};
58     void (*disableHookCallback_)(){nullptr};
59     uint32_t flushInterval_{0};
60     NetworkProfiler* profiler_{nullptr};
61 };
62 } // namespace OHOS::Developtools::Profiler
63 
64 #endif // NETWORK_PROFILER_SOCKET_CLIENT