Sming Framework API
Sming - Open Source framework for high efficiency WiFi SoC ESP8266 native development with C++ language.
OsMessageInterceptor.h
1 /****
2  * Sming Framework Project - Open Source framework for high efficiency native ESP8266 development.
3  * Created 2015 by Skurydin Alexey
4  * http://github.com/SmingHub/Sming
5  * All files of the Sming Core are provided under the LGPL v3 license.
6  *
7  * OsMessageInterceptor.h - * Support for intercepting OS debug output (calls to os_printf, etc.)
8  *
9  * author mikee47 <mike@sillyhouse.net> Feb 2019
10  *
11  * Provided to assist with tracking down the origin of error messages output by SDK.
12  * This is usually done in conjunction with the debugger or by performing a stack dump
13  * to establish the origin of the problem code.
14  *
15  * Example usage:
16 
17  static OsMessageInterceptor osMessageInterceptor;
18 
19  void handleOsMessage(OsMessage& msg)
20  {
21  debug_w("[OS] %s", msg.getBuffer());
22  if(msg.startsWith("E:M ")) {
23  // Handle memory error
24  } else if(msg.contains(" assert ")) {
25  // Handle 'assert' message
26  }
27  }
28 
29  void init()
30  {
31  ...
32 
33  osMessageInterceptor.begin(handleOsMessage);
34 
35  // Example of 'bad' system call, generates "E:M 0" message
36  os_malloc(0);
37 
38  ...
39  }
40 
41  *
42  *
43  ****/
44 
45 #ifndef _SMING_CORE_PLATFORM_OS_MESSAGE_INTERCEPTOR_H_
46 #define _SMING_CORE_PLATFORM_OS_MESSAGE_INTERCEPTOR_H_
47 
48 #include "Data/Buffer/LineBuffer.h"
49 
54 
60 typedef void (*OsMessageCallback)(OsMessage& message);
61 
68 {
69 public:
71  {
72  end();
73  }
74 
81  void begin(OsMessageCallback callback);
82 
86  void end();
87 
88 protected:
89  void putc(char c);
90 
91  static void static_putc(char c)
92  {
93  self->putc(c);
94  }
95 
96 private:
97  OsMessage message;
98  OsMessageCallback callback = nullptr;
99  static OsMessageInterceptor* self;
100 };
101 
102 #endif /* _SMING_CORE_PLATFORM_OS_MESSAGE_INTERCEPTOR_H_ */
void end()
Stop message interception and revert to output via uart driver.
Class to handle interception of OS messages.
Definition: OsMessageInterceptor.h:67
void begin(OsMessageCallback callback)
Enable message interception.