mbedConnectorInterface back port from mbedOS v3 using mbed-client C++ call interface

Committer:
ansond
Date:
Fri Feb 19 17:32:14 2016 +0000
Revision:
0:1f1f55e73248
Child:
14:d9ce4e56684e
initial checkin

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ansond 0:1f1f55e73248 1 /**
ansond 0:1f1f55e73248 2 * @file Logger.cpp
ansond 0:1f1f55e73248 3 * @brief mbed CoAP Endpoint logging class
ansond 0:1f1f55e73248 4 * @author Doug Anson/Chris Paola
ansond 0:1f1f55e73248 5 * @version 1.0
ansond 0:1f1f55e73248 6 * @see
ansond 0:1f1f55e73248 7 *
ansond 0:1f1f55e73248 8 * Copyright (c) 2014
ansond 0:1f1f55e73248 9 *
ansond 0:1f1f55e73248 10 * Licensed under the Apache License, Version 2.0 (the "License");
ansond 0:1f1f55e73248 11 * you may not use this file except in compliance with the License.
ansond 0:1f1f55e73248 12 * You may obtain a copy of the License at
ansond 0:1f1f55e73248 13 *
ansond 0:1f1f55e73248 14 * http://www.apache.org/licenses/LICENSE-2.0
ansond 0:1f1f55e73248 15 *
ansond 0:1f1f55e73248 16 * Unless required by applicable law or agreed to in writing, software
ansond 0:1f1f55e73248 17 * distributed under the License is distributed on an "AS IS" BASIS,
ansond 0:1f1f55e73248 18 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
ansond 0:1f1f55e73248 19 * See the License for the specific language governing permissions and
ansond 0:1f1f55e73248 20 * limitations under the License.
ansond 0:1f1f55e73248 21 */
ansond 0:1f1f55e73248 22
ansond 0:1f1f55e73248 23 #include "mbed-connector-interface/Logger.h"
ansond 0:1f1f55e73248 24
ansond 0:1f1f55e73248 25 // Constructor
ansond 0:1f1f55e73248 26 Logger::Logger(const Serial *pc)
ansond 0:1f1f55e73248 27 {
ansond 0:1f1f55e73248 28 this->m_pc = (Serial *)pc;
ansond 0:1f1f55e73248 29 }
ansond 0:1f1f55e73248 30
ansond 0:1f1f55e73248 31 // Copy Constructor
ansond 0:1f1f55e73248 32 Logger::Logger(const Logger &logger)
ansond 0:1f1f55e73248 33 {
ansond 0:1f1f55e73248 34 this->m_pc = logger.m_pc;
ansond 0:1f1f55e73248 35 }
ansond 0:1f1f55e73248 36
ansond 0:1f1f55e73248 37 // Destructor
ansond 0:1f1f55e73248 38 Logger::~Logger()
ansond 0:1f1f55e73248 39 {
ansond 0:1f1f55e73248 40 }
ansond 0:1f1f55e73248 41
ansond 0:1f1f55e73248 42 // Log the ouput to the attached serial console
ansond 0:1f1f55e73248 43 void Logger::logIt(const char *format,...)
ansond 0:1f1f55e73248 44 {
ansond 0:1f1f55e73248 45 // build the variable args into a string
ansond 0:1f1f55e73248 46 va_list args;
ansond 0:1f1f55e73248 47 char buffer[LOGGER_BUFFER_LENGTH+1];
ansond 0:1f1f55e73248 48 memset(buffer,0,LOGGER_BUFFER_LENGTH+1);
ansond 0:1f1f55e73248 49 va_start(args, format);
ansond 0:1f1f55e73248 50 vsnprintf(buffer,LOGGER_BUFFER_LENGTH,format,args);
ansond 0:1f1f55e73248 51
ansond 0:1f1f55e73248 52 // clean up...
ansond 0:1f1f55e73248 53 va_end(args);
ansond 0:1f1f55e73248 54
ansond 0:1f1f55e73248 55 // print it...
ansond 0:1f1f55e73248 56 if (this->m_pc != NULL)
ansond 0:1f1f55e73248 57 this->m_pc->printf("%s",buffer);
ansond 0:1f1f55e73248 58 // else
ansond 0:1f1f55e73248 59 // std::printf("%s",buffer);
ansond 0:1f1f55e73248 60 }
ansond 0:1f1f55e73248 61