ht5-portability.dox 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /**
  2. * @ingroup libosip2 The GNU oSIP stack
  3. * @defgroup howto_portability How-To handle portability.
  4. * @section howto_portability1 Description.
  5. The libosip2 library also offer high portability through a common API
  6. for conditions variables, fifos, threads, mutex and semaphore: all you
  7. need to write portable applications.
  8. The target and active development platforms are: linux, windows, macosx,
  9. android and iOS. Those platforms are tested every day and you can use
  10. the git repository without fear!
  11. Additionnaly, wince, windows mobile, vxworks, unix, linux on arm -and more-
  12. have been also tested regularly. If you have troubles for some system,
  13. please ask the mailing list (osip-dev@gnu.org)
  14. ~~~~~~~{.c}
  15. #include <osip2/osip_mt.h>
  16. #include <osip2/osip_fifo.h>
  17. #include <osip2/osip_condv.h>
  18. #include <osip2/osip_time.h>
  19. ~~~~~~~
  20. * @section howto_portability2 Threads
  21. + Here is code to show how to start a thread:
  22. ~~~~~~~{.c}
  23. void *_my_thread (void *arg)
  24. {
  25. struct sometype_t *excontext = (struct sometype_t *) arg;
  26. int i;
  27. while (stopthread == 0) {
  28. do_actions (excontext);
  29. }
  30. osip_thread_exit ();
  31. return NULL;
  32. }
  33. struct osip_thread *thread;
  34. thread = osip_thread_create (20000, _my_thread, argpointer);
  35. ~~~~~~~
  36. + Here is code to show how to terminate a thread:
  37. ~~~~~~~{.c}
  38. i = osip_thread_join (thread);
  39. osip_free (thread);
  40. ~~~~~~~
  41. * @section howto_portability3 Mutex
  42. + Here is code to show how to create/lock/unlock/release:
  43. ~~~~~~~{.c}
  44. struct osip_mutex *mutex;
  45. mutex = osip_mutex_init ();
  46. osip_mutex_lock (mutex);
  47. do_actions ();
  48. osip_mutex_unlock (mutex);
  49. osip_mutex_destroy (mutex);
  50. ~~~~~~~
  51. * @section howto_portability4 Time
  52. libosip2 is also providing a common time API.
  53. This is usefull to implement in various way
  54. a CLOCK_MONOTONIC time and make time adjustement
  55. when a drift is discovered against realtime
  56. clock.
  57. **Note**: It is required to call osip_compensatetime
  58. on Android which goes regularly into deep sleep mode.
  59. When this happens, the MONOTONIC clock is not
  60. increasing. This may also happen for other OS as
  61. well.
  62. ~~~~~~~{.c}
  63. int osip_gettimeofday (struct timeval *tp, void *tz);
  64. void osip_compensatetime ();
  65. ~~~~~~~
  66. */