1 /* 2 * Copyright (C) 2011 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #ifndef __API_GEN_H_ 17 #define __API_GEN_H_ 18 19 #include <vector> 20 #include <string.h> 21 #include "EntryPoint.h" 22 23 24 class ApiGen : private std::vector<EntryPoint> { 25 26 public: 27 typedef std::vector<std::string> StringVec; 28 typedef enum { CLIENT_SIDE, SERVER_SIDE, WRAPPER_SIDE } SideType; 29 ApiGen(const std::string & basename)30 ApiGen(const std::string & basename) : 31 m_basename(basename), 32 m_maxEntryPointsParams(0), 33 m_baseOpcode(0) 34 { } ~ApiGen()35 virtual ~ApiGen() {} 36 int readSpec(const std::string & filename); 37 int readAttributes(const std::string & attribFilename); maxEntryPointsParams()38 size_t maxEntryPointsParams() { return m_maxEntryPointsParams; } updateMaxEntryPointsParams(size_t val)39 void updateMaxEntryPointsParams(size_t val) { 40 if (m_maxEntryPointsParams == 0 || val > m_maxEntryPointsParams) m_maxEntryPointsParams = val; 41 } baseOpcode()42 int baseOpcode() { return m_baseOpcode; } setBaseOpcode(int base)43 void setBaseOpcode(int base) { m_baseOpcode = base; } 44 sideString(SideType side)45 const char *sideString(SideType side) { 46 const char *retval; 47 switch(side) { 48 case CLIENT_SIDE: 49 retval = "client"; 50 break; 51 case SERVER_SIDE: 52 retval = "server"; 53 break; 54 case WRAPPER_SIDE: 55 retval = "wrapper"; 56 break; 57 default: 58 retval = "unknown"; 59 } 60 return retval; 61 } 62 clientContextHeaders()63 StringVec & clientContextHeaders() { return m_clientContextHeaders; } encoderHeaders()64 StringVec & encoderHeaders() { return m_encoderHeaders; } serverContextHeaders()65 StringVec & serverContextHeaders() { return m_serverContextHeaders; } decoderHeaders()66 StringVec & decoderHeaders() { return m_decoderHeaders; } 67 68 EntryPoint * findEntryByName(const std::string & name); 69 int genOpcodes(const std::string &filename); 70 int genAttributesTemplate(const std::string &filename); 71 int genProcTypes(const std::string &filename, SideType side); 72 int genFuncTable(const std::string &filename, SideType side); 73 74 int genContext(const std::string &filename, SideType side); 75 int genContextImpl(const std::string &filename, SideType side); 76 77 int genEntryPoints(const std::string &filename, SideType side); 78 79 int genEncoderHeader(const std::string &filename); 80 int genEncoderImpl(const std::string &filename); 81 82 int genDecoderHeader(const std::string &filename); 83 int genDecoderImpl(const std::string &filename); 84 85 protected: 86 virtual void printHeader(FILE *fp) const; 87 std::string m_basename; 88 StringVec m_clientContextHeaders; 89 StringVec m_encoderHeaders; 90 StringVec m_serverContextHeaders; 91 StringVec m_decoderHeaders; 92 size_t m_maxEntryPointsParams; // record the maximum number of parameters in the entry points; 93 int m_baseOpcode; 94 int setGlobalAttribute(const std::string & line, size_t lc); 95 }; 96 97 #endif 98