• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 : public 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         }
58         return retval;
59     }
60 
clientContextHeaders()61     StringVec & clientContextHeaders() { return m_clientContextHeaders; }
encoderHeaders()62     StringVec & encoderHeaders() { return m_encoderHeaders; }
serverContextHeaders()63     StringVec & serverContextHeaders() { return m_serverContextHeaders; }
decoderHeaders()64     StringVec & decoderHeaders() { return m_decoderHeaders; }
65 
66     EntryPoint * findEntryByName(const std::string & name);
67     int genOpcodes(const std::string &filename);
68     int genAttributesTemplate(const std::string &filename);
69     int genProcTypes(const std::string &filename, SideType side);
70     int genFuncTable(const std::string &filename, SideType side);
71 
72     int genContext(const std::string &filename, SideType side);
73     int genContextImpl(const std::string &filename, SideType side);
74 
75     int genEntryPoints(const std::string &filename, SideType side);
76 
77     int genEncoderHeader(const std::string &filename);
78     int genEncoderImpl(const std::string &filename);
79 
80     int genDecoderHeader(const std::string &filename);
81     int genDecoderImpl(const std::string &filename);
82 
83 protected:
84     virtual void printHeader(FILE *fp) const;
85     std::string m_basename;
86     StringVec m_clientContextHeaders;
87     StringVec m_encoderHeaders;
88     StringVec m_serverContextHeaders;
89     StringVec m_decoderHeaders;
90     size_t m_maxEntryPointsParams; // record the maximum number of parameters in the entry points;
91     int m_baseOpcode;
92     int setGlobalAttribute(const std::string & line, size_t lc);
93 };
94 
95 #endif
96