diff --git a/coreapi/private_functions.h b/coreapi/private_functions.h index 74d67075c535e2df1e50eb4bd608f1254b0ee0ba..24608a5369bb3d2b312435070e177b719ea0d036 100644 --- a/coreapi/private_functions.h +++ b/coreapi/private_functions.h @@ -666,6 +666,16 @@ void linphone_xml_rpc_request_set_current_callbacks(LinphoneXmlRpcRequest *reque void linphone_core_invalidate_friends_maps(LinphoneCore *lc); +// The following methods are private and they allow a conversion from conference state enum to chat room state enum and viceversa. +// This allows to easily go from one type to another one ensuring that they are synchronized and ease debugging in case they are not +// Note that these methods must be updated if either the value of conference state or chat room state change. +// The compiler will throw an error if not doing it: +// <pathToLiblinphone>/src/c-wrapper/api/c-chat-room.cpp: In function ‘LinphoneChatRoomState linphone_conference_state_to_chat_room_state(LinphoneConferenceState)’: +// <pathToLiblinphone>/src/c-wrapper/api/c-chat-room.cpp:676:9: error: enumeration value ‘<name>’ not handled in switch [-Werror=switch] +LinphoneConferenceState linphone_chat_room_state_to_conference_state(LinphoneChatRoomState state); +LinphoneChatRoomState linphone_conference_state_to_chat_room_state(LinphoneConferenceState state); + + #ifdef __cplusplus } #endif diff --git a/include/linphone/api/c-chat-room.h b/include/linphone/api/c-chat-room.h index 976ff94af2fefbf5626fa80551e357b406848d4e..32352a5ffd91ca84bc38e9a7348d1a683f3937fd 100644 --- a/include/linphone/api/c-chat-room.h +++ b/include/linphone/api/c-chat-room.h @@ -579,7 +579,6 @@ LINPHONE_PUBLIC LINPHONE_DEPRECATED void linphone_chat_room_send_chat_message(Li */ LINPHONE_PUBLIC LINPHONE_DEPRECATED LinphoneChatMessage* linphone_chat_room_create_message(LinphoneChatRoom *chat_room,const char* message); - /** * @} */ diff --git a/src/c-wrapper/api/c-chat-room.cpp b/src/c-wrapper/api/c-chat-room.cpp index a0aa8103ddff48569a5a9488be15ffdec9077721..d3ec7330f0ac26eea95d6fb069d02dc5271753d3 100644 --- a/src/c-wrapper/api/c-chat-room.cpp +++ b/src/c-wrapper/api/c-chat-room.cpp @@ -316,7 +316,7 @@ LinphoneChatMessage *linphone_chat_room_find_message (LinphoneChatRoom *cr, cons } LinphoneChatRoomState linphone_chat_room_get_state (const LinphoneChatRoom *cr) { - return (LinphoneChatRoomState)L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getState(); + return linphone_conference_state_to_chat_room_state(static_cast<LinphoneConferenceState>(L_GET_CPP_PTR_FROM_C_OBJECT(cr)->getState())); } bool_t linphone_chat_room_has_been_left (const LinphoneChatRoom *cr) { @@ -643,3 +643,55 @@ LinphoneChatRoom *_linphone_server_group_chat_room_new (LinphoneCore *core, Linp return NULL; #endif } + +// Convert chat room enum to conference state enum +LinphoneConferenceState linphone_chat_room_state_to_conference_state(LinphoneChatRoomState state) { + // No default statement to trigger an error in case a new value is added to LinphoneChatRoomState + switch (state) { + case LinphoneChatRoomStateNone: + return LinphoneConferenceStateNone; + case LinphoneChatRoomStateInstantiated: + return LinphoneConferenceStateInstantiated; + case LinphoneChatRoomStateCreationPending: + return LinphoneConferenceStateCreationPending; + case LinphoneChatRoomStateCreated: + return LinphoneConferenceStateCreated; + case LinphoneChatRoomStateCreationFailed: + return LinphoneConferenceStateCreationFailed; + case LinphoneChatRoomStateTerminationPending: + return LinphoneConferenceStateTerminationPending; + case LinphoneChatRoomStateTerminated: + return LinphoneConferenceStateTerminated; + case LinphoneChatRoomStateTerminationFailed: + return LinphoneConferenceStateTerminationFailed; + case LinphoneChatRoomStateDeleted: + return LinphoneConferenceStateDeleted; + } + return LinphoneConferenceStateNone; +} + +// Convert conference state enum to chat room state enum +LinphoneChatRoomState linphone_conference_state_to_chat_room_state(LinphoneConferenceState state) { + // No default statement to trigger an error in case a new value is added to LinphoneConferenceState + switch (state) { + case LinphoneConferenceStateNone: + return LinphoneChatRoomStateNone; + case LinphoneConferenceStateInstantiated: + return LinphoneChatRoomStateInstantiated; + case LinphoneConferenceStateCreationPending: + return LinphoneChatRoomStateCreationPending; + case LinphoneConferenceStateCreated: + return LinphoneChatRoomStateCreated; + case LinphoneConferenceStateCreationFailed: + return LinphoneChatRoomStateCreationFailed; + case LinphoneConferenceStateTerminationPending: + return LinphoneChatRoomStateTerminationPending; + case LinphoneConferenceStateTerminated: + return LinphoneChatRoomStateTerminated; + case LinphoneConferenceStateTerminationFailed: + return LinphoneChatRoomStateTerminationFailed; + case LinphoneConferenceStateDeleted: + return LinphoneChatRoomStateDeleted; + } + return LinphoneChatRoomStateNone; +} diff --git a/src/chat/chat-room/chat-room.cpp b/src/chat/chat-room/chat-room.cpp index 683c96d6884fbbc362124c13826beb404c9959cc..a34f33ff95aa9ef0d1f22f15412c1862af07564d 100644 --- a/src/chat/chat-room/chat-room.cpp +++ b/src/chat/chat-room/chat-room.cpp @@ -263,10 +263,11 @@ void ChatRoomPrivate::notifyStateChanged () { if (q->getCore()->getCCore()->state == LinphoneGlobalStartup) { lDebug() << "Chat room [" << q->getConferenceId() << "] state changed to: " << Utils::toString(q->getState()); } else { - lInfo() << "Chat room [" << q->getConferenceId() << "] state changed to: " << q->getState(); + lInfo() << "Chat room [" << q->getConferenceId() << "] state changed to: " << Utils::toString(q->getState()); } - linphone_core_notify_chat_room_state_changed(q->getCore()->getCCore(), cr, (LinphoneChatRoomState)q->getState()); - _linphone_chat_room_notify_state_changed(cr, (LinphoneChatRoomState)q->getState()); + LinphoneChatRoomState chatRoomCState = linphone_conference_state_to_chat_room_state(static_cast<LinphoneConferenceState>(q->getState())); + linphone_core_notify_chat_room_state_changed(q->getCore()->getCCore(), cr, chatRoomCState); + _linphone_chat_room_notify_state_changed(cr, chatRoomCState); } void ChatRoomPrivate::notifyUndecryptableChatMessageReceived (const shared_ptr<ChatMessage> &chatMessage) {