• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 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 STREAM_SERVER_H
17 #define STREAM_SERVER_H
18 
19 #include <mutex>
20 
21 #include "stream_session.h"
22 #include "stream_socket.h"
23 
24 namespace OHOS {
25 namespace Sensors {
26 class StreamServer : public StreamSocket {
27 public:
28     StreamServer() = default;
29     virtual ~StreamServer();
30     int32_t GetClientFd(int32_t pid);
31     int32_t GetClientPid(int32_t fd);
32     SessionPtr GetSession(int32_t fd);
33     SessionPtr GetSessionByPid(int32_t pid);
34     int32_t AddSocketPairInfo(int32_t uid, int32_t pid, int32_t tokenType, int32_t &serverFd, int32_t &clientFd);
35 
36 protected:
37     bool AddSession(SessionPtr sess);
38     void DelSession(int32_t pid);
39     std::mutex sessionMutex_;
40     std::map<int32_t, int32_t> idxPidMap_;
41     std::map<int32_t, SessionPtr> sessionsMap_;
42 };
43 } // namespace Sensors
44 } // namespace OHOS
45 #endif // STREAM_SERVER_H
46