You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

113 lines
4.3 KiB

  1. /* Jim - A small embeddable Tcl interpreter
  2. *
  3. * Copyright 2005 Salvatore Sanfilippo <antirez@invece.org>
  4. * Copyright 2005 Clemens Hintze <c.hintze@gmx.net>
  5. * Copyright 2005 patthoyts - Pat Thoyts <patthoyts@users.sf.net>
  6. * Copyright 2008 oharboe - Øyvind Harboe - oyvind.harboe@zylin.com
  7. * Copyright 2008 Andrew Lunn <andrew@lunn.ch>
  8. * Copyright 2008 Duane Ellis <openocd@duaneellis.com>
  9. * Copyright 2008 Uwe Klein <uklein@klein-messgeraete.de>
  10. *
  11. * The FreeBSD license
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions
  15. * are met:
  16. *
  17. * 1. Redistributions of source code must retain the above copyright
  18. * notice, this list of conditions and the following disclaimer.
  19. * 2. Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials
  22. * provided with the distribution.
  23. *
  24. * THIS SOFTWARE IS PROVIDED BY THE JIM TCL PROJECT ``AS IS'' AND ANY
  25. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
  26. * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
  27. * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  28. * JIM TCL PROJECT OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  29. * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  30. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  31. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  32. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  33. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  34. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  35. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  36. *
  37. * The views and conclusions contained in the software and documentation
  38. * are those of the authors and should not be interpreted as representing
  39. * official policies, either expressed or implied, of the Jim Tcl Project.
  40. **/
  41. /* ------ USAGE -------
  42. *
  43. * In order to use this file from other extensions include it in every
  44. * file where you need to call the eventloop API, also in the init
  45. * function of your extension call Jim_ImportEventloopAPI(interp)
  46. * after the Jim_InitExtension() call.
  47. *
  48. * See the UDP extension as example.
  49. */
  50. #ifndef __JIM_EVENTLOOP_H__
  51. #define __JIM_EVENTLOOP_H__
  52. typedef int Jim_FileProc(Jim_Interp *interp, void *clientData, int mask);
  53. typedef int Jim_SignalProc(Jim_Interp *interp, void *clientData, void *msg);
  54. typedef void Jim_TimeProc(Jim_Interp *interp, void *clientData);
  55. typedef void Jim_EventFinalizerProc(Jim_Interp *interp, void *clientData);
  56. /* File event structure */
  57. #define JIM_EVENT_READABLE 1
  58. #define JIM_EVENT_WRITABLE 2
  59. #define JIM_EVENT_EXCEPTION 4
  60. #define JIM_EVENT_FEOF 8
  61. #define JIM_API(x) x
  62. #define JIM_STATIC
  63. JIM_STATIC int Jim_EventLoopOnLoad(Jim_Interp *interp);
  64. /* --- POSIX version of Jim_ProcessEvents, for now the only available --- */
  65. #define JIM_FILE_EVENTS 1
  66. #define JIM_TIME_EVENTS 2
  67. #define JIM_ALL_EVENTS (JIM_FILE_EVENTS|JIM_TIME_EVENTS)
  68. #define JIM_DONT_WAIT 4
  69. JIM_STATIC void JIM_API(Jim_CreateFileHandler) (Jim_Interp *interp,
  70. void *handle, int mask,
  71. Jim_FileProc *proc, void *clientData,
  72. Jim_EventFinalizerProc *finalizerProc);
  73. JIM_STATIC void JIM_API(Jim_DeleteFileHandler) (Jim_Interp *interp,
  74. void *handle);
  75. JIM_STATIC jim_wide JIM_API(Jim_CreateTimeHandler) (Jim_Interp *interp,
  76. jim_wide milliseconds,
  77. Jim_TimeProc *proc, void *clientData,
  78. Jim_EventFinalizerProc *finalizerProc);
  79. JIM_STATIC jim_wide JIM_API(Jim_DeleteTimeHandler) (Jim_Interp *interp, jim_wide id);
  80. JIM_STATIC int JIM_API(Jim_ProcessEvents) (Jim_Interp *interp, int flags);
  81. #undef JIM_STATIC
  82. #undef JIM_API
  83. #ifndef __JIM_EVENTLOOP_CORE__
  84. #define JIM_GET_API(name) \
  85. Jim_GetApi(interp, "Jim_" #name, ((void *)&Jim_ ## name))
  86. #if defined(JIM_EXTENSION) || defined(JIM_EMBEDDED)
  87. /* This must be included "inline" inside the extension */
  88. static void Jim_ImportEventloopAPI(Jim_Interp *interp)
  89. {
  90. JIM_GET_API(CreateFileHandler);
  91. JIM_GET_API(DeleteFileHandler);
  92. JIM_GET_API(CreateTimeHandler);
  93. JIM_GET_API(DeleteTimeHandler);
  94. JIM_GET_API(ProcessEvents);
  95. }
  96. #endif /* defined JIM_EXTENSION || defined JIM_EMBEDDED */
  97. #undef JIM_GET_API
  98. #endif /* __JIM_EVENTLOOP_CORE__ */
  99. #endif /* __JIM_EVENTLOOP_H__ */