From 96e661d4d66f6355fbbdf8af096deea2819ff28c Mon Sep 17 00:00:00 2001 From: Tom Swindell Date: Thu, 30 Apr 2015 12:00:21 +0000 Subject: [PATCH] [commhistory-daemon] Removed StreamedMediaListener code for calls as moved logging voicecall. Signed-off-by: Tom Swindell --- src/logger.cpp | 3 - src/src.pro | 2 - src/streamchannellistener.cpp | 387 -------------- src/streamchannellistener.h | 94 ---- tests/tests.pro | 1 - tests/ut_streamchannellistener/test_set.xml | 5 - .../ut_streamchannellistener.cpp | 489 ------------------ .../ut_streamchannellistener.h | 59 --- .../ut_streamchannellistener.pro | 58 --- 9 files changed, 1098 deletions(-) delete mode 100644 src/streamchannellistener.cpp delete mode 100644 src/streamchannellistener.h delete mode 100644 tests/ut_streamchannellistener/test_set.xml delete mode 100644 tests/ut_streamchannellistener/ut_streamchannellistener.cpp delete mode 100644 tests/ut_streamchannellistener/ut_streamchannellistener.h delete mode 100644 tests/ut_streamchannellistener/ut_streamchannellistener.pro diff --git a/src/logger.cpp b/src/logger.cpp index 78949bd..f8cb2b6 100644 --- a/src/logger.cpp +++ b/src/logger.cpp @@ -30,7 +30,6 @@ #include "logger.h" #include "channellistener.h" #include "textchannellistener.h" -#include "streamchannellistener.h" #include "loggerclientobserver.h" #include "messagereviver.h" #include "debug.h" @@ -99,8 +98,6 @@ void Logger::createChannelListener(const QString &channelType, listener = new TextChannelListener(account, channel, context, this); connect(listener, SIGNAL(savingFailed(const Tp::ConnectionPtr&)), m_Reviver, SLOT(checkConnection(const Tp::ConnectionPtr&))); - } else if ( channelType == QLatin1String(TP_QT_IFACE_CHANNEL_TYPE_STREAMED_MEDIA) ) { - listener = new StreamChannelListener(account, channel, context, this); } if(listener) { diff --git a/src/src.pro b/src/src.pro index ecc5072..afcc1ec 100644 --- a/src/src.pro +++ b/src/src.pro @@ -52,7 +52,6 @@ packagesExist(qt5-boostable) { HEADERS += logger.h \ channellistener.h \ textchannellistener.h \ - streamchannellistener.h \ loggerclientobserver.h \ notificationmanager.h \ serialisable.h \ @@ -81,7 +80,6 @@ SOURCES += main.cpp \ logger.cpp \ channellistener.cpp \ textchannellistener.cpp \ - streamchannellistener.cpp \ loggerclientobserver.cpp \ notificationmanager.cpp \ serialisable.cpp \ diff --git a/src/streamchannellistener.cpp b/src/streamchannellistener.cpp deleted file mode 100644 index 5a45f47..0000000 --- a/src/streamchannellistener.cpp +++ /dev/null @@ -1,387 +0,0 @@ -/****************************************************************************** -** -** This file is part of commhistory-daemon. -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Reto Zingg -** -** This library is free software; you can redistribute it and/or modify it -** under the terms of the GNU Lesser General Public License version 2.1 as -** published by the Free Software Foundation. -** -** This library is distributed in the hope that it will be useful, but -** WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -** or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -** License for more details. -** -** You should have received a copy of the GNU Lesser General Public License -** along with this library; if not, write to the Free Software Foundation, Inc., -** 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -** -******************************************************************************/ - -#include "streamchannellistener.h" -#include "notificationmanager.h" -#include "debug.h" - -// libcommhistory -#include -#include - -// TpQt4 -#include - -#define CURRENT_SERVICE_POINT_PROPERTY_NAME ("CurrentServicePoint") -#define INITIAL_SERVICE_POINT_PROPERTY TP_QT_IFACE_CHANNEL_INTERFACE_SERVICE_POINT+QLatin1String(".InitialServicePoint") -#define STREAM_CHANNEL_INITIAL_VIDEO_PROPERTY TP_QT_IFACE_CHANNEL_TYPE_STREAMED_MEDIA+QLatin1String(".InitialVideo") - -#define SAVING_INTERVAL 5*60000 // 5 minute - -using namespace RTComLogger; - -StreamChannelListener::StreamChannelListener(const Tp::AccountPtr &account, - const Tp::ChannelPtr &channel, - const Tp::MethodInvocationContextPtr<> &context, - QObject *parent) - : ChannelListener(account, channel, context, parent), - m_CallStarted(false), - m_CallEnded(false), - m_callStartTime(0), - m_EventAdded(false), - m_LoggingTimerId(0), - m_eventCommitted(false), - m_pProxy(0) -{ - DEBUG() << __PRETTY_FUNCTION__; - - invocationContextFinished(); - - makeChannelReady(Tp::StreamedMediaChannel::FeatureStreams); - - connect(&(eventModel()), SIGNAL(eventsCommitted(QList, bool)), - this, SLOT(slotEventsCommitted(QList, bool))); - - m_Event.setStartTime(QDateTime::currentDateTime()); - m_Event.setEndTime(m_Event.startTime()); - m_Event.setType(CommHistory::Event::CallEvent); - if (m_Account) - m_Event.setLocalUid(m_Account->objectPath()); - m_Event.setRemoteUid(targetId()); - - m_Direction = CommHistory::Event::Inbound; - - QVariantMap properties = m_Channel->immutableProperties(); - if (properties.contains(TP_QT_IFACE_CHANNEL+QLatin1String(".Requested"))) { - if (properties.value(TP_QT_IFACE_CHANNEL+QLatin1String(".Requested")).toBool()) - m_Direction = CommHistory::Event::Outbound; - } - m_Event.setDirection(m_Direction); - - if (properties.value(STREAM_CHANNEL_INITIAL_VIDEO_PROPERTY).toBool()) - m_Event.setIsVideoCall(true); - - QVariant spProp = m_Channel->immutableProperties().value(INITIAL_SERVICE_POINT_PROPERTY); - if (spProp.isValid()) { - const Tp::ServicePoint sp = qdbus_cast(spProp); - if (sp.servicePointType == Tp::ServicePointTypeEmergency) { - DEBUG() << Q_FUNC_INFO << "*** EMERGENCY CALL, service =" << sp.service; - m_Event.setIsEmergencyCall(true); - } - } - - // postpone adding event for incoming event to speed up call handling - if (m_Direction == CommHistory::Event::Outbound && !addEvent()) - qWarning() << Q_FUNC_INFO << "failed to add event"; -} - -StreamChannelListener::~StreamChannelListener() -{ -} - -void StreamChannelListener::callStarted() -{ - DEBUG() << Q_FUNC_INFO; - - if (m_CallStarted) - return; - - m_CallStarted = true; - m_CallEnded = false; - m_Event.setStartTime(QDateTime::currentDateTime()); - m_Event.setEndTime(m_Event.startTime()); - - struct timespec tp; -#ifdef CLOCK_BOOTTIME - clock_gettime(CLOCK_BOOTTIME, &tp); -#else - clock_gettime(CLOCK_MONOTONIC, &tp); -#endif - m_callStartTime = tp.tv_sec; - - DEBUG() << Q_FUNC_INFO << m_Event.startTime(); - - if (addEvent()) - m_LoggingTimerId = startTimer(SAVING_INTERVAL); -} - -void StreamChannelListener::callEnded() -{ - DEBUG() << Q_FUNC_INFO; - - m_CallEnded = true; - - struct timespec tp; - QDateTime endTime; -#ifdef CLOCK_BOOTTIME - if (clock_gettime(CLOCK_BOOTTIME, &tp) != -1) { -#else - if (clock_gettime(CLOCK_MONOTONIC, &tp) != -1) { -#endif - int duration = tp.tv_sec - m_callStartTime; - endTime = m_Event.startTime().addSecs(duration); - } else { - endTime = QDateTime::currentDateTime(); - } - - m_Event.setEndTime(endTime); - - if (m_LoggingTimerId > 0) { - killTimer(m_LoggingTimerId); - m_LoggingTimerId = 0; - } -} - -void StreamChannelListener::channelReady() -{ - DEBUG() << __PRETTY_FUNCTION__; - - Tp::StreamedMediaChannelPtr mediaChannel = Tp::StreamedMediaChannelPtr::dynamicCast(m_Channel); - - if (mediaChannel) { - connect(mediaChannel.data(), - SIGNAL(groupMembersChanged(const Tp::Contacts&, - const Tp::Contacts&, - const Tp::Contacts&, - const Tp::Contacts&, - const Tp::Channel::GroupMemberChangeDetails&)), - this, - SLOT(slotGroupMembersChanged(const Tp::Contacts&, - const Tp::Contacts&, - const Tp::Contacts&, - const Tp::Contacts&, - const Tp::Channel::GroupMemberChangeDetails&))); - connect(mediaChannel.data(), - SIGNAL(streamStateChanged(const Tp::StreamedMediaStreamPtr &, Tp::MediaStreamState)), - this, - SLOT(slotStreamStateChanged(const Tp::StreamedMediaStreamPtr &, Tp::MediaStreamState))); - - if (!m_Event.isEmergencyCall()) { - Tp::Client::ChannelInterfaceServicePointInterface *servicePointIf = - mediaChannel->optionalInterface(); - if (servicePointIf) { - connect(servicePointIf, SIGNAL(ServicePointChanged(const Tp::ServicePoint &)), - this, SLOT(slotServicePointChanged(const Tp::ServicePoint &))); - - const Tp::ServicePoint sp = servicePointIf->property( - CURRENT_SERVICE_POINT_PROPERTY_NAME).value(); - if (sp.servicePointType == Tp::ServicePointTypeEmergency) { - DEBUG() << Q_FUNC_INFO << "*** EMERGENCY CALL, service =" << sp.service; - m_Event.setIsEmergencyCall(true); - } - } - } - } else { - qCritical() << Q_FUNC_INFO << "Wrong channel - Null"; - } -} - -void StreamChannelListener::slotGroupMembersChanged( - const Tp::Contacts &groupMembersAdded, - const Tp::Contacts &groupLocalPendingMembersAdded, - const Tp::Contacts &groupRemotePendingMembersAdded, - const Tp::Contacts &groupMembersRemoved, - const Tp::Channel::GroupMemberChangeDetails &details) -{ - Q_UNUSED(groupLocalPendingMembersAdded) - Q_UNUSED(groupRemotePendingMembersAdded) - Q_UNUSED(details) - - DEBUG() << __PRETTY_FUNCTION__; - - Tp::StreamedMediaChannelPtr mediaChannel = Tp::StreamedMediaChannelPtr::dynamicCast(m_Channel); - - if(!mediaChannel.isNull()) { - if (!m_CallStarted) { - // call not started, new member added, members > 1 - if (!groupMembersAdded.isEmpty() && - mediaChannel->groupContacts().count() >= 2) { - Tp::StreamedMediaStreams streams = mediaChannel->streamsForType(Tp::MediaStreamTypeAudio); - - if (streams.count() - && streams.first()->localSendingState() == Tp::StreamedMediaStream::SendingStateSending) { - callStarted(); - } - - // if call is not started and nobody was added to channel and - // number if contacts less than 2 and someone was removed, call - // is rejected (when actor == self) or missed. - } else if (groupMembersAdded.isEmpty() && - mediaChannel->groupContacts().count() < 2 && - !groupMembersRemoved.isEmpty()) { - - const Tp::ContactPtr self(mediaChannel->groupSelfContact()); - bool locallyMissed = (details.actor() == self && - details.reason() == Tp::ChannelGroupChangeReasonNoAnswer && - groupMembersRemoved.contains(self)); - bool remotelyMissed = (details.actor() != self); - - if ( (locallyMissed || remotelyMissed) - && m_Direction == CommHistory::Event::Inbound) { - DEBUG() << "call missed"; - m_Event.setIsMissedCall(true); - } - - m_CallEnded = false; - m_CallStarted = false; - } - - // call already started, if not ended and someone was removed from channel - // and number of contacts on channel is less than 2, call ended. - } else if (!m_CallEnded && !groupMembersRemoved.isEmpty()) { - if (mediaChannel->groupContacts().count() < 2) - callEnded(); - } - } else { - qCritical() << "StreamChannelListener::onGroupMembersChanged() channel is null!"; - } -} - -void StreamChannelListener::slotStreamStateChanged(const Tp::StreamedMediaStreamPtr &stream, - Tp::MediaStreamState state) -{ - if (stream->type() == Tp::MediaStreamTypeVideo) { - bool modified = false; - - if (state == Tp::MediaStreamStateConnected && !m_Event.isVideoCall()) { - m_Event.setIsVideoCall(true); - modified = true; - } else if (state == Tp::MediaStreamStateDisconnected - && m_Event.isVideoCall() - && !m_CallEnded) { - m_Event.setIsVideoCall(false); - modified = true; - } - - if (modified && m_EventAdded) { - // already added -> addEvent() will modify - addEvent(); - } - } - if (stream->type() == Tp::MediaStreamTypeAudio - && state == Tp::MediaStreamStateConnected) { - Tp::StreamedMediaChannelPtr mediaChannel = - Tp::StreamedMediaChannelPtr::dynamicCast(m_Channel); - if (!mediaChannel.isNull() && mediaChannel->groupContacts().count() >= 2) - callStarted(); - } -} - -void StreamChannelListener::invalidated(Tp::DBusProxy *proxy, - const QString &errorName, const QString &errorMessage) -{ - DEBUG() << __PRETTY_FUNCTION__ << errorName << errorMessage; - - QDateTime currentTime = QDateTime::currentDateTime(); - - // ensure correct time for missed calls - if (!m_Event.startTime().isValid()) - m_Event.setStartTime(currentTime); - - if (!m_CallEnded) { - if (m_CallStarted) - // call started but aborted in the middle - m_Event.setEndTime(currentTime); - else - // not started (and ended) call should have 0 duration - m_Event.setEndTime(m_Event.startTime()); - } - - // catch connection manager crashes and other weird events - // FIXME: this may not cover all cases(?). Error.Cancelled usually - // means "hung up by local user", but if the remote hangs up before - // we get MembersChanged, tpqt probably returns the same error. - if ( (m_Direction == CommHistory::Event::Inbound) && (!m_CallStarted)) { - if (!errorName.isEmpty() && errorName != TP_QT_ERROR_CANCELLED) - m_Event.setIsMissedCall(true); - } - - if (addEvent() && m_Event.isMissedCall()) { - NotificationManager* nManager = NotificationManager::instance(); - nManager->showNotification(m_Event); - } - - // don't quit and destroy the event model before the final call - // event has been saved (and the corresponding eventsUpdated() - // signal emitted) - if (m_eventCommitted) { - ChannelListener::invalidated(proxy,errorName,errorMessage); - } else { - m_pProxy = proxy; - m_errorName = errorName; - m_errorMessage = errorMessage; - } -} - -void StreamChannelListener::timerEvent(QTimerEvent *event) -{ - if (event->timerId() == m_LoggingTimerId && m_EventAdded) { - m_Event.setEndTime(QDateTime::currentDateTime()); - m_eventCommitted = false; - eventModel().modifyEvent(m_Event); - } -} - -bool StreamChannelListener::addEvent() -{ - DEBUG() << __PRETTY_FUNCTION__; - - bool result = false; - - if (m_EventAdded) { - m_eventCommitted = false; - result = eventModel().modifyEvent(m_Event); - } else { - result = eventModel().addEvent(m_Event); - m_EventAdded = result; - } - - if (result == false) { - qCritical() << "failed to add event"; - } - - return result; -} - -void StreamChannelListener::slotServicePointChanged(const Tp::ServicePoint &servicePoint) -{ - DEBUG() << Q_FUNC_INFO; - - if (servicePoint.servicePointType == Tp::ServicePointTypeEmergency) { - DEBUG() << Q_FUNC_INFO << "*** EMERGENCY CALL, service =" << servicePoint.service; - m_Event.setIsEmergencyCall(true); - } -} - -void StreamChannelListener::slotEventsCommitted(QList events, bool successful) -{ - Q_UNUSED(events); - Q_UNUSED(successful); - - DEBUG() << Q_FUNC_INFO; - - if (m_pProxy) { - ChannelListener::invalidated(m_pProxy, m_errorName, m_errorMessage); - } else { - m_eventCommitted = true; - } -} diff --git a/src/streamchannellistener.h b/src/streamchannellistener.h deleted file mode 100644 index 73d71e0..0000000 --- a/src/streamchannellistener.h +++ /dev/null @@ -1,94 +0,0 @@ -/****************************************************************************** -** -** This file is part of commhistory-daemon. -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Reto Zingg -** -** This library is free software; you can redistribute it and/or modify it -** under the terms of the GNU Lesser General Public License version 2.1 as -** published by the Free Software Foundation. -** -** This library is distributed in the hope that it will be useful, but -** WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -** or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -** License for more details. -** -** You should have received a copy of the GNU Lesser General Public License -** along with this library; if not, write to the Free Software Foundation, Inc., -** 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -** -******************************************************************************/ - -#ifndef STREAM_CHANNEL_LISTENER_H -#define STREAM_CHANNEL_LISTENER_H - -#include -#include -#include -#include -#include "channellistener.h" - -namespace CommHistory { - class Event; -} - -namespace RTComLogger -{ - -/*! - * \class StreamChannelListener - * \brief class responsible for listening and logging activity on a stream - * channel, i.e. calls - */ -class StreamChannelListener : public ChannelListener -{ - Q_OBJECT - -public: - explicit StreamChannelListener(const Tp::AccountPtr &account, - const Tp::ChannelPtr &channel, - const Tp::MethodInvocationContextPtr<> &context, - QObject *parent = 0); - - virtual ~StreamChannelListener(); - -private Q_SLOTS: - void slotGroupMembersChanged( - const Tp::Contacts &groupMembersAdded, - const Tp::Contacts &groupLocalPendingMembersAdded, - const Tp::Contacts &groupRemotePendingMembersAdded, - const Tp::Contacts &groupMembersRemoved, - const Tp::Channel::GroupMemberChangeDetails &details); - void slotStreamStateChanged(const Tp::StreamedMediaStreamPtr &stream, - Tp::MediaStreamState state); - virtual void invalidated(Tp::DBusProxy *proxy, - const QString &errorName, const QString &errorMessage); - void slotServicePointChanged(const Tp::ServicePoint &servicePoint); - void slotEventsCommitted(QList events, bool successful); - -private: - void channelReady(); - bool addEvent(); - void channelListenerReady(); - void callStarted(); - void callEnded(); - void timerEvent(QTimerEvent *event); - -private: - bool m_CallStarted; - bool m_CallEnded; - time_t m_callStartTime; - CommHistory::Event m_Event; - bool m_EventAdded; - int m_LoggingTimerId; - - bool m_eventCommitted; - Tp::DBusProxy *m_pProxy; - QString m_errorName; - QString m_errorMessage; -}; - -} // namespace RTComLogger - -#endif // CHANNEL_LISTENER_H diff --git a/tests/tests.pro b/tests/tests.pro index 5cadfbf..0f96ca9 100644 --- a/tests/tests.pro +++ b/tests/tests.pro @@ -25,7 +25,6 @@ TEMPLATE = subdirs SUBDIRS = ut_notificationmanager \ ut_textchannellistener \ - ut_streamchannellistener \ ut_messagereviver # make sure the destination path exists diff --git a/tests/ut_streamchannellistener/test_set.xml b/tests/ut_streamchannellistener/test_set.xml deleted file mode 100644 index bf59b6b..0000000 --- a/tests/ut_streamchannellistener/test_set.xml +++ /dev/null @@ -1,5 +0,0 @@ - - - /opt/tests/@PROJECT_NAME@/ut_streamchannellistener - - diff --git a/tests/ut_streamchannellistener/ut_streamchannellistener.cpp b/tests/ut_streamchannellistener/ut_streamchannellistener.cpp deleted file mode 100644 index 8d16d5f..0000000 --- a/tests/ut_streamchannellistener/ut_streamchannellistener.cpp +++ /dev/null @@ -1,489 +0,0 @@ -/****************************************************************************** -** -** This file is part of commhistory-daemon. -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Reto Zingg -** -** This library is free software; you can redistribute it and/or modify it -** under the terms of the GNU Lesser General Public License version 2.1 as -** published by the Free Software Foundation. -** -** This library is distributed in the hope that it will be useful, but -** WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -** or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -** License for more details. -** -** You should have received a copy of the GNU Lesser General Public License -** along with this library; if not, write to the Free Software Foundation, Inc., -** 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -** -******************************************************************************/ - -// INCLUDES -#include "ut_streamchannellistener.h" - -// Qt includes -#include -#include -#include -#include - -#include "TelepathyQt/Types" -#include "TelepathyQt/Account" -#include "TelepathyQt/Channel" -#include "TelepathyQt/StreamedMediaChannel" -#include "TelepathyQt/Message" -#include "TelepathyQt/Connection" -#include "TelepathyQt/ContactManager" - -#include "streamchannellistener.h" -#include "notificationmanager.h" - -// constants -#define ACCOUNT_PATH QLatin1String("/org/freedesktop/Telepathy/Account/ring/tel/ring") -#define NUMBER QLatin1String("+358987654321") -#define CHANNEL_PATH QLatin1String("/org/freedesktop/Telepathy/Connection/ring/tel/ring/call0") -#define TARGET_HANDLE 1 - -using namespace RTComLogger; - -namespace { - bool waitSignal(QSignalSpy &spy, int msec) - { - QTime timer; - timer.start(); - while (timer.elapsed() < msec && spy.isEmpty()) - QCoreApplication::processEvents(); - - return !spy.isEmpty(); - } - - void justWait(int msec) - { - QTime timer; - timer.start(); - while (timer.elapsed() < msec) - QCoreApplication::processEvents(); - } -} - -Ut_StreamChannelListener::Ut_StreamChannelListener() -{ -} - -Ut_StreamChannelListener::~Ut_StreamChannelListener() -{ -} - -/*! - * This function will be called before the first testfunction is executed. - */ -void Ut_StreamChannelListener::initTestCase() -{ - qRegisterMetaType("ChannelListener*"); - //qRegisterMetaType("Tp::PendingOperation*"); -} - -/*! - * This function will be called after the last testfunction was executed. - */ -void Ut_StreamChannelListener::cleanupTestCase() -{ - CommHistory::CallModel model; - - QSignalSpy modelReady(&model, SIGNAL(modelReady(bool))); - model.setFilterAccount(ACCOUNT_PATH); - model.getEvents(); - QVERIFY(waitSignal(modelReady, 5000)); - - while (model.rowCount() != 0) - QVERIFY(model.deleteEvent(model.event(model.index(0,0)).id())); -} - -/*! - * This function will be called before each testfunction is executed. - */ -void Ut_StreamChannelListener::init() -{ -} - -/*! - * This unction will be called after every testfunction. - */ -void Ut_StreamChannelListener::cleanup() -{ -} - -void Ut_StreamChannelListener::invalidated_data() -{ - QTest::addColumn("waitReady"); - QTest::addColumn("startCall"); - QTest::newRow("waitReady") << true << false; - QTest::newRow("invalidateBeforeReady") << false << false; - QTest::newRow("invalidateAfterCallStart") << true << true; -} - -void Ut_StreamChannelListener::invalidated() -{ - QFETCH(bool, waitReady); - QFETCH(bool, startCall); - - NotificationManager *nm = NotificationManager::instance(); - QVERIFY(nm); - nm->postedNotifications.clear(); - - // setup connection - Tp::ConnectionPtr conn(new Tp::Connection()); - conn->ut_setIsReady(true); - - Tp::AccountPtr acc(new Tp::Account(conn, ACCOUNT_PATH)); - - //setup channel - QDateTime startTime = QDateTime::currentDateTime(); - QVariantMap immProp; - immProp.insert(TELEPATHY_INTERFACE_CHANNEL ".TargetID", NUMBER); - Tp::ChannelPtr ch(new Tp::StreamedMediaChannel(CHANNEL_PATH, immProp)); - ch->ut_setIsRequested(false); - ch->ut_setTargetHandleType(Tp::HandleTypeContact); - ch->ut_setTargetHandle(TARGET_HANDLE); - ch->ut_setConnection(conn); - - Tp::MethodInvocationContextPtr<> ctx(new Tp::MethodInvocationContext<>()); - - StreamChannelListener scl(acc, ch, ctx); - - QVERIFY(ctx->isFinished()); - QVERIFY(!ctx->isError()); - - if (waitReady) - QCoreApplication::processEvents(); - - if (startCall) { - // add streams - Tp::StreamedMediaChannelPtr::dynamicCast(ch)->ut_addStream(); - Tp::StreamedMediaChannelPtr::dynamicCast(ch)->ut_streams().first()->ut_setLocalPendingState(Tp::StreamedMediaStream::SendingStateSending); - - // add contact - // add contact - Tp::ContactPtr self(new Tp::Contact()); - self->ut_setHandle(1); - Tp::ContactPtr target(new Tp::Contact()); - target->ut_setHandle(TARGET_HANDLE); - target->ut_setId(NUMBER); - - ch->ut_setGroupSelfContact(self); - ch->ut_setGroupContacts(Tp::Contacts() << target << self); - - Tp::Channel::GroupMemberChangeDetails details(target, - Tp::ChannelGroupChangeReasonNone); - - ch->ut_emitGroupMembersChanged(Tp::Contacts() << target, - Tp::Contacts(), - Tp::Contacts(), - Tp::Contacts(), - details); - - justWait(2000); - } - - QSignalSpy closed(&scl, SIGNAL(channelClosed(ChannelListener*))); - ch->ut_invalidate(TELEPATHY_ERROR_TERMINATED, QString()); - - QVERIFY(waitSignal(closed, 5000)); - - CommHistory::CallModel model; - - QSignalSpy modelReady(&model, SIGNAL(modelReady(bool))); - model.getEvents(); - QVERIFY(waitSignal(modelReady, 5000)); - QVERIFY(model.rowCount() > 0); - - CommHistory::Event e = model.event(model.index(0,0)); - QCOMPARE(e.localUid(), ACCOUNT_PATH); - QCOMPARE(e.remoteUid(), NUMBER); - - if (startCall) { - QVERIFY(startTime.toTime_t() < e.endTime().toTime_t()); - } else { - QVERIFY(e.startTime().toTime_t() - startTime.toTime_t() <= 1); - } - if (startCall) - QVERIFY(!e.isMissedCall()); - else { - QVERIFY(e.isMissedCall()); - QCOMPARE(nm->postedNotifications.size(), 1); - } - QCOMPARE(e.direction(), CommHistory::Event::Inbound); -} - -void Ut_StreamChannelListener::normalCall_data() -{ - QTest::addColumn("incoming"); - QTest::addColumn("accept"); - QTest::addColumn("endLocally"); - QTest::addColumn("missLocally"); - QTest::addColumn("invalidateError"); - - QTest::newRow("incoming acceptAndEnd") << true << true << true << false << QString(); - QTest::newRow("incoming acceptAndEnded") << true << true << false << false << QString(); - QTest::newRow("incoming rejectedLocally") << true << false << true << false << QString(); - QTest::newRow("incoming rejectedRemotley") << true << false << false << false << QString(); - QTest::newRow("incoming missLocally") << true << false << true << true << QString(); - - QTest::newRow("outgoing acceptAndEnd") << false << true << true << false << QString(); - QTest::newRow("outgoing acceptAndEnded") << false << true << false << false << QString(); - QTest::newRow("outgoing rejectedLocally") << false << false << true << false << QString(); - QTest::newRow("outgoing rejectedRemotley") << false << false << false << false << QString(); - QTest::newRow("outgoing missLocally") << false << false << true << true << QString(); - - QTest::newRow("error before start") << true << false << true << false << QString(TP_QT4_ERROR_NOT_AVAILABLE); - QTest::newRow("error after end") << true << true << true << false << QString(TP_QT4_ERROR_NOT_AVAILABLE); -} - -void Ut_StreamChannelListener::normalCall() -{ - QFETCH(bool, incoming); - QFETCH(bool, accept); - QFETCH(bool, endLocally); - QFETCH(bool, missLocally); - QFETCH(QString, invalidateError); - - NotificationManager *nm = NotificationManager::instance(); - QVERIFY(nm); - nm->postedNotifications.clear(); - - // setup connection - Tp::ConnectionPtr conn(new Tp::Connection()); - conn->ut_setIsReady(true); - - Tp::AccountPtr acc(new Tp::Account(conn, ACCOUNT_PATH)); - - //setup channel - QDateTime startTime = QDateTime::currentDateTime(); - QVariantMap immProp; - immProp.insert(TELEPATHY_INTERFACE_CHANNEL ".TargetID", NUMBER); - immProp.insert(TELEPATHY_INTERFACE_CHANNEL ".Requested", !incoming); - Tp::ChannelPtr ch(new Tp::StreamedMediaChannel(CHANNEL_PATH, immProp)); - ch->ut_setIsRequested(!incoming); - ch->ut_setTargetHandleType(Tp::HandleTypeContact); - ch->ut_setTargetHandle(TARGET_HANDLE); - ch->ut_setConnection(conn); - - Tp::MethodInvocationContextPtr<> ctx(new Tp::MethodInvocationContext<>()); - - StreamChannelListener scl(acc, ch, ctx); - - QVERIFY(ctx->isFinished()); - QVERIFY(!ctx->isError()); - - QCoreApplication::processEvents(); //allow channel to become ready - - // add contact - Tp::ContactPtr self(new Tp::Contact()); - self->ut_setHandle(1); - Tp::ContactPtr target(new Tp::Contact()); - target->ut_setHandle(TARGET_HANDLE); - target->ut_setId(NUMBER); - - ch->ut_setGroupSelfContact(self); - ch->ut_setGroupContacts(Tp::Contacts() << target << self); - - // add streams - Tp::StreamedMediaChannelPtr::dynamicCast(ch)->ut_addStream(); - Tp::StreamedMediaChannelPtr::dynamicCast(ch)->ut_streams().first()->ut_setLocalPendingState(Tp::StreamedMediaStream::SendingStateSending); - - // emit membersChanged - if (accept) { - // start call - if (incoming) { - Tp::Channel::GroupMemberChangeDetails details(self, - Tp::ChannelGroupChangeReasonNone); - - ch->ut_emitGroupMembersChanged(Tp::Contacts() << self, - Tp::Contacts(), - Tp::Contacts(), - Tp::Contacts(), - details); - } else { - Tp::Channel::GroupMemberChangeDetails details(target, - Tp::ChannelGroupChangeReasonNone); - - ch->ut_emitGroupMembersChanged(Tp::Contacts() << target, - Tp::Contacts(), - Tp::Contacts(), - Tp::Contacts(), - details); - } - } - - justWait(2000); - - // end call - if (endLocally) { - Tp::Channel::GroupMemberChangeDetails details(self, - missLocally? - Tp::ChannelGroupChangeReasonNoAnswer - :Tp::ChannelGroupChangeReasonNone); - - ch->ut_setGroupContacts(Tp::Contacts() << target); - ch->ut_emitGroupMembersChanged(Tp::Contacts(), - Tp::Contacts(), - Tp::Contacts(), - Tp::Contacts() << self, - details); - } else { - Tp::Channel::GroupMemberChangeDetails details(target, - Tp::ChannelGroupChangeReasonNone); - - ch->ut_setGroupContacts(Tp::Contacts() << self); - ch->ut_emitGroupMembersChanged(Tp::Contacts(), - Tp::Contacts(), - Tp::Contacts(), - Tp::Contacts() << target, - details); - } - - QSignalSpy closed(&scl, SIGNAL(channelClosed(ChannelListener*))); - ch->ut_invalidate(invalidateError, QString()); - QVERIFY(waitSignal(closed, 5000)); - - CommHistory::CallModel model; - - QSignalSpy modelReady(&model, SIGNAL(modelReady(bool))); - model.getEvents(); - QVERIFY(waitSignal(modelReady, 5000)); - QVERIFY(model.rowCount() > 0); - - CommHistory::Event e = model.event(model.index(0,0)); - QCOMPARE(e.localUid(), ACCOUNT_PATH); - QCOMPARE(e.remoteUid(), NUMBER); - QVERIFY(startTime.toTime_t() <= e.startTime().toTime_t()); - justWait(1000); // account for rounding errors with clock_monotonic vs. QDateTime - QVERIFY(QDateTime::currentDateTime().toTime_t() >= e.endTime().toTime_t()); - QCOMPARE(e.isEmergencyCall(), false); - - if (accept) - QVERIFY(e.endTime().toTime_t() > e.startTime().toTime_t()); - else - QCOMPARE(e.endTime().toTime_t(), e.startTime().toTime_t()); - - if (incoming) - QCOMPARE(e.direction(), CommHistory::Event::Inbound); - else - QCOMPARE(e.direction(), CommHistory::Event::Outbound); - - if (incoming && ((!accept && !endLocally) || missLocally || (!accept && !invalidateError.isEmpty()))) { - QVERIFY(e.isMissedCall()); - QCOMPARE(nm->postedNotifications.size(), 1); - } else { - QVERIFY(!e.isMissedCall()); - QCOMPARE(nm->postedNotifications.size(), 0); - } -} - -void Ut_StreamChannelListener::emergency_data() -{ - QTest::addColumn("accept"); - - QTest::newRow("accepted") << true; - QTest::newRow("cancelled") << false; -} - -void Ut_StreamChannelListener::emergency() -{ - QFETCH(bool, accept); - - // setup connection - Tp::ConnectionPtr conn(new Tp::Connection()); - conn->ut_setIsReady(true); - - Tp::AccountPtr acc(new Tp::Account(conn, ACCOUNT_PATH)); - - //setup channel - QDateTime startTime = QDateTime::currentDateTime(); - QVariantMap immProp; - immProp.insert(TELEPATHY_INTERFACE_CHANNEL ".TargetID", "112"); - immProp.insert(TELEPATHY_INTERFACE_CHANNEL ".Requested", true); - Tp::ServicePoint sp; - sp.service = "urn:service:sos"; - sp.servicePointType = Tp::ServicePointTypeEmergency; - immProp.insert(TELEPATHY_INTERFACE_CHANNEL_INTERFACE_SERVICE_POINT ".InitialServicePoint", - QVariant::fromValue(sp)); - Tp::ChannelPtr ch(new Tp::StreamedMediaChannel(CHANNEL_PATH, immProp)); - ch->ut_setIsRequested(true); - ch->ut_setTargetHandleType(Tp::HandleTypeContact); - ch->ut_setTargetHandle(42); - ch->ut_setConnection(conn); - //ch->ut_setInterfaces(QStringList() << Tp::Client::ChannelInterfaceServicePointInterface::staticInterfaceName()); - - Tp::MethodInvocationContextPtr<> ctx(new Tp::MethodInvocationContext<>()); - - StreamChannelListener scl(acc, ch, ctx); - - QVERIFY(ctx->isFinished()); - QVERIFY(!ctx->isError()); - - QCoreApplication::processEvents(); //allow channel to become ready - - // add contact - Tp::ContactPtr self(new Tp::Contact()); - self->ut_setHandle(1); - Tp::ContactPtr target(new Tp::Contact()); - target->ut_setHandle(33); - target->ut_setId("112"); - - ch->ut_setGroupSelfContact(self); - ch->ut_setGroupContacts(Tp::Contacts() << target << self); - - // add streams - Tp::StreamedMediaChannelPtr::dynamicCast(ch)->ut_addStream(); - Tp::StreamedMediaChannelPtr::dynamicCast(ch)->ut_streams().first()->ut_setLocalPendingState(Tp::StreamedMediaStream::SendingStateSending); - - // emit membersChanged - Tp::Channel::GroupMemberChangeDetails details(target, - Tp::ChannelGroupChangeReasonNone); - - if (accept) - ch->ut_emitGroupMembersChanged(Tp::Contacts() << target, - Tp::Contacts(), - Tp::Contacts(), - Tp::Contacts(), - details); - - justWait(2000); - - // end call - ch->ut_setGroupContacts(Tp::Contacts() << target); - ch->ut_emitGroupMembersChanged(Tp::Contacts(), - Tp::Contacts(), - Tp::Contacts(), - Tp::Contacts() << self, - details); - - QSignalSpy closed(&scl, SIGNAL(channelClosed(ChannelListener*))); - ch->ut_invalidate(QString(), QString()); - QVERIFY(waitSignal(closed, 5000)); - - CommHistory::CallModel model; - - QSignalSpy modelReady(&model, SIGNAL(modelReady(bool))); - model.getEvents(); - QVERIFY(waitSignal(modelReady, 5000)); - QVERIFY(model.rowCount() > 0); - - CommHistory::Event e = model.event(model.index(0,0)); - qDebug() << e.toString(); - QCOMPARE(e.localUid(), ACCOUNT_PATH); - QCOMPARE(e.remoteUid(), QString("112")); - QVERIFY(startTime.toTime_t() <= e.startTime().toTime_t()); - justWait(1000); // account for rounding errors with clock_monotonic vs. QDateTime - QVERIFY(QDateTime::currentDateTime().toTime_t() >= e.endTime().toTime_t()); - - if (accept) - QVERIFY(e.endTime().toTime_t() > e.startTime().toTime_t()); - QCOMPARE(e.direction(), CommHistory::Event::Outbound); - QCOMPARE(e.isEmergencyCall(), true); -} - -QTEST_MAIN(Ut_StreamChannelListener) diff --git a/tests/ut_streamchannellistener/ut_streamchannellistener.h b/tests/ut_streamchannellistener/ut_streamchannellistener.h deleted file mode 100644 index 2be0221..0000000 --- a/tests/ut_streamchannellistener/ut_streamchannellistener.h +++ /dev/null @@ -1,59 +0,0 @@ -/****************************************************************************** -** -** This file is part of commhistory-daemon. -** -** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -** Contact: Reto Zingg -** -** This library is free software; you can redistribute it and/or modify it -** under the terms of the GNU Lesser General Public License version 2.1 as -** published by the Free Software Foundation. -** -** This library is distributed in the hope that it will be useful, but -** WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -** or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -** License for more details. -** -** You should have received a copy of the GNU Lesser General Public License -** along with this library; if not, write to the Free Software Foundation, Inc., -** 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -** -******************************************************************************/ - -#ifndef UT_STREAMCHANNELLISTENER_H -#define UT_STREAMCHANNELLISTENER_H - -// INCLUDES -#include -#include - -#include - -namespace RTComLogger { - -class Ut_StreamChannelListener : public QObject -{ - Q_OBJECT -public: - Ut_StreamChannelListener(); - ~Ut_StreamChannelListener(); - -private Q_SLOTS: - void initTestCase(); - void cleanupTestCase(); - void init(); - void cleanup(); - -// Test functions -private Q_SLOTS: - void invalidated_data(); - void invalidated(); - - void normalCall_data(); - void normalCall(); - void emergency_data(); - void emergency(); -}; - -} -#endif // UT_STREAMCHANNELLISTENER_H diff --git a/tests/ut_streamchannellistener/ut_streamchannellistener.pro b/tests/ut_streamchannellistener/ut_streamchannellistener.pro deleted file mode 100644 index aed382a..0000000 --- a/tests/ut_streamchannellistener/ut_streamchannellistener.pro +++ /dev/null @@ -1,58 +0,0 @@ -############################################################################### -# -# This file is part of commhistory-daemon. -# -# Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). -# Contact: Reto Zingg -# -# This library is free software; you can redistribute it and/or modify it -# under the terms of the GNU Lesser General Public License version 2.1 as -# published by the Free Software Foundation. -# -# This library is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public -# License for more details. -# -# You should have received a copy of the GNU Lesser General Public License -# along with this library; if not, write to the Free Software Foundation, Inc., -# 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -# -############################################################################### - -#----------------------------------------------------------------------------- -# Project file for test ut_textchannellistener -#----------------------------------------------------------------------------- - -#----------------------------------------------------------------------------- -# common test configuration -#----------------------------------------------------------------------------- -!include(../tests.pri) : error( "Unable to include test.pri" ) - -!include( ../stubs/stubs.pri ) : error("Unable to include stubs/stubs.pri") -INCLUDEPATH = ../stubs/ $${INCLUDEPATH} - -#----------------------------------------------------------------------------- -# test specific configuration -#----------------------------------------------------------------------------- - -TARGET = ut_streamchannellistener - -TEST_SOURCES += $$COMMHISTORYDSRCDIR/streamchannellistener.cpp \ - $$COMMHISTORYDSRCDIR/channellistener.cpp - -TEST_HEADERS += $$COMMHISTORYDSRCDIR/streamchannellistener.h \ - $$COMMHISTORYDSRCDIR/channellistener.h - -HEADERS += ut_streamchannellistener.h \ - $$TEST_HEADERS - -SOURCES += ut_streamchannellistener.cpp \ - $$TEST_SOURCES - -DESTDIR = ../bin -QT += dbus -LIBS += -lrt - -# End of File -