| 1 | {{{ |
| 2 | #!rst |
| 3 | |
| 4 | ========================================================================= |
| 5 | RFC 37: User data callbacks in CPLError |
| 6 | ========================================================================= |
| 7 | |
| 8 | :Date: 2011/10/25 |
| 9 | :Author: Howard Butler |
| 10 | :Contact: hobu.inc at gmail dot com |
| 11 | :Status: Proposed |
| 12 | :Version: GDAL 1.9 |
| 13 | |
| 14 | |
| 15 | Description: This RFC proposes to implement user context data in |
| 16 | CPLErrorHandler callback functions. It does so without disrupting existing |
| 17 | callback patterns already in use, and provides completely auxiliary |
| 18 | functionality to CPLErrorHandler. |
| 19 | |
| 20 | Rationale |
| 21 | ------------------------------------------------------------------------------ |
| 22 | |
| 23 | It could be argued that users could already manage user context of error |
| 24 | handling functions with application-level globals that control its |
| 25 | interaction. While this sentiment is technically true, this approach adds a |
| 26 | ton of complication for library users. A scenario that has error callbacks |
| 27 | pass back user context data means simpler code for users wishing to have the |
| 28 | state of their application be returned along with errors from inside of GDAL. |
| 29 | |
| 30 | The case for user data be passed in callbacks: |
| 31 | |
| 32 | * It is a common idiom for signal-based APIs (of which CPLErrorHandler is one) |
| 33 | * It is simpler than requiring library users to manage the state of internal |
| 34 | library error handling externally in their own applications |
| 35 | |
| 36 | |
| 37 | Implementation Concerns |
| 38 | ------------------------------------------------------------------------------ |
| 39 | |
| 40 | GDAL's (and OGR and OSR's) error handling callback mechanisms are in wide use |
| 41 | and changes to the base library that were to break either the callback |
| 42 | signatures *or* the behavior of existing callback operations should be |
| 43 | rejected. Adding support for user data in the call back is to be provided |
| 44 | in addition to existing functionality that already exists in the error |
| 45 | handling, and an approach that mimics and looks similar to the existing |
| 46 | operations is likely the best approach for GDAL -- if not the cleanest |
| 47 | approach in general. |
| 48 | |
| 49 | Planned Changes |
| 50 | ------------------------------------------------------------------------------ |
| 51 | |
| 52 | The first change will add a void* to CPLErrorHandlerNode: |
| 53 | |
| 54 | :: |
| 55 | |
| 56 | typedef struct errHandler |
| 57 | { |
| 58 | struct errHandler *psNext; |
| 59 | void *pUserData; |
| 60 | CPLErrorHandler pfnHandler; |
| 61 | } CPLErrorHandlerNode; |
| 62 | |
| 63 | and to methods to add error handlers with user data will be provided: |
| 64 | |
| 65 | :: |
| 66 | |
| 67 | CPLErrorHandler CPL_DLL CPL_STDCALL CPLSetErrorHandlerEx(CPLErrorHandler, void*); |
| 68 | void CPL_DLL CPL_STDCALL CPLPushErrorHandlerEx( CPLErrorHandler, void* ); |
| 69 | |
| 70 | ``CPLSetErrorHandler`` and ``CPLPushErrorHandler`` will simply use the ``Ex`` |
| 71 | functions and pass NULL in for the pUserData member. |
| 72 | |
| 73 | Finally, similar to ``CPLGetLastErrorType`` and ``CPLGetLastErrorMsg`` methods, |
| 74 | a ``CPLGetLastErrorUserData`` |
| 75 | |
| 76 | :: |
| 77 | |
| 78 | void* CPL_STDCALL CPLGetLastErrorUserData(void); |
| 79 | |
| 80 | Ticket History |
| 81 | ------------------------------------------------------------------------------ |
| 82 | |
| 83 | `#4295`:trac: contains a patch that implements the proposed solution and |
| 84 | provides context and discussion about this feature. http://trac.osgeo.org/gdal/attachment/ticket/4295/4295-hobu-rfc.patch |
| 85 | contains the current patch to implemented the proposed functionality. |
| 86 | |
| 87 | Documentation |
| 88 | ------------------------------------------------------------------------------ |
| 89 | |
| 90 | Documentation of the added functions is provided as part of the patch. |
| 91 | |
| 92 | Implementation |
| 93 | ------------------------------------------------------------------------------ |
| 94 | |
| 95 | All code will be implemented in trunk by Howard Butler after passage of the |
| 96 | RFC. |
| 97 | |
| 98 | |
| 99 | |
| 100 | }}} |