Commit 4982e812 authored by DanmeiChen's avatar DanmeiChen

complete tests

parent 667ecc8e
......@@ -2564,6 +2564,8 @@ LinphoneStatus linphone_core_start (LinphoneCore *lc) {
} else {
linphone_configuring_terminated(lc, LinphoneConfiguringSkipped, NULL);
}
L_GET_PRIVATE_FROM_C_OBJECT(lc)->startMessageKillers();
return 0;
} catch (const CorePrivate::DatabaseConnectionFailure &e) {
......
......@@ -38,23 +38,23 @@ LINPHONE_BEGIN_NAMESPACE
ChatMessageKiller::ChatMessageKiller (double duration, MainDbEventKey dbKey, const ConferenceId &conferenceId): duration(duration), dbKey(dbKey), conferenceId(conferenceId) {
timer = nullptr;
bgTask.setName("ephemeral message timeout");
start = false;
chatMessage = nullptr;
}
ChatMessageKiller::ChatMessageKiller (MainDbEventKey dbKey, const ConferenceId &conferenceId) : ChatMessageKiller(86400, dbKey, conferenceId) {
}
ChatMessageKiller::~ChatMessageKiller () {
uninitTimer();
chatMessage = nullptr;
}
// -----------------------------------------------------------------------------
int ChatMessageKiller::timerExpired (void *data, unsigned int revents) {
ChatMessageKiller *d = static_cast<ChatMessageKiller *>(data);
// stop timer
if (d->timer) {
auto core = d->dbKey.getPrivate()->core.lock()->getCCore();
if (core && core->sal)
core->sal->cancelTimer(d->timer);
belle_sip_object_unref(d->timer);
d->timer = nullptr;
}
d->bgTask.stop();
d->uninitTimer();
// delete message in database for ephemral messag
shared_ptr<LinphonePrivate::EventLog> event = LinphonePrivate::MainDb::getEventFromKey(d->dbKey);
......@@ -105,5 +105,24 @@ void ChatMessageKiller::setChatMessage (const shared_ptr<ChatMessage> &message)
chatMessage = message;
}
void ChatMessageKiller::setStart() {
start = TRUE;
}
bool_t ChatMessageKiller::getStart() {
return start;
}
void ChatMessageKiller::uninitTimer() {
if (timer) {
auto core = dbKey.getPrivate()->core.lock()->getCCore();
if (core && core->sal)
core->sal->cancelTimer(timer);
belle_sip_object_unref(timer);
timer = nullptr;
}
bgTask.stop();
}
LINPHONE_END_NAMESPACE
......@@ -39,12 +39,16 @@ class ChatMessageKiller {
public:
explicit ChatMessageKiller (MainDbEventKey dbKey, const ConferenceId &conferenceId);
explicit ChatMessageKiller (double duration, MainDbEventKey dbKey, const ConferenceId &conferenceId);
~ChatMessageKiller ();
static int timerExpired (void *data, unsigned int revents);
void startTimer ();
void setDuration (double time);
void setChatMessage(const std::shared_ptr<ChatMessage> &message);
void uninitTimer ();
void setStart ();
bool_t getStart ();
private:
belle_sip_source_t *timer;
......@@ -53,6 +57,7 @@ private:
MainDbEventKey dbKey;
ConferenceId conferenceId;
std::shared_ptr<ChatMessage> chatMessage;
bool_t start;
};
LINPHONE_END_NAMESPACE
......
......@@ -212,7 +212,7 @@ void ChatMessagePrivate::setState (ChatMessage::State newState) {
if (isEphemeral && (state == ChatMessage::State::Displayed)) {
// set ephemeral start time
ephemeralStartTime = ::ms_time(NULL);
q->getChatRoom()->getCore()->getPrivate()->mainDb->setChatMessagesEphemeralStartTime(q->getChatRoom()->getConferenceId(), ephemeralStartTime);
q->getChatRoom()->getCore()->getPrivate()->mainDb->setChatMessagesEphemeralStartTime(dbKey.getStorageId(), ephemeralStartTime);
// start chat message killer for this message
shared_ptr<ChatMessageKiller> killer = q->getChatRoom()->getCore()->getPrivate()->getMessageKiller(q->getSharedFromThis());
......
......@@ -348,9 +348,13 @@ void CorePrivate::loadChatRooms () {
sendDeliveryNotifications();
}
void CorePrivate::initMessageKillers () {
if (!mainDb->isInitialized()) return;
mainDb->updateEphemeralMessageKillers(messageKillers);
void CorePrivate::startMessageKillers () {
for (auto it=messageKillers.begin(); it!=messageKillers.end(); ++it) {
shared_ptr<ChatMessageKiller> killer = it->second;
if (killer->getStart()) {
killer->startTimer();
}
}
}
void CorePrivate::sendDeliveryNotifications () {
......
......@@ -75,7 +75,7 @@ public:
void setPlaybackGainDb (AudioStream *stream, float gain);
void loadChatRooms ();
void initMessageKillers ();
void startMessageKillers ();
void startKillerWithMessage(MainDbEventKey key, double duration);
void sendDeliveryNotifications ();
void insertChatRoom (const std::shared_ptr<AbstractChatRoom> &chatRoom);
......
......@@ -96,7 +96,9 @@ void CorePrivate::init () {
}
loadChatRooms();
initMessageKillers();
// load messageKillers
if (mainDb->isInitialized())
messageKillers = mainDb->getEphemeralMessageKillers();
} else lWarning() << "Database explicitely not requested, this Core is built with no database support.";
}
......@@ -119,6 +121,7 @@ void CorePrivate::uninit () {
ms_usleep(10000);
}
messageKillers.clear();
chatRoomsById.clear();
noCreatedClientGroupChatRooms.clear();
listeners.clear();
......@@ -226,6 +229,12 @@ shared_ptr<ChatMessageKiller> CorePrivate::getMessageKiller(shared_ptr<ChatMessa
messageKillers[key] = killer;
return killer;
} else {
shared_ptr<ChatMessageKiller> killer = it->second;
LinphoneChatMessageCbs *cbs = linphone_chat_message_get_callbacks(L_GET_C_BACK_PTR(message));
if (cbs && linphone_chat_message_cbs_get_message_killer_started(cbs)) {
killer->setChatMessage(message);
messageKillers[key] = killer;
}
return it->second;
}
}
......
......@@ -2408,20 +2408,16 @@ void MainDb::markChatMessagesAsRead (const ConferenceId &conferenceId) const {
#endif
}
void MainDb::setChatMessagesEphemeralStartTime (const ConferenceId &conferenceId, time_t &time) const {
void MainDb::setChatMessagesEphemeralStartTime (const long long &eventId, time_t &time) const {
#ifdef HAVE_DB_STORAGE
static const string query = "UPDATE chat_message_ephemeral_event"
" SET start_time = :startTime"
" WHERE event_id IN ("
" SELECT event_id FROM conference_event WHERE chat_room_id = :chatRoomId"
")";
" WHERE event_id = :eventId";
L_DB_TRANSACTION {
L_D();
const tm &startTime = Utils::getTimeTAsTm(time);
const long long &dbChatRoomId = d->selectChatRoomId(conferenceId);
*d->dbSession.getBackendSession() << query, soci::use(dbChatRoomId), soci::use(startTime);
*d->dbSession.getBackendSession() << query, soci::use(startTime),soci::use(eventId);
tr.commit();
};
#endif
......@@ -2468,17 +2464,17 @@ list<shared_ptr<ChatMessage>> MainDb::getUnreadChatMessages (const ConferenceId
#endif
}
void MainDb::updateEphemeralMessageKillers (std::unordered_map<MainDbEventKey, std::shared_ptr<ChatMessageKiller>> &messageKillers) {
std::unordered_map<MainDbEventKey, std::shared_ptr<ChatMessageKiller>> MainDb::getEphemeralMessageKillers () const {
#ifdef HAVE_DB_STORAGE
L_DB_TRANSACTION {
return L_DB_TRANSACTION {
L_D();
messageKillers.clear();
std::unordered_map<MainDbEventKey, std::shared_ptr<ChatMessageKiller>> messageKillers;
soci::rowset<soci::row> ephemeralMessages = (d->dbSession.getBackendSession()->prepare << "SELECT event_id, ephemeral_time, start_time FROM chat_message_ephemeral_event");
for (const auto &row : ephemeralMessages) {
const long long &eventId = d->dbSession.resolveId(row, 0);
const double &ephemeralTime = row.get<long>(1);
const double &ephemeralTime = row.get<double>(1);
const time_t &startTime = d->dbSession.getTime(row, 2);
soci::row rowf;
......@@ -2494,10 +2490,14 @@ void MainDb::updateEphemeralMessageKillers (std::unordered_map<MainDbEventKey, s
// startTimer for delete ephemeral messages. If expired, set duration time 0.05s
double duration = difftime(ms_time(0), startTime) > ephemeralTime ? 0.05 : difftime(ms_time(0), startTime);
killer->setDuration(duration);
killer->startTimer();
killer->setStart();
messageKillers[key] = killer;
}
}
return messageKillers;
};
#else
return NULL;
#endif
}
......
......@@ -105,7 +105,7 @@ public:
void markChatMessagesAsRead (const ConferenceId &conferenceId) const;
std::list<std::shared_ptr<ChatMessage>> getUnreadChatMessages (const ConferenceId &conferenceId) const;
void setChatMessagesEphemeralStartTime (const ConferenceId &conferenceId, time_t &time) const;
void setChatMessagesEphemeralStartTime (const long long &eventId, time_t &time) const;
std::list<ParticipantState> getChatMessageParticipantsByImdnState (
const std::shared_ptr<EventLog> &eventLog,
......@@ -123,7 +123,7 @@ public:
time_t stateChangeTime
);
void updateEphemeralMessageKillers (std::unordered_map<MainDbEventKey, std::shared_ptr<ChatMessageKiller>> &messageKillers);
std::unordered_map<MainDbEventKey, std::shared_ptr<ChatMessageKiller>> getEphemeralMessageKillers () const;
std::shared_ptr<ChatMessage> getLastChatMessage (const ConferenceId &conferenceId) const;
......
This diff is collapsed.
......@@ -182,6 +182,27 @@ void core_chat_room_state_changed (LinphoneCore *core, LinphoneChatRoom *cr, Lin
}
}
void core_global_state_changed (LinphoneCore *lc, LinphoneGlobalState gstate, const char *message) {
if (gstate == LinphoneGlobalConfiguring) {
const bctbx_list_t *chatRooms = linphone_core_get_chat_rooms(lc);
for (const bctbx_list_t *f = chatRooms ; f ; f = bctbx_list_next(f)) {
LinphoneChatRoom *room = (LinphoneChatRoom*)(f->data);
bctbx_list_t *history = linphone_chat_room_get_history(room, 0);
for (bctbx_list_t *item = history; item; item = bctbx_list_next(item)) {
LinphoneChatMessage *msg = (LinphoneChatMessage *)bctbx_list_get_data(item);
if (!!linphone_chat_message_is_ephemeral(msg)) {
LinphoneChatMessageCbs *msgCbs = linphone_chat_message_get_callbacks(msg);
linphone_chat_message_cbs_set_message_killer_started(msgCbs, liblinphone_tester_chat_message_msg_killer_started);
linphone_chat_message_cbs_set_message_killer_finished(msgCbs, liblinphone_tester_chat_message_msg_killer_finished);
linphone_chat_message_add_callbacks(msg, msgCbs);
linphone_chat_message_configure_message_killer(msg);
}
}
bctbx_list_free_with_data(history, (bctbx_list_free_func)linphone_chat_message_unref);
}
}
}
void configure_core_for_conference (LinphoneCore *core, const char* username, const LinphoneAddress *factoryAddr, bool_t server) {
const char *identity = linphone_core_get_identity(core);
const char *new_username;
......@@ -310,13 +331,15 @@ void _receive_file_plus_text(bctbx_list_t *coresList, LinphoneCoreManager *lcm,
}
// Configure list of core manager for conference and add the listener
bctbx_list_t * init_core_for_conference(bctbx_list_t *coreManagerList) {
bctbx_list_t * init_core_for_conference_ephemeral(bctbx_list_t *coreManagerList, bool_t ephemeralTest) {
LinphoneAddress *factoryAddr = linphone_address_new(sFactoryUri);
bctbx_list_for_each2(coreManagerList, (void (*)(void *, void *))_configure_core_for_conference, (void *) factoryAddr);
linphone_address_unref(factoryAddr);
LinphoneCoreCbs *cbs = linphone_factory_create_core_cbs(linphone_factory_get());
linphone_core_cbs_set_chat_room_state_changed(cbs, core_chat_room_state_changed);
if (ephemeralTest)
linphone_core_cbs_set_global_state_changed(cbs, core_global_state_changed);
bctbx_list_for_each2(coreManagerList, (void (*)(void *, void *))configure_core_for_callbacks, (void *) cbs);
linphone_core_cbs_unref(cbs);
......@@ -327,6 +350,10 @@ bctbx_list_t * init_core_for_conference(bctbx_list_t *coreManagerList) {
return coresList;
}
bctbx_list_t * init_core_for_conference(bctbx_list_t *coreManagerList) {
return init_core_for_conference_ephemeral(coreManagerList, FALSE);
}
void start_core_for_conference(bctbx_list_t *coreManagerList) {
bctbx_list_for_each(coreManagerList, (void (*)(void *))_start_core);
}
......
......@@ -372,6 +372,7 @@ void linphone_core_manager_wait_for_stun_resolution(LinphoneCoreManager *mgr);
void linphone_core_manager_destroy(LinphoneCoreManager* mgr);
void linphone_core_manager_delete_chat_room (LinphoneCoreManager *mgr, LinphoneChatRoom *cr, bctbx_list_t *coresList);
bctbx_list_t * init_core_for_conference(bctbx_list_t *coreManagerList);
bctbx_list_t * init_core_for_conference_ephemeral(bctbx_list_t *coreManagerList, bool_t ephemeralTest);
void start_core_for_conference(bctbx_list_t *coreManagerList);
void reset_counters(stats* counters);
......
......@@ -1055,7 +1055,6 @@ void message_received(LinphoneCore *lc, LinphoneChatRoom *room, LinphoneChatMess
linphone_chat_message_cbs_set_message_killer_started(msgCbs, liblinphone_tester_chat_message_msg_killer_started);
linphone_chat_message_cbs_set_message_killer_finished(msgCbs, liblinphone_tester_chat_message_msg_killer_finished);
linphone_chat_message_configure_message_killer(msg);
ms_message("[TEST] incoming message");
}
char* from=linphone_address_as_string(linphone_chat_message_get_from_address(msg));
......
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