Commit 38fbeda8 authored by jpbl's avatar jpbl
Browse files

we can receive hangup events

parent c5100adf
......@@ -18,13 +18,15 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef SFLPHONEGUI_OBJECTFACTORY_H
#define SFLPHONEGUI_OBJECTFACTORY_H
#ifndef __EVENTFACTORY_HPP__
#define __EVENTFACTORY_HPP__
#include <list>
#include <map>
#include <string>
#include "Event.hpp"
/**
* This is the base class that we will use to
* create an object from the "create" function.
......@@ -61,7 +63,7 @@ template< typename Base, typename Actual >
* with the default constructor.
*/
template< typename Base >
class EventFactory
class EventFactoryImpl
{
public:
/**
......@@ -82,4 +84,9 @@ public:
#include "EventFactory.inl"
#include "utilspp/Singleton.hpp"
typedef utilspp::SingletonHolder< EventFactoryImpl< Event > > EventFactory;
#endif
......@@ -19,8 +19,8 @@
*/
#ifndef SFLPHONEGUI_OBJECTFACTORY_INL
#define SFLPHONEGUI_OBJECTFACTORY_INL
#ifndef __EVENTFACTORY_INL__
#define __EVENTFACTORY_INL__
#include <stdexcept>
......@@ -42,7 +42,7 @@ EventCreator< Base, Actual >::clone()
template< typename Base >
Base *
EventFactory< Base >::create(const std::string &code,
EventFactoryImpl< Base >::create(const std::string &code,
const std::list< std::string > &args)
{
typename std::map< std::string, EventCreatorBase< Base > * >::iterator pos = mEventCreators.find(code);
......@@ -56,7 +56,7 @@ EventFactory< Base >::create(const std::string &code,
template< typename Base >
template< typename Actual >
void
EventFactory< Base >::registerEvent(const std::string &code)
EventFactoryImpl< Base >::registerEvent(const std::string &code)
{
if(mEventCreators.find(code) != mEventCreators.end()) {
delete mEventCreators[code];
......
......@@ -4,6 +4,7 @@
#include "globals.h"
#include "Event.hpp"
#include "PhoneLine.hpp"
#include "PhoneLineLocker.hpp"
#include "PhoneLineManager.hpp"
......@@ -11,7 +12,10 @@
PhoneLineManagerImpl::PhoneLineManagerImpl()
: mAccount(mSession.getDefaultAccount())
, mCurrentLine(NULL)
{}
{
EventFactory::instance().registerEvent< HangupEvent >("002");
mSession.getEvents();
}
PhoneLine *
PhoneLineManagerImpl::getCurrentLine()
......
......@@ -10,6 +10,7 @@
class PhoneLine;
#include "Account.hpp"
#include "EventFactory.hpp"
#include "Session.hpp"
/**
......
......@@ -2,6 +2,7 @@
#include "SFLPhoneApp.hpp"
#include "SFLPhoneWindow.hpp"
#include "SFLRequest.hpp"
#include "PhoneLine.hpp"
#include "PhoneLineButton.hpp"
#include "Requester.hpp"
......@@ -13,15 +14,16 @@ SFLPhoneApp::SFLPhoneApp(int argc, char **argv)
, mSession()
, mAccount(mSession.getDefaultAccount())
{
PhoneLineManager::instance().setNbLines(NB_PHONELINES);
Requester::instance().registerObject< Request >(std::string("playtone"));
Requester::instance().registerObject< Request >(std::string("playdtmf"));
Requester::instance().registerObject< EventRequest >(std::string("getevents"));
Requester::instance().registerObject< CallRelatedRequest >(std::string("senddtmf"));
Requester::instance().registerObject< CallRelatedRequest >(std::string("playdtmf"));
Requester::instance().registerObject< CallRelatedRequest >(std::string("call"));
Requester::instance().registerObject< CallRelatedRequest >(std::string("hold"));
Requester::instance().registerObject< CallRelatedRequest >(std::string("unhold"));
Requester::instance().registerObject< CallRelatedRequest >(std::string("hangup"));
PhoneLineManager::instance().setNbLines(NB_PHONELINES);
}
void
......
class AnswerManagerImpl
{
public:
void setPhoneLineManager(PhoneLineManager *manager);
private:
PhoneLineManager *mManager;
};
#include <memory>
#include <sstream>
#include <string>
#include "globals.h"
#include "PhoneLineManager.hpp"
#include "SFLRequest.hpp"
EventRequest::EventRequest(const std::string &sequenceId,
const std::string &command,
const std::list< std::string > &args)
: Request(sequenceId, command, args)
{}
void
CallRelatedRequest::onError(Call call, const std::string &code, const std::string &message)
EventRequest::onError(const std::string &code, const std::string &message)
{
PhoneLineManager::instance().error();
_debug("EventRequest error: (%s) %s", code.c_str(), message.c_str());
}
void
CallRelatedRequest::onEntry(Call, const std::string &, const std::string &)
{}
EventRequest::onEntry(const std::string &code, const std::string &message)
{
std::istringstream stream(message);
std::string s;
std::list< std::string > args;
while(stream.good()) {
stream >> s;
args.push_back(s);
}
std::auto_ptr< Event > e(EventFactory::instance().create(code, args));
e->execute();
}
void
CallRelatedRequest::onSuccess(Call, const std::string &, const std::string &)
{}
EventRequest::onSuccess(const std::string &code, const std::string &message)
{
_debug("EventRequest success: (%s) %s", code.c_str(), message.c_str());
}
......@@ -8,6 +8,12 @@
class EventRequest : public Request
{
public:
EventRequest(const std::string &sequenceId,
const std::string &command,
const std::list< std::string > &args);
virtual ~EventRequest(){}
/**
......
......@@ -49,6 +49,12 @@ Session::playTone() const
return Requester::instance().send(mId, "playtone", std::list< std::string >());
}
std::string
Session::getEvents() const
{
return Requester::instance().send(mId, "getevents", std::list< std::string >());
}
std::string
Session::playDtmf(char c) const
{
......
......@@ -44,6 +44,11 @@ class Session
*/
std::string playDtmf(char c) const;
/**
* This function will register to receive events
*/
std::string getEvents() const;
Call createCall() const;
......
......@@ -12,6 +12,7 @@ INCLUDEPATH += .
HEADERS += Account.hpp \
AnswerReceiver.hpp \
Call.hpp \
Event.hpp \
EventFactory.hpp \
EventFactory.inl \
globals.h \
......@@ -30,6 +31,7 @@ HEADERS += Account.hpp \
SessionIO.hpp \
SFLPhoneApp.hpp \
SFLPhoneWindow.hpp \
SFLRequest.hpp \
transqwidget.h \
ObjectFactory.inl \
RequesterImpl.inl \
......@@ -38,6 +40,7 @@ FORMS += SFLPhoneWindow.ui
SOURCES += Account.cpp \
AnswerReceiver.cpp \
Call.cpp \
Event.cpp \
JPushButton.cpp \
main.cpp \
PhoneLine.cpp \
......@@ -49,5 +52,6 @@ SOURCES += Account.cpp \
Session.cpp \
SessionIO.cpp \
SFLPhoneApp.cpp \
SFLPhoneWindow.cpp
SFLPhoneWindow.cpp \
SFLRequest.cpp
RESOURCES += sflphone.qrc
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