maximkulkin / esp-homekit

Apple HomeKit accessory server library for ESP-OPEN-RTOS
MIT License
1.1k stars 169 forks source link

Wish for C++ - compatibility #116

Closed GermanSheepDog closed 4 years ago

GermanSheepDog commented 4 years ago

Hello Maxim,

I used your very good esp-homekit-library to control some equipment for example a freezer. It worked fine and since some month it is stable.

Now I integrate a gesture sensor and most libraries was written in C++. Only the library from manufacturer of ESP32 was written in C - but it didn't work for me.

So I need to integrate and mix C and C++. It would help me, if I can use esp-homekit-library without any change in my environment.

Please add this at your header-file "homekit.h":

#ifdef __cplusplus
   extern "C" {
#endif

// Get pairing URI
int homekit_get_setup_uri(const homekit_server_config_t *config,
                          char *buffer, size_t buffer_size);

#more function headers

int  homekit_client_send(unsigned char *data, size_t size);

#ifdef __cplusplus
  }
#endif

It is the same standard used in cJSON.h.

Many thanks in advance.

maximkulkin commented 4 years ago

If you want to call esp-homekit C API from your C++ code, just wrap #include statements with extern "C" {}:

#include <iostream>

extern "C" {
#include <homekit/homekit.h>
#include <homekit/characteristics.h>
}

This is a quick fix you can do right now, I will think about implementing it in the library itself.