From d7d78a515b45364ff0117d4e4a7febe49bb749c4 Mon Sep 17 00:00:00 2001 From: Ronan Abhamon Date: Tue, 29 Aug 2017 10:46:19 +0200 Subject: [PATCH] feat(enums): supports C export --- src/CMakeLists.txt | 1 + src/c-wrapper/c-types.cpp | 56 +++++++++++++++++++-------------- src/c-wrapper/c-types.h | 16 ++++++++-- src/db/events-db.cpp | 2 +- src/event-log/event-log-enums.h | 43 +++++++++++++++++++++++++ src/event-log/event-log-p.h | 2 +- src/event-log/event-log.h | 19 ++--------- src/utils/general.h | 18 +++++++++-- 8 files changed, 111 insertions(+), 46 deletions(-) create mode 100644 src/event-log/event-log-enums.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a28041712..7f2a446e5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -43,6 +43,7 @@ set(LINPHONE_CXX_OBJECTS_PRIVATE_HEADER_FILES event-log/conference-event-p.h event-log/conference-event.h event-log/conference-participant-event.h + event-log/event-log-enums.h event-log/event-log-p.h event-log/event-log.h event-log/message-event.h diff --git a/src/c-wrapper/c-types.cpp b/src/c-wrapper/c-types.cpp index 767d32833..06f6fcb7d 100644 --- a/src/c-wrapper/c-types.cpp +++ b/src/c-wrapper/c-types.cpp @@ -22,37 +22,47 @@ // From coreapi. #include "private.h" -#include "event-log/event-log.h" - +// Must be included before cpp headers. #include "c-types.h" +#include "event-log/event-log.h" + // ================================================================²============= using namespace std; extern "C" { #define L_DECLARE_C_STRUCT_IMPL(STRUCT) \ - struct _Linphone ## STRUCT { \ - belle_sip_object_t base; \ - shared_ptr cppPtr; \ - }; \ - static void _linphone_ ## STRUCT ## _uninit(Linphone ## STRUCT * object) { \ - object->cppPtr.reset(); \ - object->cppPtr->~STRUCT (); \ - } \ - static void _linphone_ ## STRUCT ## _clone(Linphone ## STRUCT * dest, const Linphone ## STRUCT * src) { \ - new(&dest->cppPtr) shared_ptr(); \ - dest->cppPtr = make_shared(*src->cppPtr.get()); \ - } \ - BELLE_SIP_DECLARE_VPTR_NO_EXPORT(Linphone ## STRUCT); \ - BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(Linphone ## STRUCT); \ - BELLE_SIP_INSTANCIATE_VPTR(Linphone ## STRUCT, belle_sip_object_t, \ - _linphone_ ## STRUCT ## _uninit, \ - _linphone_ ## STRUCT ## _clone, \ - NULL, \ - FALSE \ - ); + struct _Linphone ## STRUCT { \ + belle_sip_object_t base; \ + shared_ptr cppPtr; \ + }; \ + static void _linphone_ ## STRUCT ## _uninit(Linphone ## STRUCT * object) { \ + object->cppPtr.reset(); \ + object->cppPtr->~STRUCT (); \ + } \ + static void _linphone_ ## STRUCT ## _clone(Linphone ## STRUCT * dest, const Linphone ## STRUCT * src) { \ + new(&dest->cppPtr) shared_ptr(); \ + dest->cppPtr = make_shared(*src->cppPtr.get()); \ + } \ + BELLE_SIP_DECLARE_VPTR_NO_EXPORT(Linphone ## STRUCT); \ + BELLE_SIP_DECLARE_NO_IMPLEMENTED_INTERFACES(Linphone ## STRUCT); \ + BELLE_SIP_INSTANCIATE_VPTR(Linphone ## STRUCT, belle_sip_object_t, \ + _linphone_ ## STRUCT ## _uninit, \ + _linphone_ ## STRUCT ## _clone, \ + NULL, \ + FALSE \ + ); // ----------------------------------------------------------------------------- -L_DECLARE_C_STRUCT_IMPL(EventLog); + + L_DECLARE_C_STRUCT_IMPL(EventLog); + +LinphoneEventLog *event_log_new () { + return nullptr; +} + +LinphoneEventLogType event_log_get_type (const LinphoneEventLog *eventLog) { + return LinphoneEventLogType::NoneEvent; +} } diff --git a/src/c-wrapper/c-types.h b/src/c-wrapper/c-types.h index 24a73990b..9b1dad31a 100644 --- a/src/c-wrapper/c-types.h +++ b/src/c-wrapper/c-types.h @@ -19,17 +19,27 @@ #ifndef _C_TYPES_H_ #define _C_TYPES_H_ +#define L_DECLARE_ENUM(CLASS, ENUM) enum Linphone ## CLASS ## ENUM +#define L_DECLARE_C_STRUCT(STRUCT) typedef struct _Linphone ## STRUCT Linphone ## STRUCT; + +#include "event-log/event-log-enums.h" + // ============================================================================= #ifdef __cplusplus extern "C" { #endif -#define L_DECLARE_C_STRUCT(STRUCT) typedef struct _Linphone ## STRUCT Linphone ## STRUCT; +// ----------------------------------------------------------------------------- +// Event log. +// ----------------------------------------------------------------------------- -L_DECLARE_C_STRUCT(EventLog) +L_DECLARE_C_STRUCT(EventLog); -#undef L_DECLARE_C_STRUCT +LINPHONE_PUBLIC LinphoneEventLog *event_log_new (); +LINPHONE_PUBLIC LinphoneEventLogType event_log_get_type (const LinphoneEventLog *eventLog); + +// ----------------------------------------------------------------------------- #ifdef __cplusplus } diff --git a/src/db/events-db.cpp b/src/db/events-db.cpp index 60a28c116..284fc3509 100644 --- a/src/db/events-db.cpp +++ b/src/db/events-db.cpp @@ -252,7 +252,7 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {} bool EventsDb::addEvent (const EventLog &eventLog) { // TODO. switch (eventLog.getType()) { - case EventLog::None: + case EventLog::NoneEvent: return false; case EventLog::MessageEvent: case EventLog::CallStartEvent: diff --git a/src/event-log/event-log-enums.h b/src/event-log/event-log-enums.h new file mode 100644 index 000000000..1542fdf54 --- /dev/null +++ b/src/event-log/event-log-enums.h @@ -0,0 +1,43 @@ +/* + * event-log-enums.h + * Copyright (C) 2017 Belledonne Communications SARL + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef _EVENT_LOG_ENUMS_H_ +#define _EVENT_LOG_ENUMS_H_ + +#include "utils/general.h" + +// ============================================================================= + +L_DECLARE_ENUM(EventLog, Type) { + NoneEvent, + // MessageEvent. + MessageEvent, + // CallEvent. + CallStartEvent, + CallEndEvent, + // ConferenceEvent. + ConferenceCreatedEvent, + ConferenceDestroyedEvent, + // ConferenceParticipantEvent. + ConferenceParticipantAddedEvent, + ConferenceParticipantRemovedEvent, + ConferenceParticipantSetAdminEvent, + ConferenceParticipantUnsetAdminEvent +}; + +#endif // ifndef _EVENT_LOG_ENUMS_H_ diff --git a/src/event-log/event-log-p.h b/src/event-log/event-log-p.h index ce5507a17..e9e266178 100644 --- a/src/event-log/event-log-p.h +++ b/src/event-log/event-log-p.h @@ -28,7 +28,7 @@ LINPHONE_BEGIN_NAMESPACE class EventLogPrivate : public ClonableObjectPrivate { private: - EventLog::Type type = EventLog::None; + EventLog::Type type = EventLog::NoneEvent; L_DECLARE_PUBLIC(EventLog); }; diff --git a/src/event-log/event-log.h b/src/event-log/event-log.h index f83fa85e2..180a09e44 100644 --- a/src/event-log/event-log.h +++ b/src/event-log/event-log.h @@ -29,22 +29,7 @@ class EventLogPrivate; class LINPHONE_PUBLIC EventLog : public ClonableObject { public: - enum Type { - None, - // MessageEvent. - MessageEvent, - // CallEvent. - CallStartEvent, - CallEndEvent, - // ConferenceEvent. - ConferenceCreatedEvent, - ConferenceDestroyedEvent, - // ConferenceParticipantEvent. - ConferenceParticipantAddedEvent, - ConferenceParticipantRemovedEvent, - ConferenceParticipantSetAdminEvent, - ConferenceParticipantUnsetAdminEvent - }; + enum Type : int; EventLog (); EventLog (const EventLog &src); @@ -61,6 +46,8 @@ private: L_DECLARE_PRIVATE(EventLog); }; +#include "event-log-enums.h" + LINPHONE_END_NAMESPACE #endif // ifndef _EVENT_LOG_H_ diff --git a/src/utils/general.h b/src/utils/general.h index 243c7a7ca..2291c43eb 100644 --- a/src/utils/general.h +++ b/src/utils/general.h @@ -22,8 +22,14 @@ // ============================================================================= #define LINPHONE_NAMESPACE LinphonePrivate -#define LINPHONE_BEGIN_NAMESPACE namespace LINPHONE_NAMESPACE { -#define LINPHONE_END_NAMESPACE } + +#ifdef __cplusplus + #define LINPHONE_BEGIN_NAMESPACE namespace LINPHONE_NAMESPACE { + #define LINPHONE_END_NAMESPACE } +#else + #define LINPHONE_BEGIN_NAMESPACE + #define LINPHONE_END_NAMESPACE +#endif // ----------------------------------------------------------------------------- @@ -47,6 +53,12 @@ LINPHONE_BEGIN_NAMESPACE // ----------------------------------------------------------------------------- +#ifdef __cplusplus + +#ifndef L_DECLARE_ENUM + #define L_DECLARE_ENUM(CLASS, ENUM) enum CLASS::ENUM : int +#endif + void l_assert (const char *condition, const char *file, int line); #ifdef DEBUG @@ -117,6 +129,8 @@ inline const Object *getPublicHelper (const T *object, const ObjectPrivate *) { return *this; \ } +#endif + LINPHONE_END_NAMESPACE #endif // ifndef _GENERAL_H_