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), fCount(1) {} 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 uint32 Count() const { return fCount; } 35 void SetCount(uint32 count) { fCount = count; } 36 37 private: 38 string fTypeName; 39 TypeHandler *fHandler; 40 uint32 fCount; 41 }; 42 43 // Parameter 44 class Parameter : public Type { 45 public: 46 Parameter(string name, int32 offset, string typeName, TypeHandler *handler) 47 : Type(typeName, handler), 48 fName(name), 49 fOffset(offset), 50 fInOut(false), 51 fOut(false) 52 { 53 } 54 55 const string &Name() const { return fName; } 56 int32 Offset() const { return fOffset; } 57 bool InOut() const { return fInOut; } 58 void SetInOut(bool inout) { fInOut = inout; } 59 bool Out() const { return fOut; } 60 void SetOut(bool out) { fOut = out; } 61 62 private: 63 string fName; 64 int32 fOffset; 65 bool fInOut; 66 bool fOut; 67 }; 68 69 // Syscall 70 class Syscall { 71 public: 72 Syscall(string name, string returnTypeName, TypeHandler *returnTypeHandler) 73 : fName(name), 74 fReturnType(new Type(returnTypeName, returnTypeHandler)), 75 fTracingEnabled(false) 76 { 77 } 78 79 const string &Name() const 80 { 81 return fName; 82 } 83 84 Type *ReturnType() const 85 { 86 return fReturnType; 87 } 88 89 void AddParameter(Parameter *parameter) 90 { 91 fParameters.push_back(parameter); 92 } 93 94 void AddParameter(string name, int32 offset, string typeName, 95 TypeHandler *handler) 96 { 97 AddParameter(new Parameter(name, offset, typeName, handler)); 98 } 99 100 int32 CountParameters() const 101 { 102 return fParameters.size(); 103 } 104 105 Parameter *ParameterAt(int32 index) const 106 { 107 return fParameters[index]; 108 } 109 110 Parameter *GetParameter(string name) const 111 { 112 int32 count = CountParameters(); 113 for (int32 i = 0; i < count; i++) { 114 Parameter *parameter = ParameterAt(i); 115 if (parameter->Name() == name) 116 return parameter; 117 } 118 119 return NULL; 120 } 121 122 bool TracingEnabled() const 123 { 124 return fTracingEnabled; 125 } 126 127 void EnableTracing(bool enable) 128 { 129 fTracingEnabled = enable; 130 } 131 132 private: 133 string fName; 134 Type *fReturnType; 135 vector<Parameter*> fParameters; 136 bool fTracingEnabled; 137 }; 138 139 #endif // STRACE_SYSCALL_H 140