• 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 SERVICE_ENTRY_H
17 #define SERVICE_ENTRY_H
18 
19 #include <cstdint>
20 #include <map>
21 #include "service_base.h"
22 
23 static const uint32_t PROTOCOL_TYPE_FILTER = 0xF0000000;
24 
25 enum ProtocolType {
26     PROTOCOL_TYPE_RAW = 0,
27     PROTOCOL_TYPE_PROTOBUF = 0x10000000,
28 };
29 
30 struct ProtocolHead {
31     uint32_t protoType;
32     uint32_t protoSize;
33     int8_t datas[0];
34 };
35 
36 class UnixSocketServer;
37 
38 class ServiceEntry {
39 public:
40     ServiceEntry();
41     ~ServiceEntry();
42 
43     bool StartServer(const std::string& addrname);
44 
45     bool RegisterService(ServiceBase& psb);
46 
47     const ServiceBase* FindServiceByName(const std::string& service_name);
48 
49 private:
50     std::shared_ptr<UnixSocketServer> unixSocketServer_;
51 
52     std::map<std::string, ServiceBase*> serviceMap_;
53 };
54 
55 uint64_t GetTimeMS();
56 uint64_t GetTimeUS();
57 uint64_t GetTimeNS();
58 
59 #endif