Skip to content
This repository has been archived by the owner on Nov 10, 2021. It is now read-only.

Commit

Permalink
Add extern "C" for use in C++ builds
Browse files Browse the repository at this point in the history
The following was added to the header files
so they could be include in C++ programs:

    #ifdef __cplusplus
    extern "C"
    {
    #endif

    //C functions here

    #ifdef __cplusplus
    }
    #endif

With this added the extern "C" was removed from
the unittest code since it was will no longer be
needed.

Change-Id: Ifcea38413dde9b0d94c04a9e3d2925a3b63eb63f
Signed-off-by: George Nash <george.nash@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/26745
Tested-by: IoTivity Jenkins <jenkins-daemon@iotivity.org>
Reviewed-by: Kishen Maloor <kishen.maloor@intel.com>
  • Loading branch information
georgen117 authored and kmaloor committed Aug 13, 2018
1 parent 22bbbc9 commit f70c7f3
Show file tree
Hide file tree
Showing 78 changed files with 686 additions and 36 deletions.
9 changes: 9 additions & 0 deletions api/oc_events.h
Expand Up @@ -19,6 +19,11 @@

#include "util/oc_process.h"

#ifdef __cplusplus
extern "C"
{
#endif

typedef enum {
INBOUND_NETWORK_EVENT,
UDP_TO_TLS_EVENT,
Expand All @@ -35,4 +40,8 @@ typedef enum {

extern oc_process_event_t oc_events[];

#ifdef __cplusplus
}
#endif

#endif /* OC_EVENTS_H */
12 changes: 6 additions & 6 deletions api/unittest/RITest.cpp
Expand Up @@ -22,12 +22,12 @@
#include <string>
#include <stdio.h>
#include <gtest/gtest.h>
extern "C" {
#include "port/linux/config.h"
#include "oc_api.h"
#include "oc_ri.h"
#include "oc_helpers.h"
}

#include "port/linux/config.h"
#include "oc_api.h"
#include "oc_ri.h"
#include "oc_helpers.h"


#define RESOURCE_URI "/LightResourceURI"
#define RESOURCE_NAME "roomlights"
Expand Down
10 changes: 5 additions & 5 deletions api/unittest/coreresourcetest.cpp
Expand Up @@ -22,11 +22,11 @@
#include <string>
#include <stdio.h>
#include <gtest/gtest.h>
extern "C" {
#include "oc_core_res.h"
#include "oc_api.h"
#include "oc_helpers.h"
}

#include "oc_core_res.h"
#include "oc_api.h"
#include "oc_helpers.h"

#define DEVICE_URI "/oic/d"
#define DEVICE_TYPE "oic.d.light"
#define MANUFACTURER_NAME "Samsung"
Expand Down
6 changes: 2 additions & 4 deletions api/unittest/ocapitest.cpp
Expand Up @@ -22,10 +22,8 @@
#include <string>
#include <gtest/gtest.h>

extern "C" {
#include "oc_api.h"
#include "port/oc_clock.h"
}
#include "oc_api.h"
#include "port/oc_clock.h"

#define MAX_WAIT_TIME 10
#define RESOURCE_URI "/LightResourceURI"
Expand Down
5 changes: 2 additions & 3 deletions api/unittest/reptest.cpp
Expand Up @@ -21,9 +21,8 @@

#include <stdlib.h>
#include "gtest/gtest.h"
extern "C" {
#include "oc_rep.h"
}

#include "oc_rep.h"

TEST(TestRep, OCRepFinalizeTest_P)
{
Expand Down
4 changes: 1 addition & 3 deletions api/unittest/uuidtest.cpp
Expand Up @@ -21,9 +21,7 @@
#include <cstdlib>
#include "gtest/gtest.h"

extern "C" {
#include "oc_uuid.h"
}
#include "oc_uuid.h"

#define UUID "12345678123412341234123456789012"

Expand Down
18 changes: 18 additions & 0 deletions include/oc_api.h
Expand Up @@ -36,6 +36,11 @@
#include "oc_signal_event_loop.h"
#include "port/oc_storage.h"

#ifdef __cplusplus
extern "C"
{
#endif

typedef struct {
int (*init)(void);
void (*signal_event_loop)(void);
Expand Down Expand Up @@ -304,9 +309,18 @@ void oc_send_separate_response(oc_separate_response_t *handle,

int oc_notify_observers(oc_resource_t *resource);

#ifdef __cplusplus
}
#endif

/** Client side */
#include "oc_client_state.h"

#ifdef __cplusplus
extern "C"
{
#endif

bool oc_do_ip_discovery(const char *rt, oc_discovery_handler_t handler,
void *user_data);

Expand Down Expand Up @@ -385,4 +399,8 @@ void oc_remove_delayed_callback(void *cb_data, oc_trigger_t callback);
} \
void name##_interrupt_x_handler(void)

#ifdef __cplusplus
}
#endif

#endif /* OC_API_H */
9 changes: 9 additions & 0 deletions include/oc_base64.h
Expand Up @@ -20,6 +20,11 @@
#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
extern "C"
{
#endif

/**
* encode byte buffer to base64 string. The base64 encoder does not NUL terminate
* its output. User the return value to add '\0' to the end of the string.
Expand Down Expand Up @@ -76,4 +81,8 @@ int oc_base64_encode(const uint8_t *input, size_t input_len,
*/
int oc_base64_decode(uint8_t *str, size_t len);

#ifdef __cplusplus
}
#endif

#endif /* OC_BASE64_H */
9 changes: 9 additions & 0 deletions include/oc_blockwise.h
Expand Up @@ -23,6 +23,11 @@
#include "oc_ri.h"
#include "port/oc_connectivity.h"

#ifdef __cplusplus
extern "C"
{
#endif

typedef enum {
OC_BLOCKWISE_CLIENT = 0,
OC_BLOCKWISE_SERVER
Expand Down Expand Up @@ -109,4 +114,8 @@ void oc_blockwise_scrub_buffers(void);

void oc_blockwise_scrub_buffers_for_client_cb(void *cb);

#ifdef __cplusplus
}
#endif

#endif /* OC_BLOCKWISE_H */
9 changes: 9 additions & 0 deletions include/oc_buffer.h
Expand Up @@ -22,6 +22,11 @@
#include "util/oc_process.h"
#include <stdbool.h>

#ifdef __cplusplus
extern "C"
{
#endif

OC_PROCESS_NAME(message_buffer_handler);
oc_message_t *oc_allocate_message(void);
void oc_set_buffers_avail_cb(oc_memb_buffers_avail_callback_t cb);
Expand All @@ -36,4 +41,8 @@ void oc_message_unref(oc_message_t *message);
void oc_recv_message(oc_message_t *message);
void oc_send_message(oc_message_t *message);

#ifdef __cplusplus
}
#endif

#endif /* OC_BUFFER_H */
10 changes: 10 additions & 0 deletions include/oc_buffer_settings.h
Expand Up @@ -17,9 +17,19 @@
#ifndef OC_BUFFER_SETTINGS_H
#define OC_BUFFER_SETTINGS_H

#ifdef __cplusplus
extern "C"
{
#endif

int oc_set_mtu_size(size_t mtu_size);
long oc_get_mtu_size(void);
void oc_set_max_app_data_size(size_t size);
long oc_get_max_app_data_size(void);
long oc_get_block_size(void);

#ifdef __cplusplus
}
#endif

#endif /* OC_BUFFER_SETTINGS_H */
9 changes: 9 additions & 0 deletions include/oc_client_state.h
Expand Up @@ -25,6 +25,11 @@
#include "oc_blockwise.h"
#endif /* OC_BLOCK_WISE */

#ifdef __cplusplus
extern "C"
{
#endif

typedef enum { HIGH_QOS = 0, LOW_QOS } oc_qos_t;

typedef struct
Expand Down Expand Up @@ -102,4 +107,8 @@ oc_discovery_flags_t oc_ri_process_discovery_payload(
uint8_t *payload, int len, oc_discovery_handler_t handler,
oc_endpoint_t *endpoint, void *user_data);

#ifdef __cplusplus
}
#endif

#endif /* OC_CLIENT_STATE_H */
9 changes: 9 additions & 0 deletions include/oc_collection.h
Expand Up @@ -20,6 +20,11 @@
#include "oc_ri.h"
#include "util/oc_list.h"

#ifdef __cplusplus
extern "C"
{
#endif

struct oc_link_s
{
struct oc_link_s *next;
Expand Down Expand Up @@ -58,4 +63,8 @@ oc_link_t *oc_get_link_by_uri(oc_collection_t *collection, const char *uri_path,
bool oc_check_if_collection(oc_resource_t *resource);
void oc_collection_add(oc_collection_t *collection);

#ifdef __cplusplus
}
#endif

#endif /* OC_COLLECTION_H */
9 changes: 9 additions & 0 deletions include/oc_core_res.h
Expand Up @@ -19,6 +19,11 @@

#include "oc_ri.h"

#ifdef __cplusplus
extern "C"
{
#endif

typedef void (*oc_core_init_platform_cb_t)(void *data);
typedef void (*oc_core_add_device_cb_t)(void *data);

Expand Down Expand Up @@ -83,4 +88,8 @@ void oc_core_regen_unique_ids(size_t device);

bool oc_filter_resource_by_rt(oc_resource_t *resource, oc_request_t *request);

#ifdef __cplusplus
}
#endif

#endif /* OC_CORE_RES_H */
9 changes: 9 additions & 0 deletions include/oc_discovery.h
Expand Up @@ -17,6 +17,15 @@
#ifndef OC_DISCOVERY_H
#define OC_DISCOVERY_H

#ifdef __cplusplus
extern "C"
{
#endif

void oc_create_discovery_resource(int resource_idx, size_t device);

#ifdef __cplusplus
}
#endif

#endif /* OC_DISCOVERY_H */
9 changes: 9 additions & 0 deletions include/oc_endpoint.h
Expand Up @@ -19,6 +19,11 @@

#include "oc_helpers.h"

#ifdef __cplusplus
extern "C"
{
#endif

typedef enum { OCF_VER_1_0_0 = 2048, OIC_VER_1_1_0 = 2112 } ocf_version_t;

typedef struct
Expand Down Expand Up @@ -86,4 +91,8 @@ int oc_ipv6_endpoint_is_link_local(oc_endpoint_t *endpoint);
int oc_endpoint_compare(const oc_endpoint_t *ep1, const oc_endpoint_t *ep2);
int oc_endpoint_compare_address(oc_endpoint_t *ep1, oc_endpoint_t *ep2);

#ifdef __cplusplus
}
#endif

#endif /* OC_ENDPOINT_H */
9 changes: 9 additions & 0 deletions include/oc_helpers.h
Expand Up @@ -24,6 +24,11 @@
#include <stdio.h>
#include <string.h>

#ifdef __cplusplus
extern "C"
{
#endif

typedef struct oc_mmem oc_handle_t, oc_string_t, oc_array_t, oc_string_array_t;

#define oc_cast(block, type) ((type *)(OC_MMEM_PTR(&(block))))
Expand Down Expand Up @@ -149,4 +154,8 @@ void _oc_alloc_string_array(
#endif
oc_string_array_t *ocstringarray, size_t size);

#ifdef __cplusplus
}
#endif

#endif /* OC_HELPERS_H */
8 changes: 8 additions & 0 deletions include/oc_introspection.h
Expand Up @@ -17,6 +17,11 @@
#ifndef OC_INTROSPECTION_H
#define OC_INTROSPECTION_H

#ifdef __cplusplus
extern "C"
{
#endif

/**
* @brief functions for introspection .
* The introspection mechanism is implemented by 2 different mechanisms
Expand Down Expand Up @@ -56,5 +61,8 @@ void oc_set_introspection_file(size_t device, const char* filename);
*/
void oc_create_introspection_resource(size_t device);

#ifdef __cplusplus
}
#endif

#endif /* OC_INTROSPECTION_H */
9 changes: 9 additions & 0 deletions include/oc_network_events.h
Expand Up @@ -20,6 +20,11 @@
#include "port/oc_network_events_mutex.h"
#include "util/oc_process.h"

#ifdef __cplusplus
extern "C"
{
#endif

typedef enum {
NETWORK_INTERFACE_DOWN,
NETWORK_INTERFACE_UP
Expand Down Expand Up @@ -49,4 +54,8 @@ void oc_network_event(oc_message_t *message);

void oc_network_interface_event(oc_interface_event_t event);

#ifdef __cplusplus
}
#endif

#endif /* OC_NETWORK_EVENTS_H */
9 changes: 9 additions & 0 deletions include/oc_network_monitor.h
Expand Up @@ -22,6 +22,11 @@
#include "oc_network_events.h"
#include "oc_session_events.h"

#ifdef __cplusplus
extern "C"
{
#endif

/**
@brief Add the callback to receive change notifications for
Network interface event.
Expand Down Expand Up @@ -54,4 +59,8 @@ int oc_add_session_event_callback(session_event_handler_t cb);
*/
int oc_remove_session_event_callback(session_event_handler_t cb);

#ifdef __cplusplus
}
#endif

#endif /* OC_NETWORK_HELPERS_H */

0 comments on commit f70c7f3

Please sign in to comment.