• 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 __VAR__H__
17 #define __VAR__H__
18 
19 #include "VarType.h"
20 #include <string>
21 #include <stdio.h>
22 
23 class Var {
24 public:
25     // pointer data direction - from the client point of view.
26     typedef enum { POINTER_OUT = 0x1, POINTER_IN = 0x2, POINTER_INOUT = 0x3 } PointerDir;
27     Var() = default;
28 
Var(const std::string & name,const VarType * vartype,const std::string & lenExpression,PointerDir dir,const std::string & packExpression,const std::string & unpackExpression,const std::string & writeExpression)29     Var(const std::string & name,
30         const VarType * vartype,
31         const std::string & lenExpression,
32         PointerDir dir,
33         const std::string &packExpression,
34         const std::string &unpackExpression,
35         const std::string &writeExpression) :
36         m_name(name),
37         m_type(const_cast<VarType *>(vartype)),
38         m_lenExpression(lenExpression),
39         m_pointerDir(dir),
40         m_packExpression(packExpression),
41         m_unpackExpression(unpackExpression),
42         m_host_packTmpAllocExpression(""),
43         m_host_packExpression(""),
44         m_guest_unpackExpression(""),
45         m_guest_packExpression(""),
46         m_writeExpression(writeExpression)
47     {
48     }
49 
init(const std::string name,const VarType * vartype,std::string lenExpression,PointerDir dir,std::string packExpression,std::string unpackExpression,std::string writeExpression)50     void init(const std::string name, const VarType * vartype,
51               std::string lenExpression,
52               PointerDir dir,
53               std::string packExpression,
54               std::string unpackExpression,
55               std::string writeExpression) {
56         m_name = name;
57         m_type = vartype;
58         m_lenExpression = lenExpression;
59         m_packExpression = packExpression;
60         m_unpackExpression = unpackExpression;
61         m_host_packTmpAllocExpression = "";
62         m_host_packExpression = "";
63         m_guest_unpackExpression = "";
64         m_guest_packExpression = "";
65         m_writeExpression = writeExpression;
66         m_pointerDir = dir;
67         m_nullAllowed = false;
68         m_isLarge = false;
69 
70     }
71 
name()72     const std::string & name() const { return m_name; }
type()73     const VarType * type() const { return m_type; }
isPointer()74     bool isPointer() const { return m_type->isPointer(); }
isVoid()75     bool isVoid() const { return ((m_type->bytes() == 0) && (!m_type->isPointer())); }
lenExpression()76     const std::string & lenExpression() const { return m_lenExpression; }
packExpression()77     const std::string & packExpression() const { return(m_packExpression); }
unpackExpression()78     const std::string & unpackExpression() const { return(m_unpackExpression); }
hostPackTmpAllocExpression()79     const std::string & hostPackTmpAllocExpression() const { return(m_host_packTmpAllocExpression); }
hostPackExpression()80     const std::string & hostPackExpression() const { return(m_host_packExpression); }
guestUnpackExpression()81     const std::string & guestUnpackExpression() const { return(m_guest_unpackExpression); }
guestPackExpression()82     const std::string & guestPackExpression() const { return(m_guest_packExpression); }
writeExpression()83     const std::string & writeExpression() const { return(m_writeExpression); }
paramCheckExpression()84     const std::string & paramCheckExpression() const { return m_paramCheckExpression; }
setLenExpression(const std::string & lenExpression)85     void setLenExpression(const std::string & lenExpression) { m_lenExpression = lenExpression; }
setPackExpression(const std::string & packExpression)86     void setPackExpression(const std::string & packExpression) { m_packExpression = packExpression; }
setUnpackExpression(const std::string & unpackExpression)87     void setUnpackExpression(const std::string & unpackExpression) { m_unpackExpression = unpackExpression; }
setHostPackTmpAllocExpression(const std::string & expr)88     void setHostPackTmpAllocExpression(const std::string & expr) { m_host_packTmpAllocExpression = expr; }
setHostPackExpression(const std::string & expr)89     void setHostPackExpression(const std::string & expr) { m_host_packExpression = expr; }
setGuestUnpackExpression(const std::string & expr)90     void setGuestUnpackExpression(const std::string & expr) { m_guest_unpackExpression = expr; }
setGuestPackExpression(const std::string & expr)91     void setGuestPackExpression(const std::string & expr) { m_guest_packExpression = expr; }
setWriteExpression(const std::string & writeExpression)92     void setWriteExpression(const std::string & writeExpression) { m_writeExpression = writeExpression; }
setParamCheckExpression(const std::string & paramCheckExpression)93     void setParamCheckExpression(const std::string & paramCheckExpression) { m_paramCheckExpression = paramCheckExpression; }
setPointerDir(PointerDir dir)94     void setPointerDir(PointerDir dir) { m_pointerDir = dir; }
pointerDir()95     PointerDir pointerDir() { return m_pointerDir; }
setNullAllowed(bool state)96     void setNullAllowed(bool state) { m_nullAllowed = state; }
setIsLarge(bool state)97     void setIsLarge(bool state) { m_isLarge = state; }
setDMA(bool state)98     void setDMA(bool state) { m_isDMA = state; }
nullAllowed()99     bool nullAllowed() const { return m_nullAllowed; }
isLarge()100     bool isLarge() const { return m_isLarge; }
isDMA()101     bool isDMA() const { return m_isDMA; }
printType(FILE * fp)102     void printType(FILE *fp) { fprintf(fp, "%s", m_type->name().c_str()); }
printTypeName(FILE * fp)103     void printTypeName(FILE *fp) { printType(fp); fprintf(fp, " %s", m_name.c_str()); }
104 
105 private:
106     std::string m_name;
107     const VarType * m_type = nullptr;
108     std::string m_lenExpression; // an expression to calcualte a pointer data size
109     PointerDir m_pointerDir = POINTER_IN;
110     bool m_nullAllowed = false;
111     bool m_isLarge = false;
112     bool m_isDMA = false;
113     std::string m_packExpression; // an expression to pack data into the stream
114     std::string m_unpackExpression; // an expression to unpack data that has arrived from the stream
115     std::string m_host_packTmpAllocExpression; // an expression to create temporaries for getting into packed form for readbacks
116     std::string m_host_packExpression; // an expression to pack data into the stream but for readbacks
117     std::string m_guest_unpackExpression; // an expression to unpack readbacks on the guest
118     std::string m_guest_packExpression; // an expression to pack large buffer writes on the guest
119     std::string m_writeExpression; // an expression to write data into the stream
120     std::string m_paramCheckExpression; //an expression to check parameter value
121 };
122 
123 #endif
124