zrtp_iface_system.h 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. /**
  10. * \file zrtp_iface_system.h
  11. * \brief libzrtp platform-dependent routine
  12. */
  13. #ifndef __ZRTP_IFACE_SYSTEM_H__
  14. #define __ZRTP_IFACE_SYSTEM_H__
  15. #include "zrtp_config.h"
  16. #include "zrtp_types.h"
  17. #if defined(__cplusplus)
  18. extern "C"
  19. {
  20. #endif
  21. /*============================================================================*/
  22. /* System wide functions */
  23. /*============================================================================*/
  24. /**
  25. * \defgroup zrtp_iface Library Interfaces Overview
  26. *
  27. * This section describes the requirements for the implementation of each interface function.
  28. * Descriptions are divided into groups by function
  29. */
  30. /**
  31. * \defgroup zrtp_iface_base Basic platform-dependent routine
  32. * \ingroup zrtp_iface
  33. * \{
  34. */
  35. /**
  36. * \brief Time in miliseconds
  37. *
  38. * libzrtp uses a unix-like time calculation scheme: time since 1/1/1970.
  39. */
  40. typedef uint64_t zrtp_time_t;
  41. /**
  42. * \brief Allocates memory of a defined size
  43. *
  44. * Allocates \c size bytes and returns a pointer to the allocated memory Allocated memory is not
  45. * cleared.
  46. *
  47. * \param size - number of bytes for allocation
  48. * \return
  49. * - pointer to the allocated memory if successful.
  50. * - NULL if the memory allocation failed.
  51. */
  52. extern void* zrtp_sys_alloc(unsigned int size);
  53. /**
  54. * \brief release memory
  55. *
  56. * Release the memory space pointed to by \c obj, which was returned by a previous zrtp_sys_alloc()
  57. * call. If \c obj is NULL, no operation is performed.
  58. *
  59. * \param obj - pointer to the released memory
  60. */
  61. extern void zrtp_sys_free(void* obj);
  62. /**
  63. * \brief Memory copying function.
  64. *
  65. * This function copies \c length bytes from memory area \c src to memory area \c dest. The memory
  66. * areas should not overlap.
  67. *
  68. * \param dest - pointer to the destination buffer
  69. * \param src - pointer to the source buffer;
  70. * \param length - number of bytes to be copied.
  71. * \return
  72. * - pointer to the destination buffer (dest)
  73. */
  74. extern void* zrtp_memcpy(void* dest, const void* src, unsigned int length);
  75. /**
  76. * \brief Write a byte to a byte string
  77. *
  78. * The zrtp_memset() function writes \c n bytes of value \c c (converted to an unsigned char) to the
  79. * string \c s.
  80. * \return
  81. * - first argument
  82. */
  83. extern void *zrtp_memset(void *s, int c, unsigned int n);
  84. /**
  85. * \brief Returns current date and time
  86. *
  87. * This function should return current unix-like date and time: number of microseconds since
  88. * 1.1.1970.
  89. */
  90. extern zrtp_time_t zrtp_time_now();
  91. /** \} */
  92. /*============================================================================*/
  93. /* Mutex related interfaces */
  94. /*============================================================================*/
  95. /**
  96. * \defgroup zrtp_iface_mutex Synchronization related functions
  97. * \ingroup zrtp_iface
  98. * \{
  99. */
  100. /**
  101. * \brief Initializing the mutex structure
  102. *
  103. * This function allocates and initializes the mutex referenced by \c mutex with default attributes.
  104. * Upon successful initialization, the state of the mutex becomes initialized and unlocked. This
  105. * function should create a NON RECURSIVE mutex. (Attempting to relock the mutex causes deadlock)
  106. *
  107. * \param mutex - out parameter, mutex structure for allocation and initialization
  108. * \return:
  109. * - zrtp_status_ok if initialization successful;
  110. * - zrtp_status_fail if an error occurred.
  111. * \sa zrtp_mutex_destroy()
  112. */
  113. extern zrtp_status_t zrtp_mutex_init(zrtp_mutex_t** mutex);
  114. /**
  115. * \brief Deinitializing the mutex structure
  116. *
  117. * This function destroys the mutex object previously allocated by zrtp_mutex_init().
  118. *
  119. * \param mutex - mutex structure for deinitialization.
  120. * \return:
  121. * - zrtp_status_ok if deinitialization successful;
  122. * - zrtp_status_fail if an error occurred.
  123. * \sa zrtp_mutex_init()
  124. */
  125. extern zrtp_status_t zrtp_mutex_destroy(zrtp_mutex_t* mutex);
  126. /**
  127. * \brief Mutex locking
  128. *
  129. * This function locks the mutex object referenced by \c mutex. If the mutex is already locked, the
  130. * thread that called it is blocked until the mutex becomes available. This operation returns the
  131. * mutex object referenced by the mutex in the locked state with the calling thread as its owner.
  132. *
  133. * \param mutex - mutex for locking;
  134. * \return:
  135. * - zrtp_status_ok if successful;
  136. * - zrtp_status_fail if an error occurred.
  137. */
  138. extern zrtp_status_t zrtp_mutex_lock(zrtp_mutex_t* mutex);
  139. /**
  140. * \brief Mutex releasing
  141. *
  142. * This function releases the mutex object referenced by mutex. The way a mutex is released depends
  143. * on the mutex's type attribute. If there are threads blocked on the mutex object referenced by
  144. * mutex when zrtp_mutex_unlock() is called and the mutex becomes available, the scheduling policy
  145. * determines which thread acquires the mutex.
  146. *
  147. * \param mutex - mutex to release
  148. * \return:
  149. * - zrtp_status_ok if successful;
  150. * - zrtp_status_fail if an error occurred.
  151. */
  152. extern zrtp_status_t zrtp_mutex_unlock(zrtp_mutex_t* mutex);
  153. /*! \} */
  154. #if defined(__cplusplus)
  155. }
  156. #endif
  157. #endif /* __ZRTP_IFACE_SYSTEM_H__ */