• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2023 The Pigweed Authors
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); you may not
4 // use this file except in compliance with the License. You may obtain a copy of
5 // the License at
6 //
7 //     https://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 // License for the specific language governing permissions and limitations under
13 // the License.
14 
15 // If the project is still using pw_tokenizer's global handler with payload
16 // facade, then define its functions as used by pw_log_tokenized.
17 
18 #include <cstdarg>
19 
20 #include "pw_log_tokenized/handler.h"
21 #include "pw_preprocessor/compiler.h"
22 #include "pw_tokenizer/encode_args.h"
23 #include "pw_tokenizer/tokenize_to_global_handler_with_payload.h"
24 
25 // If the new API is in use, define pw_tokenizer_HandleEncodedMessageWithPayload
26 // to redirect to it, in case there are any direct calls to it. Only projects
27 // that use the base64_over_hdlc backend will have been updated to the new API.
28 #if PW_LOG_TOKENIZED_BACKEND_USES_NEW_API
29 
pw_tokenizer_HandleEncodedMessageWithPayload(uint32_t metadata,const uint8_t encoded_message[],size_t size_bytes)30 extern "C" void pw_tokenizer_HandleEncodedMessageWithPayload(
31     uint32_t metadata, const uint8_t encoded_message[], size_t size_bytes) {
32   pw_log_tokenized_HandleLog(metadata, encoded_message, size_bytes);
33 }
34 
35 #else  // If the new API is not in use, implement it to redirect to the old API.
36 
pw_log_tokenized_HandleLog(uint32_t metadata,const uint8_t encoded_message[],size_t size_bytes)37 extern "C" void pw_log_tokenized_HandleLog(uint32_t metadata,
38                                            const uint8_t encoded_message[],
39                                            size_t size_bytes) {
40   pw_tokenizer_HandleEncodedMessageWithPayload(
41       metadata, encoded_message, size_bytes);
42 }
43 
44 #endif  // PW_LOG_TOKENIZED_BACKEND_USES_NEW_API
45 
46 // Implement the global tokenized log handler function, which is identical
47 // This function is the same as _pw_log_tokenized_EncodeTokenizedLog().
_pw_tokenizer_ToGlobalHandlerWithPayload(uint32_t metadata,pw_tokenizer_Token token,pw_tokenizer_ArgTypes types,...)48 extern "C" void _pw_tokenizer_ToGlobalHandlerWithPayload(
49     uint32_t metadata,
50     pw_tokenizer_Token token,
51     pw_tokenizer_ArgTypes types,
52     ...) {
53   va_list args;
54   va_start(args, types);
55   pw::tokenizer::EncodedMessage<> encoded_message(token, types, args);
56   va_end(args);
57 
58   pw_log_tokenized_HandleLog(
59       metadata, encoded_message.data_as_uint8(), encoded_message.size());
60 }
61