Commit 752d89a8 authored by Ronan's avatar Ronan

feat(Enums): provide useful macros to share enums between C/C++

parent 93c17c21
......@@ -19,17 +19,12 @@
#ifndef _C_TYPES_H_
#define _C_TYPES_H_
// Do not move this define.
// Enable C enums.
#define L_USE_C_ENUM
// TODO: Remove me in the future.
#include "linphone/types.h"
#include "linphone/utils/enum-generator.h"
#include "linphone/enums/event-log-enums.h"
#define L_DECLARE_C_ENUM(CLASS, ENUM, VALUES) enum Linphone ## CLASS ## ENUM { VALUES }
// =============================================================================
#ifdef __cplusplus
......@@ -105,7 +100,7 @@ typedef struct _LinphoneParticipant LinphoneParticipant;
// C Enums.
// =============================================================================
L_DECLARE_C_ENUM(EventLog, Type, L_ENUM_VALUES_EVENT_LOG_TYPE);
L_DECLARE_C_ENUM(EventLogType, L_ENUM_VALUES_EVENT_LOG_TYPE);
#ifdef __cplusplus
}
......
......@@ -19,22 +19,18 @@
#ifndef _EVENT_LOG_ENUMS_H_
#define _EVENT_LOG_ENUMS_H_
#include "linphone/utils/enum-generator.h"
// =============================================================================
#define L_ENUM_VALUES_EVENT_LOG_TYPE \
L_DECLARE_ENUM_VALUES(EventLog, Type, \
None, \
Message, \
CallStart, \
CallEnd, \
ConferenceCreated, \
ConferenceDestroyed, \
ConferenceParticipantAdded, \
ConferenceParticipantRemoved, \
ConferenceParticipantSetAdmin, \
ConferenceParticipantUnsetAdmin \
)
#define L_ENUM_VALUES_EVENT_LOG_TYPE(F) \
F(None) \
F(Message) \
F(CallStart) \
F(CallEnd) \
F(ConferenceCreated) \
F(ConferenceDestroyed) \
F(ConferenceParticipantAdded) \
F(ConferenceParticipantRemoved) \
F(ConferenceParticipantSetAdmin) \
F(ConferenceParticipantUnsetAdmin)
#endif // ifndef _EVENT_LOG_ENUMS_H_
......@@ -25,15 +25,37 @@
LINPHONE_BEGIN_NAMESPACE
#define L_ENUM_VALUE(C, VALUE) C ## VALUE
#ifndef L_USE_C_ENUM
#define L_DECLARE_ENUM_VALUES(CLASS_NAME, ENUM_NAME, ...) \
MM_APPLY_COMMA(L_ENUM_VALUE, ENUM_NAME, __VA_ARGS__)
#else
#define L_DECLARE_ENUM_VALUES(CLASS_NAME, ENUM_NAME, ...) \
MM_APPLY_COMMA(L_ENUM_VALUE, Linphone ## CLASS_NAME ## ENUM_NAME, __VA_ARGS__)
#endif // ifndef L_USE_C_ENUM
// -----------------------------------------------------------------------------
// Low-level, do not call.
// -----------------------------------------------------------------------------
// Declare one enum value. `value` is optional, it can be generated.
// It's useful to force value in the case of mask.
#define L_DECLARE_ENUM_VALUE_1_ARGS(NAME) NAME,
#define L_DECLARE_ENUM_VALUE_2_ARGS(NAME, VALUE) NAME = VALUE,
// Call the right macro. (With or without value.)
#define L_DECLARE_ENUM_MACRO_CHOOSER(...) \
L_GET_ARG_3(__VA_ARGS__, L_DECLARE_ENUM_VALUE_2_ARGS, L_DECLARE_ENUM_VALUE_1_ARGS)
// Enum value declaration.
#define L_DECLARE_ENUM_VALUE(...) L_DECLARE_ENUM_MACRO_CHOOSER(__VA_ARGS__)(__VA_ARGS__)
// -----------------------------------------------------------------------------
// Public API.
// -----------------------------------------------------------------------------
#define L_DECLARE_ENUM(NAME, VALUES) \
enum class NAME { \
VALUES(L_DECLARE_ENUM_VALUE) \
};
#define L_C_ENUM_PREFIX Linphone
#define L_DECLARE_C_ENUM(NAME, VALUES) \
enum L_CONCAT(L_C_ENUM_PREFIX, NAME) { \
L_APPLY(L_CONCAT, L_CONCAT(L_C_ENUM_PREFIX, NAME), L_GET_HEAP(VALUES(L_DECLARE_ENUM_VALUE))) \
};
LINPHONE_END_NAMESPACE
......
This diff is collapsed.
......@@ -281,17 +281,17 @@ EventsDb::EventsDb () : AbstractDb(*new EventsDbPrivate) {}
// TODO.
switch (eventLog.getType()) {
case EventLog::TypeNone:
case EventLog::Type::None:
return false;
case EventLog::TypeMessage:
case EventLog::TypeCallStart:
case EventLog::TypeCallEnd:
case EventLog::TypeConferenceCreated:
case EventLog::TypeConferenceDestroyed:
case EventLog::TypeConferenceParticipantAdded:
case EventLog::TypeConferenceParticipantRemoved:
case EventLog::TypeConferenceParticipantSetAdmin:
case EventLog::TypeConferenceParticipantUnsetAdmin:
case EventLog::Type::Message:
case EventLog::Type::CallStart:
case EventLog::Type::CallEnd:
case EventLog::Type::ConferenceCreated:
case EventLog::Type::ConferenceDestroyed:
case EventLog::Type::ConferenceParticipantAdded:
case EventLog::Type::ConferenceParticipantRemoved:
case EventLog::Type::ConferenceParticipantSetAdmin:
case EventLog::Type::ConferenceParticipantUnsetAdmin:
break;
}
......
......@@ -36,7 +36,7 @@ public:
CallEvent::CallEvent (Type type, const shared_ptr<Call> &call) : EventLog(*new CallEventPrivate, type) {
L_D(CallEvent);
L_ASSERT(call);
L_ASSERT(type == TypeCallStart || type == TypeCallEnd);
L_ASSERT(type == Type::CallStart || type == Type::CallEnd);
d->call = call;
}
......
......@@ -30,7 +30,7 @@ LINPHONE_BEGIN_NAMESPACE
ConferenceEvent::ConferenceEvent (Type type, const shared_ptr<const Address> &address) :
EventLog(*new ConferenceEventPrivate, type) {
L_D(ConferenceEvent);
L_ASSERT(type == TypeConferenceCreated || type == TypeConferenceDestroyed);
L_ASSERT(type == Type::ConferenceCreated || type == Type::ConferenceDestroyed);
L_ASSERT(address);
d->address = make_shared<Address>(*address);
}
......
......@@ -41,10 +41,10 @@ ConferenceParticipantEvent::ConferenceParticipantEvent (
) : ConferenceEvent(*new ConferenceParticipantEventPrivate, type, conferenceAddress) {
L_D(ConferenceParticipantEvent);
L_ASSERT(
type == TypeConferenceParticipantAdded ||
type == TypeConferenceParticipantRemoved ||
type == TypeConferenceParticipantSetAdmin ||
type == TypeConferenceParticipantUnsetAdmin
type == Type::ConferenceParticipantAdded ||
type == Type::ConferenceParticipantRemoved ||
type == Type::ConferenceParticipantSetAdmin ||
type == Type::ConferenceParticipantUnsetAdmin
);
L_ASSERT(participantAddress);
d->participantAddress = make_shared<Address>(*participantAddress);
......
......@@ -28,7 +28,7 @@ LINPHONE_BEGIN_NAMESPACE
class EventLogPrivate : public ClonableObjectPrivate {
private:
EventLog::Type type = EventLog::TypeNone;
EventLog::Type type = EventLog::Type::None;
L_DECLARE_PUBLIC(EventLog);
};
......
......@@ -20,6 +20,7 @@
#define _EVENT_LOG_H_
#include "linphone/enums/event-log-enums.h"
#include "linphone/utils/enum-generator.h"
#include "object/clonable-object.h"
......@@ -31,9 +32,7 @@ class EventLogPrivate;
class LINPHONE_PUBLIC EventLog : public ClonableObject {
public:
enum Type {
L_ENUM_VALUES_EVENT_LOG_TYPE
};
L_DECLARE_ENUM(Type, L_ENUM_VALUES_EVENT_LOG_TYPE);
EventLog ();
EventLog (const EventLog &src);
......
......@@ -34,7 +34,7 @@ public:
// -----------------------------------------------------------------------------
MessageEvent::MessageEvent (const shared_ptr<Message> &message) :
EventLog(*new MessageEventPrivate, EventLog::TypeMessage) {
EventLog(*new MessageEventPrivate, EventLog::Type::Message) {
L_D(MessageEvent);
L_ASSERT(message);
d->message = message;
......
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