FastUIDraw
api_callback.hpp
Go to the documentation of this file.
1 /*!
2  * \file api_callback.hpp
3  * \brief file api_callback.hpp
4  *
5  * Copyright 2017 by Intel.
6  *
7  * Contact: kevin.rogovin@gmail.com
8  *
9  * This Source Code Form is subject to the
10  * terms of the Mozilla Public License, v. 2.0.
11  * If a copy of the MPL was not distributed with
12  * this file, You can obtain one at
13  * http://mozilla.org/MPL/2.0/.
14  *
15  * \author Kevin Rogovin <kevin.rogovin@gmail.com>
16  *
17  */
18 
19 #ifndef FASTUIDRAW_API_CALLBACK_HPP
20 #define FASTUIDRAW_API_CALLBACK_HPP
21 
22 #include <fastuidraw/util/util.hpp>
24 
25 namespace fastuidraw
26 {
27  /*!
28  * An APICallbackSet represents a collection of functors
29  * to be called before and after each function call from
30  * a collection of functions. This class is used by the
31  * fastuidraw::gl_binding and can be reused for other
32  * 3D API's (by definding a macro for each 3D API function
33  * that pre-calls to APICallbackSet::pre_call() and post-
34  * calls to APICallbackSet::post_call() around each 3D
35  * API function call.
36  */
38  {
39  public:
40  /*!
41  * A Callback is a functor to be called before
42  * and after each function.
43  */
44  class CallBack:public reference_counted<CallBack>::concurrent
45  {
46  public:
47  /*!
48  * Ctor
49  * \param parent APICallbackSet on which to attach the object
50  */
51  explicit
52  CallBack(APICallbackSet *parent);
53 
54  virtual
55  ~CallBack();
56 
57  /*!
58  * Set if the CallBack is active.
59  */
60  void
61  active(bool b);
62 
63  /*!
64  * Returns true if and only if the CallBack is active
65  */
66  bool
67  active(void) const;
68 
69  /*!
70  * To be implemented by a derived class to record
71  * just before a call.
72  * \param call_string_values string showing call's values
73  * \param call_string_src string showing function call as it appears in source
74  * \param function_name name of function called
75  * \param function_ptr pointer to function originating the call
76  * \param src_file file of orignating call
77  * \param src_line line number of orignating call
78  */
79  virtual
80  void
81  pre_call(c_string call_string_values,
82  c_string call_string_src,
83  c_string function_name,
84  void *function_ptr,
85  c_string src_file, int src_line) = 0;
86 
87  /*!
88  * To be implemented by a derived class to record
89  * just after a GL call.
90  * \param call_string_values string showing call's values
91  * \param call_string_src string showing function call as it appears in source
92  * \param function_name name of function called
93  * \param error_string error string generated
94  * \param function_ptr pointer to function originating the call
95  * \param src_file file of orignating call
96  * \param src_line line number of orignating call
97  */
98  virtual
99  void
100  post_call(c_string call_string_values,
101  c_string call_string_src,
102  c_string function_name,
103  c_string error_string,
104  void *function_ptr,
105  c_string src_file, int src_line) = 0;
106 
107  /*!
108  * To be implemented by a derived class; called when a message
109  * is emitted.
110  * \param message message emitted.
111  * \param src_file file of orignating message
112  * \param src_line line number of orignating message
113  */
114  virtual
115  void
116  message(c_string message, c_string src_file, int src_line) = 0;
117 
118  /*!
119  * To be optionally implemented by a derived class; called
120  * when a function cannot be loaded/found.
121  * \param function_name name of function that could not be loaded/found
122  */
123  virtual
124  void
126  {
127  FASTUIDRAWunused(function_name);
128  }
129 
130  private:
131  void *m_d;
132  };
133 
134  /*!
135  * Ctor.
136  * \param label label with which to identify the APICallbackSet,
137  * string is copied.
138  */
139  explicit
141 
142  virtual
143  ~APICallbackSet();
144 
145  /*!
146  * Return the label passed in the ctor.
147  */
148  c_string
149  label(void) const;
150 
151  /*!
152  * Sets the function that the system uses
153  * to fetch the function pointers.
154  * \param get_proc value to use, default is nullptr.
155  */
156  void
158 
159  /*!
160  * Sets the function that the system uses
161  * to fetch the function pointers.
162  * \param datum client data pointer passed to function
163  * \param get_proc value to use, default is nullptr.
164  */
165  void
166  get_proc_function(void *datum,
167  void* (*get_proc)(void*, c_string));
168 
169  /*!
170  * Fetches a function using the function fetcher
171  * passed to get_proc_function().
172  * \param function name of function to fetch
173  */
174  void*
175  get_proc(c_string function);
176 
177  /*!
178  * To be called by an implementation before issuing a function
179  * call.
180  */
181  void
182  pre_call(c_string call_string_values,
183  c_string call_string_src,
184  c_string function_name,
185  void *function_ptr,
186  c_string src_file, int src_line);
187 
188  /*!
189  * To be called by an impementation after issuing a function
190  * call.
191  */
192  void
193  post_call(c_string call_string_values,
194  c_string call_string_src,
195  c_string function_name,
196  c_string error_string,
197  void *function_ptr,
198  c_string src_file, int src_line);
199 
200  /*!
201  * To be called by an implementation when attempting to
202  * call a function whose function pointer is null
203  */
204  void
206 
207  /*!
208  * To be called by an implementation to emit a
209  * message to each of the callbacks.
210  */
211  void
212  message(c_string message, c_string src_file, int src_line);
213 
214  private:
215  void *m_d;
216  };
217 }
218 
219 #endif
virtual void on_call_unloadable_function(c_string function_name)
all classes and functions of FastUIDraw are in the namespace fastuidraw.
Definition: colorstop.hpp:28
void get_proc_function(void *(*get_proc)(c_string))
virtual void post_call(c_string call_string_values, c_string call_string_src, c_string function_name, c_string error_string, void *function_ptr, c_string src_file, int src_line)=0
#define FASTUIDRAWunused(X)
Definition: util.hpp:84
APICallbackSet(c_string label)
void call_unloadable_function(c_string fname)
file util.hpp
Defines default reference counting base classes.
const char * c_string
Conveniant typedef for C-style strings.
Definition: util.hpp:135
virtual void pre_call(c_string call_string_values, c_string call_string_src, c_string function_name, void *function_ptr, c_string src_file, int src_line)=0
Class for which copy ctor and assignment operator are private functions.
Definition: util.hpp:505
CallBack(APICallbackSet *parent)
c_string label(void) const
void * get_proc(c_string function)
virtual void message(c_string message, c_string src_file, int src_line)=0
file reference_counted.hpp