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