zrtp_iface_scheduler.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /*
  2. * libZRTP SDK library, implements the ZRTP secure VoIP protocol.
  3. * Copyright (c) 2006-2009 Philip R. Zimmermann. All rights reserved.
  4. * Contact: http://philzimmermann.com
  5. * For licensing and other legal details, see the file zrtp_legal.c.
  6. *
  7. * Viktor Krykun <v.krikun at zfoneproject.com>
  8. */
  9. #ifndef __ZRTP_IFACE_SCHEDULER_H__
  10. #define __ZRTP_IFACE_SCHEDULER_H__
  11. #include "zrtp_config.h"
  12. #include "zrtp_base.h"
  13. #include "zrtp_string.h"
  14. #include "zrtp_error.h"
  15. #include "zrtp_iface.h"
  16. #if defined(ZRTP_USE_BUILTIN_SCEHDULER) && (ZRTP_USE_BUILTIN_SCEHDULER == 1)
  17. #if defined(__cplusplus)
  18. extern "C"
  19. {
  20. #endif
  21. /**
  22. * In order to use default secheduler libzrtp one should define tow extra interfaces:
  23. * sleep and threads riutine.
  24. */
  25. /**
  26. * \brief Suspend thread execution for an interval measured in miliseconds
  27. * \param msec - number of miliseconds
  28. * \return: 0 if successful and -1 in case of errors.
  29. */
  30. #if ZRTP_PLATFORM != ZP_WIN32_KERNEL
  31. #if (ZRTP_PLATFORM == ZP_WIN32) || (ZRTP_PLATFORM == ZP_WINCE)
  32. #include <windows.h>
  33. typedef LPTHREAD_START_ROUTINE zrtp_thread_routine_t;
  34. #elif (ZRTP_PLATFORM == ZP_LINUX) || (ZRTP_PLATFORM == ZP_DARWIN) || (ZRTP_PLATFORM == ZP_BSD) || (ZRTP_PLATFORM == ZP_ANDROID)
  35. typedef void *(*zrtp_thread_routine_t)(void*);
  36. #elif (ZRTP_PLATFORM == ZP_SYMBIAN)
  37. typedef int(*zrtp_thread_routine_t)(void*);
  38. #endif
  39. /**
  40. * \brief Function is used to create a new thread, within a process.
  41. *
  42. * Thread should be created with default attributes. Upon its creation, the thread executes
  43. * \c start_routine, with \c arg as its sole argument.
  44. * \param start_routine - thread start routine.
  45. * \param arg - start routine arguments.
  46. * \return 0 if successful and -1 in case of errors.
  47. */
  48. extern int zrtp_thread_create(zrtp_thread_routine_t start_routine, void *arg);
  49. extern int zrtp_sleep(unsigned int msec);
  50. #endif
  51. void zrtp_def_scheduler_down();
  52. zrtp_status_t zrtp_def_scheduler_init(zrtp_global_t* zrtp);
  53. void zrtp_def_scheduler_call_later(zrtp_stream_t *ctx, zrtp_retry_task_t* ztask);
  54. void zrtp_def_scheduler_cancel_call_later(zrtp_stream_t* ctx, zrtp_retry_task_t* ztask);
  55. void zrtp_def_scheduler_wait_call_later(zrtp_stream_t* ctx);
  56. zrtp_status_t zrtp_sem_init(zrtp_sem_t** sem, uint32_t value, uint32_t limit);
  57. zrtp_status_t zrtp_sem_destroy(zrtp_sem_t* sem);
  58. zrtp_status_t zrtp_sem_wait(zrtp_sem_t* sem);
  59. zrtp_status_t zrtp_sem_trtwait(zrtp_sem_t* sem);
  60. zrtp_status_t zrtp_sem_post(zrtp_sem_t* sem);
  61. #if defined(__cplusplus)
  62. }
  63. #endif
  64. #endif /* ZRTP_USE_BUILTIN_SCEHDULER */
  65. #endif /*__ZRTP_IFACE_SCHEDULER_H__*/