1 /* 2 * Copyright 2005, Ingo Weinhold, bonefish@users.sf.net. 3 * Distributed under the terms of the MIT License. 4 */ 5 #ifndef STRACE_SYSCALL_H 6 #define STRACE_SYSCALL_H 7 8 #include <string> 9 #include <vector> 10 11 #include <SupportDefs.h> 12 13 #include "TypeHandler.h" 14 15 using std::string; 16 using std::vector; 17 18 // Type 19 class Type { 20 public: 21 Type(string typeName, TypeHandler *handler) 22 : fTypeName(typeName), fHandler(handler) {} 23 24 const string &TypeName() const { return fTypeName; } 25 26 void SetHandler(TypeHandler *handler) 27 { 28 delete fHandler; 29 fHandler = handler; 30 } 31 32 TypeHandler *Handler() const { return fHandler; } 33 34 private: 35 string fTypeName; 36 TypeHandler *fHandler; 37 }; 38 39 // Parameter 40 class Parameter : public Type { 41 public: 42 Parameter(string name, int32 offset, string typeName, TypeHandler *handler) 43 : Type(typeName, handler), 44 fName(name), 45 fOffset(offset), 46 fInOut(false), 47 fOut(false) 48 { 49 } 50 51 const string &Name() const { return fName; } 52 int32 Offset() const { return fOffset; } 53 bool InOut() const { return fInOut; } 54 void SetInOut(bool inout) { fInOut = inout; } 55 bool Out() const { return fOut; } 56 void SetOut(bool out) { fOut = out; } 57 58 private: 59 string fName; 60 int32 fOffset; 61 bool fInOut; 62 bool fOut; 63 }; 64 65 // Syscall 66 class Syscall { 67 public: 68 Syscall(string name, string returnTypeName, TypeHandler *returnTypeHandler) 69 : fName(name), 70 fReturnType(new Type(returnTypeName, returnTypeHandler)), 71 fTracingEnabled(false) 72 { 73 } 74 75 const string &Name() const 76 { 77 return fName; 78 } 79 80 Type *ReturnType() const 81 { 82 return fReturnType; 83 } 84 85 void AddParameter(Parameter *parameter) 86 { 87 fParameters.push_back(parameter); 88 } 89 90 void AddParameter(string name, int32 offset, string typeName, 91 TypeHandler *handler) 92 { 93 AddParameter(new Parameter(name, offset, typeName, handler)); 94 } 95 96 int32 CountParameters() const 97 { 98 return fParameters.size(); 99 } 100 101 Parameter *ParameterAt(int32 index) const 102 { 103 return fParameters[index]; 104 } 105 106 Parameter *GetParameter(string name) const 107 { 108 int32 count = CountParameters(); 109 for (int32 i = 0; i < count; i++) { 110 Parameter *parameter = ParameterAt(i); 111 if (parameter->Name() == name) 112 return parameter; 113 } 114 115 return NULL; 116 } 117 118 bool TracingEnabled() const 119 { 120 return fTracingEnabled; 121 } 122 123 void EnableTracing(bool enable) 124 { 125 fTracingEnabled = enable; 126 } 127 128 private: 129 string fName; 130 Type *fReturnType; 131 vector<Parameter*> fParameters; 132 bool fTracingEnabled; 133 }; 134 135 #endif // STRACE_SYSCALL_H 136