logging_api.h 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. /*
  2. * logging_api.h
  3. *
  4. * Copyright 2016 Michael Zillgith
  5. *
  6. * This file is part of libIEC61850.
  7. *
  8. * libIEC61850 is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * libIEC61850 is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with libIEC61850. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. * See COPYING file for the complete license text.
  22. */
  23. #ifndef LIBIEC61850_SRC_LOGGING_LOGGING_API_H_
  24. #define LIBIEC61850_SRC_LOGGING_LOGGING_API_H_
  25. #ifdef __cplusplus
  26. extern "C" {
  27. #endif
  28. #include "libiec61850_common_api.h"
  29. /** \addtogroup server_api_group
  30. * @{
  31. */
  32. /**
  33. * @defgroup LOGGING_SPI Service provider interface (SPI) for log storage implementations
  34. *
  35. * This interface has to be implemented by the log storage provider. The Log storage provider
  36. * has to provide a specific constructor that creates an instance of LogStorage by allocating
  37. * the required memory for the struct sLogStorage data structure and populate the function
  38. * pointers with provider specific implementation functions.
  39. *
  40. * @{
  41. */
  42. /** The LogStorage object handle */
  43. typedef struct sLogStorage* LogStorage;
  44. /**
  45. * \brief Will be called for each new LogEntry by the getEntries and getEntriesAfter functions
  46. *
  47. * \param parameter - a user provided parameter that is passed to the callback handler
  48. * \param timestamp - the entry timestamp of the LogEntry
  49. * \param entryID - the entryID of the LogEntry
  50. * \param moreFollow - more data will follow - if false, the data is not valid and no more data will follow
  51. *
  52. * \return true ready to receive new data, false abort operation
  53. */
  54. typedef bool (*LogEntryCallback) (void* parameter, uint64_t timestamp, uint64_t entryID, bool moreFollow);
  55. /**
  56. * \brief Will be called for each new LogEntryData by the getEntries and getEntriesAfter functions
  57. *
  58. * \param parameter - a user provided parameter that is passed to the callback handler
  59. * \param dataRef - the data reference of the LogEntryData
  60. * \param data - the data content as an unstructured binary data block
  61. * \param dataSize - the size of the binary data block
  62. * \param reasonCode - the reasonCode of the LogEntryData
  63. * \param moreFollow - more data will follow - if false, the data is not valid and no more data will follow
  64. *
  65. * \return true ready to receive new data, false abort operation
  66. */
  67. typedef bool (*LogEntryDataCallback) (void* parameter, const char* dataRef, uint8_t* data, int dataSize, uint8_t reasonCode, bool moreFollow);
  68. struct sLogStorage {
  69. void* instanceData;
  70. int maxLogEntries;
  71. uint64_t (*addEntry) (LogStorage self, uint64_t timestamp);
  72. bool (*addEntryData) (LogStorage self, uint64_t entryID, const char* dataRef, uint8_t* data, int dataSize, uint8_t reasonCode);
  73. bool (*getEntries) (LogStorage self, uint64_t startingTime, uint64_t endingTime,
  74. LogEntryCallback entryCallback, LogEntryDataCallback entryDataCallback, void* parameter);
  75. bool (*getEntriesAfter) (LogStorage self, uint64_t startingTime, uint64_t entryID,
  76. LogEntryCallback entryCallback, LogEntryDataCallback entryDataCallback, void* parameter);
  77. bool (*getOldestAndNewestEntries) (LogStorage self, uint64_t* newEntry, uint64_t* newEntryTime,
  78. uint64_t* oldEntry, uint64_t* oldEntryTime);
  79. void (*destroy) (LogStorage self);
  80. };
  81. /**
  82. * \brief Set the maximum number of log entries for this log
  83. *
  84. * \param self the pointer of the LogStorage instance
  85. * \param maxEntries the maximum number of log entries
  86. */
  87. LIB61850_API void
  88. LogStorage_setMaxLogEntries(LogStorage self, int maxEntries);
  89. /**
  90. * \brief Get the maximum allowed number of log entries for this log
  91. *
  92. * \param self the pointer of the LogStorage instance
  93. *
  94. * \return the maximum number of log entries
  95. */
  96. LIB61850_API int
  97. LogStorage_getMaxLogEntries(LogStorage self);
  98. /**
  99. * \brief Add an entry to the log
  100. *
  101. * \param self the pointer of the LogStorage instance
  102. * \param timestamp the entry time of the new entry
  103. *
  104. * \return the entryID of the new entry
  105. */
  106. LIB61850_API uint64_t
  107. LogStorage_addEntry(LogStorage self, uint64_t timestamp);
  108. /**
  109. * \brief Add new entry data to an existing log entry
  110. *
  111. * \param self the pointer of the LogStorage instance
  112. * \param entryID the ID of the log entry where the data will be added
  113. * \param dataRef the data reference of the log entry data
  114. * \param data the data content as an unstructured binary data block
  115. * \param dataSize - the size of the binary data block
  116. * \param reasonCode - the reasonCode of the LogEntryData
  117. *
  118. * \return true if the entry data was successfully added, false otherwise
  119. */
  120. LIB61850_API bool
  121. LogStorage_addEntryData(LogStorage self, uint64_t entryID, const char* dataRef, uint8_t* data, int dataSize, uint8_t reasonCode);
  122. /**
  123. * \brief Get log entries specified by a time range
  124. *
  125. * \param self the pointer of the LogStorage instance
  126. * \param startingTime start time of the time range
  127. * \param endingTime end time of the time range
  128. * \param entryCallback callback function to be called for each new log entry
  129. * \param entryDataCallback callback function to be called for each new log entry data
  130. * \param parameter - a user provided parameter that is passed to the callback handler
  131. *
  132. * \return true if the request has been successful, false otherwise
  133. */
  134. LIB61850_API bool
  135. LogStorage_getEntries(LogStorage self, uint64_t startingTime, uint64_t endingTime,
  136. LogEntryCallback entryCallback, LogEntryDataCallback entryDataCallback, void* parameter);
  137. /**
  138. * \brief Get log entries specified by a start log entry
  139. *
  140. * The request will return all log entries that where entered into the log after the
  141. * log entry specified by startingTime and entryID.
  142. *
  143. * \param self the pointer of the LogStorage instance
  144. * \param startingTime timestamp of the start log entry
  145. * \param entryID entryID of the start log entry
  146. * \param entryCallback callback function to be called for each new log entry
  147. * \param entryDataCallback callback function to be called for each new log entry data
  148. * \param parameter - a user provided parameter that is passed to the callback handler
  149. *
  150. * \return true if the request has been successful, false otherwise
  151. */
  152. LIB61850_API bool
  153. LogStorage_getEntriesAfter(LogStorage self, uint64_t startingTime, uint64_t entryID,
  154. LogEntryCallback entryCallback, LogEntryDataCallback entryDataCallback, void* parameter);
  155. /**
  156. * \brief Get the entry time and entryID of the oldest and the newest log entries
  157. *
  158. * This function is used to update the log status information in the LCB
  159. *
  160. * \param self the pointer of the LogStorage instance
  161. * \param newEntry pointer to store the entryID of the newest entry
  162. * \param newEntryTime pointer to store the entry time of the newest entry
  163. * \param oldEntry pointer to store the entryID of the oldest entry
  164. * \param oldEntryTime pointer to store the entry time of the oldest entry
  165. *
  166. */
  167. LIB61850_API bool
  168. LogStorage_getOldestAndNewestEntries(LogStorage self, uint64_t* newEntry, uint64_t* newEntryTime,
  169. uint64_t* oldEntry, uint64_t* oldEntryTime);
  170. /**
  171. * \brief Destroy the LogStorage instance and free all related resources
  172. *
  173. * \param self the pointer of the LogStorage instance
  174. */
  175. LIB61850_API void
  176. LogStorage_destroy(LogStorage self);
  177. /**@}*/
  178. /**@}*/
  179. #ifdef __cplusplus
  180. }
  181. #endif
  182. #endif /* LIBIEC61850_SRC_LOGGING_LOGGING_API_H_ */