Commit 4adfec37 authored by Ronan's avatar Ronan

fix(ChatMessage): use const, always use const, it is cute and useful

parent 83e1fe3e
Pipeline #315 failed with stage
in 0 seconds
......@@ -88,28 +88,28 @@ LINPHONE_PUBLIC time_t linphone_chat_message_get_time (const LinphoneChatMessage
* Returns TRUE if the message has been sent, returns FALSE if the message has been received.
* @param[in] msg #LinphoneChatMessage object.
*/
LINPHONE_PUBLIC bool_t linphone_chat_message_is_outgoing (LinphoneChatMessage *msg);
LINPHONE_PUBLIC bool_t linphone_chat_message_is_outgoing (const LinphoneChatMessage *msg);
/**
* Get origin of the message
* @param[in] msg #LinphoneChatMessage object.
* @return #LinphoneAddress
*/
LINPHONE_PUBLIC const LinphoneAddress *linphone_chat_message_get_from_address (LinphoneChatMessage *msg);
LINPHONE_PUBLIC const LinphoneAddress *linphone_chat_message_get_from_address (const LinphoneChatMessage *msg);
/**
* Get destination of the message
* @param[in] msg #LinphoneChatMessage object.
* @return #LinphoneAddress
*/
LINPHONE_PUBLIC const LinphoneAddress *linphone_chat_message_get_to_address (LinphoneChatMessage *msg);
LINPHONE_PUBLIC const LinphoneAddress *linphone_chat_message_get_to_address (const LinphoneChatMessage *msg);
/**
* Get the content type of a chat message.
* @param[in] msg #LinphoneChatMessage object.
* @return The content type of the chat message
*/
LINPHONE_PUBLIC const char *linphone_chat_message_get_content_type (LinphoneChatMessage *msg);
LINPHONE_PUBLIC const char *linphone_chat_message_get_content_type (const LinphoneChatMessage *msg);
/**
* Set the content type of a chat message.
......@@ -125,7 +125,7 @@ LINPHONE_PUBLIC void linphone_chat_message_set_content_type (LinphoneChatMessage
* @return text or NULL if no text.
* @deprecated use getTextContent() instead
*/
LINPHONE_PUBLIC const char *linphone_chat_message_get_text (LinphoneChatMessage* msg);
LINPHONE_PUBLIC const char *linphone_chat_message_get_text (const LinphoneChatMessage* msg);
/**
* Get the message identifier.
......@@ -167,7 +167,7 @@ LINPHONE_PUBLIC LinphoneChatRoom *linphone_chat_message_get_chat_room (const Lin
* @return The path to the file to use for the file transfer.
* @deprecated use linphone_content_get_file_path() instead.
*/
LINPHONE_PUBLIC const char *linphone_chat_message_get_file_transfer_filepath (LinphoneChatMessage *msg);
LINPHONE_PUBLIC const char *linphone_chat_message_get_file_transfer_filepath (const LinphoneChatMessage *msg);
// =============================================================================
......@@ -200,7 +200,7 @@ LINPHONE_PUBLIC LinphoneChatMessageState linphone_chat_message_get_state (const
* @param[in] msg #LinphoneChatMessage object.
* @return whether the message was encrypted when transfered or not
*/
LINPHONE_PUBLIC bool_t linphone_chat_message_is_secured (LinphoneChatMessage *msg);
LINPHONE_PUBLIC bool_t linphone_chat_message_is_secured (const LinphoneChatMessage *msg);
/**
* Linphone message can carry external body as defined by rfc2017
......@@ -223,21 +223,21 @@ LINPHONE_PUBLIC void linphone_chat_message_set_external_body_url (LinphoneChatMe
* @param[in] msg #LinphoneChatMessage object.
* @return a pointer to the #LinphoneContent structure or NULL if not present.
*/
LINPHONE_PUBLIC LinphoneContent *linphone_chat_message_get_file_transfer_information (LinphoneChatMessage *msg);
LINPHONE_PUBLIC LinphoneContent *linphone_chat_message_get_file_transfer_information (const LinphoneChatMessage *msg);
/**
* Return whether or not a chat message is a file transfer.
* @param[in] msg #LinphoneChatMessage object
* @return Whether or not the message is a file transfer
*/
LINPHONE_PUBLIC bool_t linphone_chat_message_is_file_transfer (LinphoneChatMessage *msg);
LINPHONE_PUBLIC bool_t linphone_chat_message_is_file_transfer (const LinphoneChatMessage *msg);
/**
* Return whether or not a chat message is a text.
* @param[in] msg #LinphoneChatMessage object.
* @return Whether or not the message is a text
*/
LINPHONE_PUBLIC bool_t linphone_chat_message_is_text (LinphoneChatMessage *msg);
LINPHONE_PUBLIC bool_t linphone_chat_message_is_text (const LinphoneChatMessage *msg);
/**
* Start the download of the file from remote server
......@@ -288,14 +288,14 @@ LINPHONE_PUBLIC void linphone_chat_message_send (LinphoneChatMessage *msg);
*/
LINPHONE_PUBLIC LINPHONE_DEPRECATED void linphone_chat_message_resend (LinphoneChatMessage *msg);
LINPHONE_PUBLIC const LinphoneAddress *linphone_chat_message_get_peer_address (LinphoneChatMessage *msg);
LINPHONE_PUBLIC const LinphoneAddress *linphone_chat_message_get_peer_address (const LinphoneChatMessage *msg);
/**
* Returns the origin address of a message if it was a outgoing message, or the destination address if it was an incoming message.
* @param[in] msg #LinphoneChatMessage object.
* @return #LinphoneAddress
*/
LINPHONE_PUBLIC const LinphoneAddress *linphone_chat_message_get_local_address (LinphoneChatMessage *msg);
LINPHONE_PUBLIC const LinphoneAddress *linphone_chat_message_get_local_address (const LinphoneChatMessage *msg);
/**
* Add custom headers to the message.
......@@ -314,7 +314,7 @@ LINPHONE_PUBLIC void linphone_chat_message_add_custom_header (
* @param[in] msg #LinphoneChatMessage object.
* @param header_name header name searched
*/
LINPHONE_PUBLIC const char * linphone_chat_message_get_custom_header (LinphoneChatMessage *msg, const char *header_name);
LINPHONE_PUBLIC const char * linphone_chat_message_get_custom_header (const LinphoneChatMessage *msg, const char *header_name);
/**
* Removes a custom header from the message.
......@@ -327,9 +327,9 @@ LINPHONE_PUBLIC void linphone_chat_message_remove_custom_header (LinphoneChatMes
* Returns TRUE if the message has been read, otherwise returns FALSE.
* @param[in] msg #LinphoneChatMessage object.
*/
LINPHONE_PUBLIC bool_t linphone_chat_message_is_read (LinphoneChatMessage *msg);
LINPHONE_PUBLIC bool_t linphone_chat_message_is_read (const LinphoneChatMessage *msg);
LINPHONE_PUBLIC LinphoneReason linphone_chat_message_get_reason (LinphoneChatMessage *msg);
LINPHONE_PUBLIC LinphoneReason linphone_chat_message_get_reason (const LinphoneChatMessage *msg);
/**
* Get full details about delivery error of a chat message.
......@@ -409,7 +409,7 @@ LINPHONE_PUBLIC const char *linphone_chat_message_get_text_content (const Linpho
* @param[in] msg #LinphoneChatMessage object.
* @return true if download or upload is in progress, false otherwise
*/
LINPHONE_PUBLIC bool_t linphone_chat_message_is_file_transfer_in_progress (LinphoneChatMessage *msg);
LINPHONE_PUBLIC bool_t linphone_chat_message_is_file_transfer_in_progress (const LinphoneChatMessage *msg);
/**
* Gets the list of participants for which the imdn state has reached the specified state and the time at which they did.
......
......@@ -47,13 +47,15 @@ L_DECLARE_C_OBJECT_IMPL_WITH_XTORS(ChatMessage,
_linphone_chat_message_destructor,
LinphoneChatMessageCbs *cbs;
LinphoneAddress *from; // cache for shared_ptr<Address>
LinphoneAddress *to; // cache for shared_ptr<Address>
LinphoneChatMessageStateChangedCb message_state_changed_cb;
void *message_state_changed_user_data;
struct Cache {
~Cache () {
if (from)
linphone_address_unref(from);
if (to)
linphone_address_unref(to);
if (contents)
bctbx_list_free(contents);
}
......@@ -62,6 +64,9 @@ L_DECLARE_C_OBJECT_IMPL_WITH_XTORS(ChatMessage,
string textContentBody;
string customHeaderValue;
LinphoneAddress *from = nullptr;
LinphoneAddress *to = nullptr;
bctbx_list_t *contents = nullptr;
} mutable cache;
)
......@@ -74,11 +79,6 @@ static void _linphone_chat_message_constructor (LinphoneChatMessage *msg) {
static void _linphone_chat_message_destructor (LinphoneChatMessage *msg) {
linphone_chat_message_cbs_unref(msg->cbs);
msg->cbs = nullptr;
if (msg->from)
linphone_address_unref(msg->from);
if (msg->to)
linphone_address_unref(msg->to);
msg->cache.~Cache();
}
......@@ -127,11 +127,11 @@ time_t linphone_chat_message_get_time (const LinphoneChatMessage *msg) {
return L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getTime();
}
bool_t linphone_chat_message_is_secured (LinphoneChatMessage *msg) {
bool_t linphone_chat_message_is_secured (const LinphoneChatMessage *msg) {
return L_GET_CPP_PTR_FROM_C_OBJECT(msg)->isSecured();
}
bool_t linphone_chat_message_is_outgoing (LinphoneChatMessage *msg) {
bool_t linphone_chat_message_is_outgoing (const LinphoneChatMessage *msg) {
return L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getDirection() == LinphonePrivate::ChatMessage::Direction::Outgoing;
}
......@@ -143,7 +143,7 @@ const char* linphone_chat_message_get_message_id (const LinphoneChatMessage *msg
return L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getImdnMessageId().c_str();
}
bool_t linphone_chat_message_is_read (LinphoneChatMessage *msg) {
bool_t linphone_chat_message_is_read (const LinphoneChatMessage *msg) {
return L_GET_CPP_PTR_FROM_C_OBJECT(msg)->isRead();
}
......@@ -155,21 +155,21 @@ void linphone_chat_message_set_appdata (LinphoneChatMessage *msg, const char *da
L_GET_PRIVATE_FROM_C_OBJECT(msg)->setAppdata(L_C_TO_STRING(data));
}
const LinphoneAddress *linphone_chat_message_get_from_address (LinphoneChatMessage *msg) {
if (msg->from)
linphone_address_unref(msg->from);
msg->from = linphone_address_new(L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getFromAddress().asString().c_str());
return msg->from;
const LinphoneAddress *linphone_chat_message_get_from_address (const LinphoneChatMessage *msg) {
if (msg->cache.from)
linphone_address_unref(msg->cache.from);
msg->cache.from = linphone_address_new(L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getFromAddress().asString().c_str());
return msg->cache.from;
}
const LinphoneAddress *linphone_chat_message_get_to_address (LinphoneChatMessage *msg) {
if (msg->to)
linphone_address_unref(msg->to);
msg->to = linphone_address_new(L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getToAddress().asString().c_str());
return msg->to;
const LinphoneAddress *linphone_chat_message_get_to_address (const LinphoneChatMessage *msg) {
if (msg->cache.to)
linphone_address_unref(msg->cache.to);
msg->cache.to = linphone_address_new(L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getToAddress().asString().c_str());
return msg->cache.to;
}
const char *linphone_chat_message_get_file_transfer_filepath (LinphoneChatMessage *msg) {
const char *linphone_chat_message_get_file_transfer_filepath (const LinphoneChatMessage *msg) {
return L_STRING_TO_C(L_GET_PRIVATE_FROM_C_OBJECT(msg)->getFileTransferFilepath());
}
......@@ -189,7 +189,7 @@ void linphone_chat_message_remove_custom_header (LinphoneChatMessage *msg, const
L_GET_PRIVATE_FROM_C_OBJECT(msg)->removeSalCustomHeader(L_C_TO_STRING(header_name));
}
const char *linphone_chat_message_get_custom_header (LinphoneChatMessage *msg, const char *header_name) {
const char *linphone_chat_message_get_custom_header (const LinphoneChatMessage *msg, const char *header_name) {
msg->cache.customHeaderValue = L_GET_PRIVATE_FROM_C_OBJECT(msg)->getSalCustomHeaderValue(L_C_TO_STRING(header_name));
return L_STRING_TO_C(msg->cache.customHeaderValue);
}
......@@ -276,7 +276,7 @@ const char *linphone_chat_message_get_text_content (const LinphoneChatMessage *m
return L_STRING_TO_C(msg->cache.textContentBody);
}
bool_t linphone_chat_message_is_file_transfer_in_progress (LinphoneChatMessage *msg) {
bool_t linphone_chat_message_is_file_transfer_in_progress (const LinphoneChatMessage *msg) {
return L_GET_CPP_PTR_FROM_C_OBJECT(msg)->isFileTransferInProgress();
}
......@@ -300,7 +300,7 @@ bool_t linphone_chat_message_download_content (LinphoneChatMessage *msg, Linphon
// Old listener
// =============================================================================
LinphoneChatMessageStateChangedCb linphone_chat_message_get_message_state_changed_cb(LinphoneChatMessage* msg) {
LinphoneChatMessageStateChangedCb linphone_chat_message_get_message_state_changed_cb (LinphoneChatMessage* msg) {
return msg->message_state_changed_cb;
}
......@@ -312,7 +312,7 @@ void linphone_chat_message_set_message_state_changed_cb_user_data (LinphoneChatM
msg->message_state_changed_user_data = user_data;
}
void * linphone_chat_message_get_message_state_changed_cb_user_data (LinphoneChatMessage* msg) {
void *linphone_chat_message_get_message_state_changed_cb_user_data (LinphoneChatMessage* msg) {
return msg->message_state_changed_user_data;
}
......@@ -320,7 +320,7 @@ void * linphone_chat_message_get_message_state_changed_cb_user_data (LinphoneCha
// Structure has changed, hard to keep the behavior
// =============================================================================
const char *linphone_chat_message_get_content_type (LinphoneChatMessage *msg) {
const char *linphone_chat_message_get_content_type (const LinphoneChatMessage *msg) {
msg->cache.contentType = L_GET_PRIVATE_FROM_C_OBJECT(msg)->getContentType().asString();
return L_STRING_TO_C(msg->cache.contentType);
}
......@@ -329,7 +329,7 @@ void linphone_chat_message_set_content_type (LinphoneChatMessage *msg, const cha
L_GET_PRIVATE_FROM_C_OBJECT(msg)->setContentType(LinphonePrivate::ContentType(L_C_TO_STRING(content_type)));
}
const char *linphone_chat_message_get_text (LinphoneChatMessage *msg) {
const char *linphone_chat_message_get_text (const LinphoneChatMessage *msg) {
return L_STRING_TO_C(L_GET_PRIVATE_FROM_C_OBJECT(msg)->getText());
}
......@@ -338,7 +338,7 @@ int linphone_chat_message_set_text (LinphoneChatMessage *msg, const char* text)
return 0;
}
LinphoneContent *linphone_chat_message_get_file_transfer_information (LinphoneChatMessage *msg) {
LinphoneContent *linphone_chat_message_get_file_transfer_information (const LinphoneChatMessage *msg) {
const LinphonePrivate::Content *content = L_GET_PRIVATE_FROM_C_OBJECT(msg)->getFileTransferInformation();
if (content) return L_GET_C_BACK_PTR(content);
return NULL;
......@@ -352,25 +352,25 @@ bool_t linphone_chat_message_download_file (LinphoneChatMessage *msg) {
// Nothing to do, they call other C API methods
// =============================================================================
const LinphoneAddress *linphone_chat_message_get_peer_address (LinphoneChatMessage *msg) {
const LinphoneAddress *linphone_chat_message_get_peer_address (const LinphoneChatMessage *msg) {
return linphone_chat_room_get_peer_address(linphone_chat_message_get_chat_room(msg));
}
const LinphoneAddress *linphone_chat_message_get_local_address (LinphoneChatMessage *msg) {
const LinphoneAddress *linphone_chat_message_get_local_address (const LinphoneChatMessage *msg) {
if (L_GET_CPP_PTR_FROM_C_OBJECT(msg)->getDirection() == LinphonePrivate::ChatMessage::Direction::Outgoing)
return linphone_chat_message_get_from_address(msg);
return linphone_chat_message_get_to_address(msg);
}
LinphoneReason linphone_chat_message_get_reason (LinphoneChatMessage *msg) {
LinphoneReason linphone_chat_message_get_reason (const LinphoneChatMessage *msg) {
return linphone_error_info_get_reason(linphone_chat_message_get_error_info(msg));
}
bool_t linphone_chat_message_is_file_transfer (LinphoneChatMessage *msg) {
bool_t linphone_chat_message_is_file_transfer (const LinphoneChatMessage *msg) {
return L_GET_PRIVATE_FROM_C_OBJECT(msg)->hasFileTransferContent();
}
bool_t linphone_chat_message_is_text (LinphoneChatMessage *msg) {
bool_t linphone_chat_message_is_text (const LinphoneChatMessage *msg) {
return L_GET_PRIVATE_FROM_C_OBJECT(msg)->hasTextContent();
}
......
......@@ -112,7 +112,7 @@ public:
void addSalCustomHeader (const std::string &name, const std::string &value);
void removeSalCustomHeader (const std::string &name);
std::string getSalCustomHeaderValue (const std::string &name);
std::string getSalCustomHeaderValue (const std::string &name) const;
void loadFileTransferUrlFromBodyToContent ();
std::string createFakeFileTransferFromUrl(const std::string &url);
......@@ -125,10 +125,10 @@ public:
// Deprecated methods only used for C wrapper, to be removed some day...
// -----------------------------------------------------------------------------
const ContentType &getContentType ();
const ContentType &getContentType () const;
void setContentType (const ContentType &contentType);
const std::string &getText ();
const std::string &getText () const;
void setText (const std::string &text);
const std::string &getFileTransferFilepath () const;
......@@ -197,8 +197,8 @@ private:
// Cache for returned values, used for compatibility with previous C API
std::string fileTransferFilePath;
ContentType cContentType;
std::string cText;
mutable ContentType cContentType;
mutable std::string cText;
// TODO: Remove my comment. VARIABLES OK.
// Do not expose.
......
......@@ -201,7 +201,7 @@ void ChatMessagePrivate::removeSalCustomHeader (const string &name) {
salCustomHeaders = sal_custom_header_remove(salCustomHeaders, name.c_str());
}
string ChatMessagePrivate::getSalCustomHeaderValue (const string &name) {
string ChatMessagePrivate::getSalCustomHeaderValue (const string &name) const {
return L_C_TO_STRING(sal_custom_header_find(salCustomHeaders, name.c_str()));
}
......@@ -289,7 +289,7 @@ void ChatMessagePrivate::setExternalBodyUrl (const string &url) {
externalBodyUrl = url;
}
const ContentType &ChatMessagePrivate::getContentType () {
const ContentType &ChatMessagePrivate::getContentType () const {
loadContentsFromDatabase();
if (direction == ChatMessage::Direction::Incoming) {
if (contents.size() > 0) {
......@@ -325,7 +325,7 @@ void ChatMessagePrivate::setContentType (const ContentType &contentType) {
}
}
const string &ChatMessagePrivate::getText () {
const string &ChatMessagePrivate::getText () const {
loadContentsFromDatabase();
if (direction == ChatMessage::Direction::Incoming) {
if (hasTextContent()) {
......@@ -1082,7 +1082,7 @@ bool ChatMessage::downloadFile(FileTransferContent *fileTransferContent) {
return d->fileTransferChatMessageModifier.downloadFile(getSharedFromThis(), fileTransferContent);
}
bool ChatMessage::isFileTransferInProgress() {
bool ChatMessage::isFileTransferInProgress () const {
L_D();
return d->fileTransferChatMessageModifier.isFileTransferInProgressAndValid();
}
......
......@@ -110,7 +110,7 @@ public:
void removeCustomHeader (const std::string &headerName);
bool downloadFile (FileTransferContent *content);
bool isFileTransferInProgress();
bool isFileTransferInProgress () const;
protected:
explicit ChatMessage (ChatMessagePrivate &p);
......
......@@ -1016,7 +1016,7 @@ void FileTransferChatMessageModifier::cancelFileTransfer () {
releaseHttpRequest();
}
bool FileTransferChatMessageModifier::isFileTransferInProgressAndValid () {
bool FileTransferChatMessageModifier::isFileTransferInProgressAndValid () const {
return httpRequest && !belle_http_request_is_cancelled(httpRequest);
}
......
......@@ -62,7 +62,7 @@ public:
bool downloadFile (const std::shared_ptr<ChatMessage> &message, FileTransferContent *fileTransferContent);
void cancelFileTransfer ();
bool isFileTransferInProgressAndValid ();
bool isFileTransferInProgressAndValid () const;
std::string createFakeFileTransferFromUrl (const std::string &url);
private:
......
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