2 * Copyright 2005-2007, Haiku Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
6 * Ingo Weinhold <bonefish@cs.tu-berlin.de>
7 * Hugo Santos <hugosantos@gmail.com>
9 #ifndef STRACE_TYPE_HANDLER_H
10 #define STRACE_TYPE_HANDLER_H
15 #include <arch_config.h>
16 #include <SupportDefs.h>
24 typedef FUNCTION_CALL_PARAMETER_ALIGNMENT_TYPE align_t
;
30 virtual ~TypeHandler() {}
32 virtual string
GetParameterValue(Context
&, Parameter
*,
33 const void *value
) = 0;
34 virtual string
GetReturnValue(Context
&, uint64 value
) = 0;
37 class EnumTypeHandler
: public TypeHandler
{
39 typedef std::map
<int, const char *> EnumMap
;
41 EnumTypeHandler(const EnumMap
&);
43 string
GetParameterValue(Context
&c
, Parameter
*, const void *);
44 string
GetReturnValue(Context
&, uint64 value
);
47 string
RenderValue(Context
&, unsigned int value
) const;
52 // currently limited to select ints
53 class TypeHandlerSelector
: public TypeHandler
{
55 typedef std::map
<int, TypeHandler
*> SelectMap
;
57 TypeHandlerSelector(const SelectMap
&, int sibling
,
60 string
GetParameterValue(Context
&, Parameter
*, const void *);
61 string
GetReturnValue(Context
&, uint64 value
);
64 const SelectMap
&fMap
;
66 TypeHandler
*fDefault
;
69 // templatized TypeHandler factory class
70 // (I tried a simple function first, but then the compiler complains for
71 // the partial instantiation. Not sure, if I'm missing something or this is
73 template<typename Type
>
74 struct TypeHandlerFactory
{
75 static TypeHandler
*Create();
78 extern TypeHandler
*create_pointer_type_handler();
79 extern TypeHandler
*create_string_type_handler();
81 // specialization for "const char*"
83 struct TypeHandlerFactory
<const char*> {
84 static inline TypeHandler
*Create()
86 return create_string_type_handler();
90 #define DEFINE_FACTORY(name, type) \
92 struct TypeHandlerFactory<type> { \
93 static inline TypeHandler *Create() \
95 extern TypeHandler *create_##name##_type_handler(); \
96 return create_##name##_type_handler(); \
104 struct sockaddr_args
;
108 DEFINE_FACTORY(fdset_ptr
, fd_set
*);
109 DEFINE_FACTORY(ifconf_ptr
, ifconf
*);
110 DEFINE_FACTORY(ifreq_ptr
, ifreq
*);
111 DEFINE_FACTORY(message_args_ptr
, message_args
*);
112 DEFINE_FACTORY(sockaddr_args_ptr
, sockaddr_args
*);
113 DEFINE_FACTORY(socket_args_ptr
, socket_args
*);
114 DEFINE_FACTORY(sockopt_args_ptr
, sockopt_args
*);
116 DEFINE_FACTORY(int_ptr
, int *);
117 DEFINE_FACTORY(long_ptr
, long *);
118 DEFINE_FACTORY(longlong_ptr
, long long *);
119 DEFINE_FACTORY(uint_ptr
, unsigned int *);
120 DEFINE_FACTORY(ulong_ptr
, unsigned long *);
121 DEFINE_FACTORY(ulonglong_ptr
, unsigned long long *);
123 // partial specialization for generic pointers
124 template<typename Type
>
125 struct TypeHandlerFactory
<Type
*> {
126 static inline TypeHandler
*Create()
128 return create_pointer_type_handler();
132 template<typename Type
>
133 class TypeHandlerImpl
: public TypeHandler
{
135 string
GetParameterValue(Context
&, Parameter
*, const void *);
136 string
GetReturnValue(Context
&, uint64 value
);
139 #endif // STRACE_TYPE_HANDLER_H