• 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 FOUNDATION_APPEXECFWK_SERVICES_APPMGR_INCLUDE_LMKS_SERVER_H
17 #define FOUNDATION_APPEXECFWK_SERVICES_APPMGR_INCLUDE_LMKS_SERVER_H
18 
19 #include <string>
20 #include <sys/un.h>
21 
22 #include "lmks_utils.h"
23 
24 namespace OHOS {
25 namespace LMKS {
26 constexpr uint32_t MAX_LMKS_TARGETS = 6;  // max number of lmks command targets
27 constexpr uint32_t MAX_LMKS_TARGETS_SIZE = sizeof(int) * (MAX_LMKS_TARGETS * 2 + 1);  // max packet length
28 
29 using LMKS_PACKET = int[MAX_LMKS_TARGETS_SIZE / sizeof(int)];
30 
31 class LmksServer {
32 public:
33     LmksServer();
34     virtual ~LmksServer();
35 
36     void StartServer();
37 
38 private:
39     int RegisterSocket();
40     int WaitConnection();
41     int RecvSocketMessage(int connectFd, void *buf, int len);
42     int SendSocketMessage(int connectFd, const void *buf, int len);
43     void ProcessMessage(int connectFd, LMKS_PACKET cmds, int len);
44     void CloseSocket();
45 
46 private:
47     bool isStart_;
48     int socketFd_;
49     struct sockaddr_un socketAddr_;
50     uint32_t socketAddrLen_;
51     std::shared_ptr<LmksUtils> lmksUtils_;
52 };
53 }  // namespace LMKS
54 }  // namespace OHOS
55 
56 #endif  // FOUNDATION_APPEXECFWK_SERVICES_APPMGR_INCLUDE_LMKS_SERVER_H
57