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 IPC_GENERATOR_IMPL_H 17 #define IPC_GENERATOR_IMPL_H 18 19 #include <map> 20 #include <ostream> 21 22 class IpcServices { 23 public: IpcServices()24 IpcServices() 25 { 26 methodCount_ = 0; 27 } ~IpcServices()28 ~IpcServices() {} 29 std::string serviceName_; 30 std::map<int, std::string> methodList_; 31 std::map<int, std::string> requestList_; 32 std::map<int, std::string> responseList_; 33 int methodCount_; AddMethod(std::string method,std::string request,std::string response)34 bool AddMethod(std::string method, std::string request, std::string response) 35 { 36 for (int i = 0; i < methodCount_; i++) { 37 if (methodList_[i] == method) { 38 return false; 39 } 40 } 41 methodList_[methodCount_] = method; 42 requestList_[methodCount_] = request; 43 responseList_[methodCount_] = response; 44 methodCount_++; 45 return true; 46 } 47 }; 48 49 class IpcGeneratorImpl { 50 public: 51 IpcGeneratorImpl(); 52 ~IpcGeneratorImpl(); 53 54 std::string SetNames(std::string fileName, std::string packageName); 55 bool AddService(std::string serviceName); 56 bool AddServiceMethod(std::string serviceName, 57 std::string methodName, 58 std::string requestName, 59 std::string responseName); 60 61 std::string GenHeader(); 62 std::string GenSource(); 63 64 private: 65 std::string fileName_ = ""; 66 std::string baseName_ = ""; 67 std::string packageName_ = ""; 68 std::string headFileName_ = ""; 69 70 void GenerateHeader(std::string& header_str); 71 72 std::string GenSendResponseImpl(int servicep, const std::string& server_class_name); 73 std::string GenOnResponseImpl(int servicep, const std::string& client_class_name); 74 75 std::string GenServiceCallImpl(int servicep, const std::string& server_class_name); 76 std::string GenClientProcImpl(int servicep); 77 std::string GenClientRequestImpl(int servicep, const std::string& client_class_name); 78 std::string GenServiceProcImpl(int servicep); 79 80 std::map<int, IpcServices> serviceList_; 81 int serviceCount_ = 0; 82 83 std::map<int, std::string> enumMessageDict_; 84 }; 85 86 #endif