PageRenderTime 26ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/Externals/AKOLibrary.framework/Versions/A/Headers/LoggerClient.h

https://github.com/akosmasoftware/Notitas
C Header | 231 lines | 92 code | 38 blank | 101 comment | 0 complexity | 68d6fe6e9221f48d61e1644fc8978dcc MD5 | raw file
  1. /*
  2. * LoggerClient.h
  3. *
  4. * version 1.0 2011-10-30
  5. *
  6. * Part of NSLogger (client side)
  7. * https://github.com/fpillet/NSLogger
  8. *
  9. * BSD license follows (http://www.opensource.org/licenses/bsd-license.php)
  10. *
  11. * Copyright (c) 2010-2011 Florent Pillet All Rights Reserved.
  12. *
  13. * Redistribution and use in source and binary forms, with or without modification,
  14. * are permitted provided that the following conditions are met:
  15. *
  16. * Redistributions of source code must retain the above copyright notice,
  17. * this list of conditions and the following disclaimer. Redistributions in
  18. * binary form must reproduce the above copyright notice, this list of
  19. * conditions and the following disclaimer in the documentation and/or other
  20. * materials provided with the distribution. Neither the name of Florent
  21. * Pillet nor the names of its contributors may be used to endorse or promote
  22. * products derived from this software without specific prior written
  23. * permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  24. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
  25. * NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  26. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  27. * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  28. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
  29. * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  30. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  31. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  32. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  33. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  34. *
  35. */
  36. #import <unistd.h>
  37. #import <pthread.h>
  38. #import <libkern/OSAtomic.h>
  39. #import <Foundation/Foundation.h>
  40. #import <CoreFoundation/CoreFoundation.h>
  41. #import <SystemConfiguration/SystemConfiguration.h>
  42. #if !TARGET_OS_IPHONE
  43. #import <CoreServices/CoreServices.h>
  44. #endif
  45. // This define is here so that user application can test whether NSLogger Client is
  46. // being included in the project, and potentially configure their macros accordingly
  47. #define NSLOGGER_WAS_HERE 1
  48. // Set this to 0 if you absolutely NOT want any access to Cocoa (Objective-C, NS* calls)
  49. // We need a couple ones to reliably obtain the thread number and device information
  50. // Note that since we need NSAutoreleasePool when using Cocoa in the logger's worker thread,
  51. // we need to put Cocoa in multithreading mode. Also, ALLOW_COCOA_USE allows the client code
  52. // to use NSLog()-style message formatting (less verbose than CFShow()-style) through the
  53. // use of -[NSString stringWithFormat:arguments:]
  54. #define ALLOW_COCOA_USE 1
  55. /* -----------------------------------------------------------------
  56. * Logger option flags & default options
  57. * -----------------------------------------------------------------
  58. */
  59. enum {
  60. kLoggerOption_LogToConsole = 0x01,
  61. kLoggerOption_BufferLogsUntilConnection = 0x02,
  62. kLoggerOption_BrowseBonjour = 0x04,
  63. kLoggerOption_BrowseOnlyLocalDomain = 0x08,
  64. kLoggerOption_UseSSL = 0x10
  65. };
  66. #define LOGGER_DEFAULT_OPTIONS (kLoggerOption_BufferLogsUntilConnection | \
  67. kLoggerOption_BrowseBonjour | \
  68. kLoggerOption_BrowseOnlyLocalDomain | \
  69. kLoggerOption_UseSSL)
  70. /* -----------------------------------------------------------------
  71. * Structure defining a Logger
  72. * -----------------------------------------------------------------
  73. */
  74. typedef struct
  75. {
  76. CFStringRef bufferFile; // If non-NULL, all buffering is done to the specified file instead of in-memory
  77. CFStringRef host; // Viewer host to connect to (instead of using Bonjour)
  78. UInt32 port; // port on the viewer host
  79. CFMutableArrayRef bonjourServiceBrowsers; // Active service browsers
  80. CFMutableArrayRef bonjourServices; // Services being tried
  81. CFNetServiceBrowserRef bonjourDomainBrowser; // Domain browser
  82. CFMutableArrayRef logQueue; // Message queue
  83. pthread_mutex_t logQueueMutex;
  84. pthread_cond_t logQueueEmpty;
  85. pthread_t workerThread; // The worker thread responsible for Bonjour resolution, connection and logs transmission
  86. CFRunLoopSourceRef messagePushedSource; // A message source that fires on the worker thread when messages are available for send
  87. CFRunLoopSourceRef bufferFileChangedSource; // A message source that fires on the worker thread when the buffer file configuration changes
  88. CFWriteStreamRef logStream; // The connected stream we're writing to
  89. CFWriteStreamRef bufferWriteStream; // If bufferFile not NULL and we're not connected, points to a stream for writing log data
  90. CFReadStreamRef bufferReadStream; // If bufferFile not NULL, points to a read stream that will be emptied prior to sending the rest of in-memory messages
  91. SCNetworkReachabilityRef reachability; // The reachability object we use to determine when the target host becomes reachable
  92. CFRunLoopTimerRef checkHostTimer; // A timer to regularly check connection to the defined host, along with reachability for added reliability
  93. uint8_t *sendBuffer; // data waiting to be sent
  94. NSUInteger sendBufferSize;
  95. NSUInteger sendBufferUsed; // number of bytes of the send buffer currently in use
  96. NSUInteger sendBufferOffset; // offset in sendBuffer to start sending at
  97. int32_t messageSeq; // sequential message number (added to each message sent)
  98. // settings
  99. uint32_t options; // Flags, see enum above
  100. CFStringRef bonjourServiceType; // leave NULL to use the default
  101. CFStringRef bonjourServiceName; // leave NULL to use the first one available
  102. // internal state
  103. BOOL connected; // Set to YES once the write stream declares the connection open
  104. volatile BOOL quit; // Set to YES to terminate the logger worker thread's runloop
  105. BOOL incompleteSendOfFirstItem; // set to YES if we are sending the first item in the queue and it's bigger than what the buffer can hold
  106. } Logger;
  107. /* -----------------------------------------------------------------
  108. * LOGGING FUNCTIONS
  109. * -----------------------------------------------------------------
  110. */
  111. #ifdef __cplusplus
  112. extern "C" {
  113. #endif
  114. // Functions to set and get the default logger
  115. extern void LoggerSetDefaultLogger(Logger *aLogger);
  116. extern Logger *LoggerGetDefaultLogger(void);
  117. // Initialize a new logger, set as default logger if this is the first one
  118. // Options default to:
  119. // - logging to console = NO
  120. // - buffer until connection = YES
  121. // - browse Bonjour = YES
  122. // - browse only locally on Bonjour = YES
  123. extern Logger* LoggerInit(void);
  124. // Set logger options if you don't want the default options (see above)
  125. extern void LoggerSetOptions(Logger *logger, uint32_t options);
  126. // Set Bonjour logging names, so you can force the logger to use a specific service type
  127. // or direct logs to the machine on your network which publishes a specific name
  128. extern void LoggerSetupBonjour(Logger *logger, CFStringRef bonjourServiceType, CFStringRef bonjourServiceName);
  129. // Directly set the viewer host (hostname or IP address) and port we want to connect to. If set, LoggerStart() will
  130. // try to connect there first before trying Bonjour
  131. extern void LoggerSetViewerHost(Logger *logger, CFStringRef hostName, UInt32 port);
  132. // Configure the logger to use a local file for buffering, instead of memory.
  133. // - If you initially set a buffer file after logging started but while a logger connection
  134. // has not been acquired, the contents of the log queue will be written to the buffer file
  135. // the next time a logging function is called, or when LoggerStop() is called.
  136. // - If you want to change the buffering file after logging started, you should first
  137. // call LoggerStop() the call LoggerSetBufferFile(). Note that all logs stored in the previous
  138. // buffer file WON'T be transferred to the new file in this case.
  139. extern void LoggerSetBufferFile(Logger *logger, CFStringRef absolutePath);
  140. // Activate the logger, try connecting
  141. extern void LoggerStart(Logger *logger);
  142. //extern void LoggerConnectToHost(CFDataRef address, int port);
  143. // Deactivate and free the logger.
  144. extern void LoggerStop(Logger *logger);
  145. // Pause the current thread until all messages from the logger have been transmitted
  146. // this is useful to use before an assert() aborts your program. If waitForConnection is YES,
  147. // LoggerFlush() will block even if the client is not currently connected to the desktop
  148. // viewer. You should be using NO most of the time, but in some cases it can be useful.
  149. extern void LoggerFlush(Logger *logger, BOOL waitForConnection);
  150. /* Logging functions. Each function exists in four versions:
  151. *
  152. * - one without a Logger instance (uses default logger) and without filename/line/function (no F suffix)
  153. * - one without a Logger instance but with filename/line/function (F suffix)
  154. * - one with a Logger instance (use a specific Logger) and without filename/line/function (no F suffix)
  155. * - one with a Logger instance (use a specific Logger) and with filename/line/function (F suffix)
  156. *
  157. * The exception being the single LogMessageCompat() function which is designed to be a drop-in replacement for NSLog()
  158. *
  159. */
  160. // Log a message, calling format compatible with NSLog
  161. extern void LogMessageCompat(NSString *format, ...);
  162. // Log a message. domain can be nil if default domain.
  163. extern void LogMessage(NSString *domain, int level, NSString *format, ...);
  164. extern void LogMessageF(const char *filename, int lineNumber, const char *functionName, NSString *domain, int level, NSString *format, ...);
  165. extern void LogMessageTo(Logger *logger, NSString *domain, int level, NSString *format, ...);
  166. extern void LogMessageToF(Logger *logger, const char *filename, int lineNumber, const char *functionName, NSString *domain, int level, NSString *format, ...);
  167. // Log a message. domain can be nil if default domain (versions with va_list format args instead of ...)
  168. extern void LogMessage_va(NSString *domain, int level, NSString *format, va_list args);
  169. extern void LogMessageF_va(const char *filename, int lineNumber, const char *functionName, NSString *domain, int level, NSString *format, va_list args);
  170. extern void LogMessageTo_va(Logger *logger, NSString *domain, int level, NSString *format, va_list args);
  171. extern void LogMessageToF_va(Logger *logger, const char *filename, int lineNumber, const char *functionName, NSString *domain, int level, NSString *format, va_list args);
  172. // Send binary data to remote logger
  173. extern void LogData(NSString *domain, int level, NSData *data);
  174. extern void LogDataF(const char *filename, int lineNumber, const char *functionName, NSString *domain, int level, NSData *data);
  175. extern void LogDataTo(Logger *logger, NSString *domain, int level, NSData *data);
  176. extern void LogDataToF(Logger *logger, const char *filename, int lineNumber, const char *functionName, NSString *domain, int level, NSData *data);
  177. // Send image data to remote logger
  178. extern void LogImageData(NSString *domain, int level, int width, int height, NSData *data);
  179. extern void LogImageDataF(const char *filename, int lineNumber, const char *functionName, NSString *domain, int level, int width, int height, NSData *data);
  180. extern void LogImageDataTo(Logger *logger, NSString *domain, int level, int width, int height, NSData *data);
  181. extern void LogImageDataToF(Logger *logger, const char *filename, int lineNumber, const char *functionName, NSString *domain, int level, int width, int height, NSData *data);
  182. // Mark the start of a block. This allows the remote logger to group blocks together
  183. extern void LogStartBlock(NSString *format, ...);
  184. extern void LogStartBlockTo(Logger *logger, NSString *format, ...);
  185. // Mark the end of a block
  186. extern void LogEndBlock(void);
  187. extern void LogEndBlockTo(Logger *logger);
  188. // Log a marker (text can be null)
  189. extern void LogMarker(NSString *text);
  190. extern void LogMarkerTo(Logger *logger, NSString *text);
  191. #ifdef __cplusplus
  192. };
  193. #endif