Commit d7d78a51 authored by Ronan's avatar Ronan

feat(enums): supports C export

parent 3e7e4cb5
......@@ -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
......
......@@ -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<LINPHONE_NAMESPACE::STRUCT> 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<LINPHONE_NAMESPACE::STRUCT>(); \
dest->cppPtr = make_shared<LINPHONE_NAMESPACE::STRUCT>(*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<LINPHONE_NAMESPACE::STRUCT> 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<LINPHONE_NAMESPACE::STRUCT>(); \
dest->cppPtr = make_shared<LINPHONE_NAMESPACE::STRUCT>(*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;
}
}
......@@ -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)
LINPHONE_PUBLIC LinphoneEventLog *event_log_new ();
LINPHONE_PUBLIC LinphoneEventLogType event_log_get_type (const LinphoneEventLog *eventLog);
#undef L_DECLARE_C_STRUCT
// -----------------------------------------------------------------------------
#ifdef __cplusplus
}
......
......@@ -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:
......
/*
* 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 <http://www.gnu.org/licenses/>.
*/
#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_
......@@ -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);
};
......
......@@ -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_
......@@ -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_
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment