Skip to content

Commit

Permalink
c++ support experiment, tested ok on mk3060, esp32
Browse files Browse the repository at this point in the history
  • Loading branch information
librae8226 committed Dec 13, 2017
1 parent eeb585f commit a2cff3b
Show file tree
Hide file tree
Showing 6 changed files with 191 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/aos/internal/log_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ extern int csp_printf(const char *fmt, ...);
#define log_print(CON, MOD, COLOR, LVL, FMT, ...) \
do { \
if (CON) { \
csp_printf("[%06d]<" LVL "> "FMT"\n", (unsigned)aos_now_ms(), ##__VA_ARGS__); \
csp_printf("[%06d]<" LVL "> " FMT "\n", (unsigned)aos_now_ms(), ##__VA_ARGS__); \
} \
} while (0)

Expand Down
56 changes: 56 additions & 0 deletions sketch/cpp_class.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (C) 2014 Hamburg University of Applied Sciences (HAW)
* Copyright (C) 2014 Ho Chi Minh city University of Technology (HCMUT)
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @ingroup examples
* @{
*
* @file
* @brief implementation of declared functions of object cpp_class
*
* @author Martin Landsmann <martin.landsmann@haw-hamburg.de>
* @author DangNhat Pham-Huu <51002279@hcmut.edu.vn>
*
* @}
*/

#include <cstdio>
#include "cpp_class.h"

cpp_class::cpp_class()
{
printf("Instanciating Object [constructor called]\n");
greet();
}

cpp_class::~cpp_class()
{
printf("Destroying Object [destructor called]\n");
printf("Im shutting down!\n");
}

void cpp_class::say_hello(void)
{
printf("Hello!\n");
}

void cpp_class::say_hello(int n)
{
printf("Hello![int: %d]\n", n);
}

void cpp_class::say_hello(float f)
{
printf("Hello![float: %f]\n", f);
}

void cpp_class::greet(void)
{
printf("Im starting!\n");
}
64 changes: 64 additions & 0 deletions sketch/cpp_class.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Copyright (C) 2014 Hamburg University of Applied Sciences (HAW)
* Copyright (C) 2014 Ho Chi Minh city University of Technology (HCMUT)
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/

/**
* @defgroup
* @brief
* @ingroup examples
* @{
*
* @file
* @brief simple c++ object declaration with public and private functions
*
* @author Martin Landsmann <martin.landsmann@haw-hamburg.de>
* @author DangNhat Pham-Huu <51002279@stu.hcmut.edu.vn>
*/

#ifndef CPP_CLASS_H
#define CPP_CLASS_H

class cpp_class
{
public:
/**
* @brief constructor
*/
cpp_class();

/**
* @brief destructor
*/
~cpp_class();

/**
* @brief public function
*/
void say_hello(void);

/**
* @brief overloaded public function with int parameter
*/
void say_hello(int n);

/**
* @brief overloaded public function with float parameter
*/
void say_hello(float f);
private:
/**
* @brief private function
*/
void greet(void);
};

void setup(void);
void loop(void);

/** @} */
#endif /* CPP_CLASS_H */
9 changes: 9 additions & 0 deletions sketch/ino.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#include "cpp_class.h"

void setup() {
cpp_class cpp_obj;
cpp_obj.say_hello((float)3.141592653);
}

void loop() {
}
35 changes: 35 additions & 0 deletions sketch/sketch.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright (C) 2015-2017 Alibaba Group Holding Limited
*/

#if defined (__cplusplus)
extern "C" {
#endif
#include <aos/aos.h>
#include <assert.h>
#if defined (__cplusplus)
}
#endif
#include <cstdio>
#include "cpp_class.h"

static void app_delayed_action(void *arg)
{
LOG("%s:%d %s\r\n", __func__, __LINE__, aos_task_name());
aos_post_delayed_action(5000, app_delayed_action, NULL);
}

extern "C" int application_start(int argc, char *argv[])
{
cpp_class cpp_obj;

aos_post_delayed_action(1000, app_delayed_action, NULL);

printf("hello\n");
cpp_obj.say_hello(42);
setup();

aos_loop_run();

return 0;
}
26 changes: 26 additions & 0 deletions sketch/sketch.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
NAME := sketch

$(NAME)_SOURCES := \
sketch.cpp \
cpp_class.cpp \
ino.cpp

GLOBAL_DEFINES += AOS_NO_WIFI

$(NAME)_COMPONENTS := yloop cli

#$(NAME)_CXXFLAGS := -std=c++11 -fno-rtti -fno-exceptions

ifeq ($(BENCHMARKS),1)
$(NAME)_COMPONENTS += benchmarks
GLOBAL_DEFINES += CONFIG_CMD_BENCHMARKS
endif

ifneq (,${BINS})
GLOBAL_CFLAGS += -DSYSINFO_OS_BINS
endif

CURRENT_TIME = $(shell /bin/date +%Y%m%d.%H%M)
CONFIG_SYSINFO_APP_VERSION = APP-1.0.0-$(CURRENT_TIME)
$(info app_version:${CONFIG_SYSINFO_APP_VERSION})
GLOBAL_CFLAGS += -DSYSINFO_APP_VERSION=\"$(CONFIG_SYSINFO_APP_VERSION)\"

0 comments on commit a2cff3b

Please sign in to comment.