Advertisement
christoph

lcm-python for win32

Feb 1st, 2012
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.32 KB | None | 0 0
  1. Index: lcm-python/module.c
  2. ===================================================================
  3. --- lcm-python/module.c (revision 638)
  4. +++ lcm-python/module.c (working copy)
  5. @@ -1,4 +1,5 @@
  6.  #include <Python.h>
  7. +#include "pylcm_subscription.h"
  8.  
  9.  //#define dbg(...) fprintf (stderr, __VA_ARGS__)
  10.  #define dbg(...)
  11. Index: lcm-python/pyeventlog.c
  12. ===================================================================
  13. --- lcm-python/pyeventlog.c (revision 638)
  14. +++ lcm-python/pyeventlog.c (working copy)
  15. @@ -1,6 +1,9 @@
  16.  #include <Python.h>
  17.  
  18.  #include <lcm/eventlog.h>
  19. +#ifdef WIN32
  20. +#include <WinPorting.h>
  21. +#endif
  22.  
  23.  typedef struct {
  24.      PyObject_HEAD
  25. @@ -13,7 +16,8 @@
  26.  "Event Log parser\n\
  27. ");
  28.  
  29. -PyTypeObject pylcmeventlog_type;
  30. +//gives redefinition error in MSVC
  31. +//PyTypeObject pylcmeventlog_type;
  32.  
  33.  static PyObject *
  34.  pylog_close (PyLogObject *self)
  35. @@ -134,14 +138,14 @@
  36.          return NULL;
  37.      }
  38.  
  39. -    lcm_eventlog_event_t le = {
  40. -        .eventnum = 0,
  41. -        .timestamp = utime,
  42. -        .channellen = channellen,
  43. -        .datalen = datalen,
  44. -        .channel = channel,
  45. -        .data = data
  46. -    };
  47. +    lcm_eventlog_event_t le; //msvc needs init of all fields seperately
  48. +    le.eventnum = 0;
  49. +    le.timestamp = utime;
  50. +    le.channellen = channellen;
  51. +    le.datalen = datalen;
  52. +    le.channel = channel;
  53. +    le.data = data;
  54. +    
  55.  
  56.      if (0 != lcm_eventlog_write_event (self->eventlog, &le)) {
  57.          PyErr_SetFromErrno (PyExc_IOError);
  58. @@ -194,14 +198,15 @@
  59.  static PyObject *
  60.  pylog_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
  61.  {
  62. -   PyObject *new;
  63. +   //msvc does not allow usage of new as variable name
  64. +   PyObject *newobj;
  65.  
  66. -   new = type->tp_alloc(type, 0);
  67. -   if (new != NULL) {
  68. -       ((PyLogObject *)new)->eventlog = NULL;
  69. -        ((PyLogObject *)new)->mode = 0;
  70. +   newobj = type->tp_alloc(type, 0);
  71. +   if (newobj != NULL) {
  72. +       ((PyLogObject *)newobj)->eventlog = NULL;
  73. +        ((PyLogObject *)newobj)->mode = 0;
  74.      }
  75. -   return new;
  76. +   return newobj;
  77.  }
  78.  
  79.  static void
  80. Index: lcm-python/pylcm.c
  81. ===================================================================
  82. --- lcm-python/pylcm.c  (revision 638)
  83. +++ lcm-python/pylcm.c  (working copy)
  84. @@ -1,3 +1,4 @@
  85. +#ifndef WIN32
  86.  #include <sys/socket.h>
  87.  #include <sys/select.h>
  88.  #include <netinet/in.h>
  89. @@ -2,2 +3,5 @@
  90.  #include <arpa/inet.h>
  91. +#else
  92. +#include <winsock2.h>
  93. +#endif
  94.  
  95. @@ -54,7 +58,8 @@
  96.  @undocumented: __new__, __getattribute__\n\
  97.  ");
  98.  
  99. -PyTypeObject pylcm_type;
  100. +//gives redefinition error in MSVC
  101. +//PyTypeObject pylcm_type;
  102.  
  103. // all LCM messages subscribed to by all LCM objects pass through this
  104. // handler first.
  105. @@ -64,9 +69,10 @@
  106. {
  107.     // if an exception has occurred, then abort.
  108.     if (PyErr_Occurred ()) return;
  109. +  
  110. +   //MSVC requires explicit cast
  111. +    PyLCMSubscriptionObject *subs_obj = (PyLCMSubscriptionObject*) userdata;
  112.  
  113. -    PyLCMSubscriptionObject *subs_obj = userdata;
  114. -
  115.     PyObject *arglist = Py_BuildValue ("ss#", channel,
  116.              rbuf->data, rbuf->data_size);
  117.  
  118. Index: lcm-python/setup.py
  119. ===================================================================
  120. --- lcm-python/setup.py (revision 638)
  121. +++ lcm-python/setup.py (working copy)
  122. @@ -1,30 +1,68 @@
  123.  import commands
  124.  from distutils.core import setup, Extension
  125. +from distutils import msvccompiler
  126. +import os
  127.  
  128. +if os.name == 'nt':
  129. +   #check for GLIB_PATH environment var, exit with error if not found
  130. +   glibPath = os.getenv('GLIB_PATH')
  131. +   if not glibPath:
  132. +       sys.exit('GLIB_PATH environment variable not set.')
  133. +      
  134. +   includeDirs = []
  135. +   lcmBase = '..'
  136. +   includeDirs.append(os.path.join(lcmBase, 'WinSpecific\include'))
  137. +   includeDirs.append(os.path.join(lcmBase, 'WinSpecific'))
  138. +      
  139. +   libraryDirs = ['..\WinSpecific\Release', os.path.join(glibPath, 'lib')]
  140. +  
  141. +   #define additional macro WIN32, used to discriminate win specific code
  142. +   defineMacros = [('WIN32', 1)]
  143. +      
  144. +   winlibs = ['Ws2_32', 'glib-2.0', 'gthread-2.0', 'lcm']
  145. +   # compiler arguments
  146. +   # /TP enforces compilation of code as c++
  147. +   extraCompileArgs = ['/TP']
  148.  
  149. -pkgconfig_cflags = commands.getoutput ("pkg-config --cflags lcm glib-2.0 gthread-2.0")
  150. -pkgconfig_include_flags = commands.getoutput ("pkg-config --cflags-only-I lcm")
  151. -pkgconfig_include_dirs = [ t[2:] for t in pkgconfig_include_flags.split() ]
  152. +   # we need to patch the msvccompiler.MSVCCompiler class to compile
  153. +   # .c C files as C++ code (/TP switch for MSVC)
  154. +   # the default behaviour generates the command line switch /Tc for
  155. +   # every .c source file
  156. +   msvccompiler.MSVCCompiler._c_extensions = []
  157. +   msvccompiler.MSVCCompiler._cpp_extensions.append('.c')
  158. +  
  159. +   pylcm_extension = Extension("lcm._lcm", ["module.c", "pyeventlog.c", "pylcm.c",
  160. +                               "pylcm_subscription.c"],
  161. +                           include_dirs=includeDirs,
  162. +                          define_macros=defineMacros,
  163. +                          library_dirs=libraryDirs,
  164. +                           libraries=winlibs,
  165. +                          extra_compile_args=extraCompileArgs
  166. +                          )
  167. +else:
  168. +   pkgconfig_cflags = commands.getoutput ("pkg-config --cflags lcm glib-2.0 gthread-2.0")
  169. +   pkgconfig_include_flags = commands.getoutput ("pkg-config --cflags-only-I lcm")
  170. +   pkgconfig_include_dirs = [ t[2:] for t in pkgconfig_include_flags.split() ]
  171.  
  172. -pkgconfig_lflags = commands.getoutput ( \
  173. -        "pkg-config --libs-only-l lcm glib-2.0 gthread-2.0")
  174. -pkgconfig_libs = [ t[2:] for t in pkgconfig_lflags.split() ]
  175. +   pkgconfig_lflags = commands.getoutput ( \
  176. +           "pkg-config --libs-only-l lcm glib-2.0 gthread-2.0")
  177. +   pkgconfig_libs = [ t[2:] for t in pkgconfig_lflags.split() ]
  178.  
  179. -pkgconfig_biglflags = commands.getoutput ( \
  180. -        "pkg-config --libs-only-L lcm glib-2.0 gthread-2.0")
  181. -pkgconfig_ldirs = [ t[2:] for t in pkgconfig_biglflags.split() ]
  182. +   pkgconfig_biglflags = commands.getoutput ( \
  183. +           "pkg-config --libs-only-L lcm glib-2.0 gthread-2.0")
  184. +   pkgconfig_ldirs = [ t[2:] for t in pkgconfig_biglflags.split() ]
  185.  
  186. -pylcm_extension = Extension("lcm._lcm",
  187. -                           sources=["module.c", "pyeventlog.c", "pylcm.c",
  188. -                               "pylcm_subscription.c"],
  189. -                           library_dirs=pkgconfig_ldirs,
  190. -                           include_dirs=pkgconfig_include_dirs,
  191. -                           libraries=pkgconfig_libs,
  192. -                           extra_compile_args=['-Wno-strict-prototypes',
  193. -                               pkgconfig_cflags,
  194. -                               "-D_FILE_OFFSET_BITS=64",
  195. -                               "-D_LARGEFILE_SOURCE",
  196. -                               "-std=gnu99" ])
  197. +   pylcm_extension = Extension("lcm._lcm",
  198. +                              sources=["module.c", "pyeventlog.c", "pylcm.c",
  199. +                                  "pylcm_subscription.c"],
  200. +                              library_dirs=pkgconfig_ldirs,
  201. +                              include_dirs=pkgconfig_include_dirs,
  202. +                              libraries=pkgconfig_libs,
  203. +                              extra_compile_args=['-Wno-strict-prototypes',
  204. +                                  pkgconfig_cflags,
  205. +                                  "-D_FILE_OFFSET_BITS=64",
  206. +                                  "-D_LARGEFILE_SOURCE",
  207. +                                  "-std=gnu99" ])
  208.  
  209.  setup(name="lcm", version="0.8.0",
  210.        ext_modules=[pylcm_extension],
  211. Index: WinSpecific/include/lcm/lcm.h
  212. ===================================================================
  213. --- WinSpecific/include/lcm/lcm.h   (revision 638)
  214. +++ WinSpecific/include/lcm/lcm.h   (working copy)
  215. @@ -213,6 +213,28 @@
  216.  LCM_API_FUNCTION
  217.  int lcm_handle (lcm_t *lcm);
  218.  
  219. +/**
  220. + * @brief Adjusts the maximum number of received messages that can be queued up
  221. + * for a subscription.  
  222. + *
  223. + * In general, you probably don't want to use this function.  Instead, use the
  224. + * message-specific set_queue_capacity function generated by @c lcm-gen.  Use
  225. + * this function only when you want to work with untyped subscriptions.  TODO
  226. + * link to example or more details.
  227. + *
  228. + * Setting this to a low number may reduce overall latency at the expense of
  229. + * dropping more messages.  Conversely, setting this to a high number may drop
  230. + * fewer messages at the expense of increased latency.  A value of 0 indicates
  231. + * no limit, and should be used carefully.
  232. + *
  233. + * @param handler the subscription object
  234. + * @param num_messages the maximum queue size, in messages.  The default is 30.
  235. + *
  236. + */
  237. +LCM_API_FUNCTION
  238. +int lcm_subscription_set_queue_capacity(lcm_subscription_t* handler, int num_messages);
  239. +
  240. +
  241. #ifdef __cplusplus
  242. }
  243. #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement