Skip to content
Snippets Groups Projects
Commit ab71a175 authored by jpbl's avatar jpbl
Browse files

*** empty log message ***

parent 68844237
Branches
Tags
No related merge requests found
This diff is collapsed.
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "account.h"
#include "requester.h"
Account::Account(const std::string &id)
: mId(id)
{}
Call
Account::createCall()
{
std::string callId = Requester::instance().generateCallId();
return Call(mSessionId, mAccountId, callId);
}
std::string
Account::register()
{
return Requester::instance().sendAccountRequest(mSessionId, mId, "register");
}
std::string
Account::unregister()
{
return Requester::instance().sendAccountRequest(mSessionId, mId, "unregister");
}
......@@ -21,13 +21,30 @@
#ifndef SFLPHONEGUI_ACCOUNT_H
#define SFLPHONEGUI_ACCOUNT_H
#include <string>
class Call;
class Account {
public:
void call(const std::string &to);
void register(){};
void unregister(){};
/**
* This will generate a call ready to be used.
*/
Call createCall();
std::string register();
std::string unregister();
private:
/**
* This is the session id that we are related to.
*/
std::string mSessionId;
/**
* This is the account id that we are related to.
*/
std::string mId;
};
......
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "call.h"
std::string
Call::call(const std::string &destination)
{
std::list< std::string> args;
args.push_back(mAccountId);
args.push_back(to);
return Requester::instance().sendCallCommand(mSession, mId, "answer", args)
}
std::string
Call::answer()
{
return Requester::instance().sendCallCommand(mSession, mId, "answer")
}
std::string
Call::hangup()
{
return Requester::instance().sendCallCommand(mSession, mId, "hangup")
}
std::string
Call::cancel()
{
return Requester::instance().sendCallCommand(mSession, mId, "cancel")
}
std::string
Call::hold()
{
return Requester::instance().sendCallCommand(mSession, mId, "hold")
}
std::string
Call::unhold()
{
return Requester::instance().sendCallCommand(mSession, mId, "unhold")
}
std::string
Call::refuse()
{
return Requester::instance().sendCallCommand(mSession, mId, "refuse")
}
std::string
Call::sendDtmf(char c)
{
std::list< std::string > args;
args.push_back(std::string(c));
return Requester::instance().sendCallCommand(mSession, mId, "senddtmf", args)
}
......@@ -18,97 +18,82 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef SFLPHONEGUI_SFLPHONECLIENT_H
#define SFLPHONEGUI_SFLPHONECLIENT_H
#ifndef SFLPHONEGUI_CALL_H
#define SFLPHONEGUI_CALL_H
#include <list>
#include <string>
#include <vector>
class Account;
class SFLPhoneClient
class Call
{
public:
Call(const std::string &sessionId,
const std::string &accountId,
const std::string &callId);
/**
* This function just return the dotted formated
* version. like: "0.5.6"
* This function will try to call the destination.
*
*/
std::string version();
std::string call(const std::string &destination);
/**
* This function will connect the client to the
* sflphone server.
* This function will answer the call.
*/
void connect();
std::string answer();
/**
* This function will disconnect the client from
* the sflphone server.
* This function will hangup on a call.
*/
void disconnect();
std::string hangup();
/**
* This function returns the current list of config
* entries of sflphone's server.
* ///TODO need to clarify this function.
*/
std::list< ConfigEntry > listConfig();
std::string cancel();
/**
* This function will save the current config. Then,
* next time sflphone will start, it will have the
* same configuration has it is right now.
* This function will put the call on hold.
* This *should* stop temporarly the streaming.
*/
void saveConfig();
std::string hold();
/**
* This function will set the specified option
* to the value given in argument. You need to
* call the saveConfig() function if you want
* sflphone's server to keep this option for
* the next restart.
*
* Note: Be carefull because when you want
* to set the audio device, or the audio codec, you
* need to set the value of the position
* in the vector, not the description of the device,
* or the codec.
* This function will unhold a holding call.
* This *should* restart a stopped streaming.
*/
void setOption(const std::string &name, const std::string &value);
std::string unhold();
/**
* This function will return the value of
* the specified option.
* This function refuse and incomming call.
* It means that the phone is ringing but we
* don't want to answer.
*/
std::string getOption(const std::string &name);
std::string refuse();
/**
* This function returns a vector containing the
* audio devices. See setOption's description note
* if you want to set the audio device.
* This function will send a tone to the line.
* This is used if you make a choice when you
* have a voice menu.
*/
std::vector< std::string > listAudioDevices();
std::string sendDtmf(char c);
private:
/**
* This function returns a vector containing the
* audio codecs. See setOption's description note
* if you want to set the audio codec.
* This is the unique identifier of the call.
*/
std::vector< std::string > listAudioCodecs();
std::string mId;
/**
* This function returns a list of accounts available
* on the system.
* This is the session id that we belong to.
*/
std::list< std::string > listAccounts();
std::string mSessionId;
/**
* This function returns the Account structure identified
* by the string given in argument. Use listAccounts() function
* if you want to know which ones are availables.
* This is the account id that we belong to.
*/
Account *getAccount(const std::string &name);
}
std::string mAccountId;
};
#endif
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
Request::Request(const std::string &sequenceId,
const std::string &command,
const std::list< std::string > &args)
: mSequenceId(sequenceId)
, mCommand(command)
, mArgs(args)
{}
void
Request::onError(int code, const std::string &message)
{}
void
Request::onSuccess(int code, const std::string &message)
{}
std::string
Request::toString()
{
std::ostream id;
id << mCommand << mSequenceId;
for(std::list< std::string >::iterator pos = mArgs.begin();
pos != mArgs.end();
pos++) {
id << " " << (*pos);
}
return id.str();
}
CallRequest::CallRequest(const std::string &sequenceId,
const std::string &callId,
const std::string &command,
const std::list< std::string > &args)
: Request(sequenceId, command, args)
, mCallId(callId)
{}
void
CallRequest::onError(int code, const std::string &message)
{
onError(Call(mCallId), code, message);
}
void
CallRequest::onError(Call call, int code, const std::string &message)
{}
void
CallRequest::onSuccess(int code, const std::string &message)
{
onSuccess(Call(mCallId), code, message);
}
void
CallRequest::onSuccess(Call call, int code, const std::string &message)
{}
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef SFLPHONEGUI_REQUEST_H
#define SFLPHONEGUI_REQUEST_H
class Request
{
public:
Request(const std::string &sequenceId,
const std::string &command,
const std::list< std::string > &args);
/**
* This function will be called when the request
* receive its answer, if the request didn't successfully
* ended.
*/
virtual void onError(int code, const std::string &message);
/**
* This function will be called when the request
* receive its answer, if the request successfully
* ended.
*/
virtual void onSuccess(int code, const std::string &message);
/**
* This function will translate the function into a string.
* This is used for sending the request through a text channel.
*/
std::string toString();
/**
* Return the sequence ID.
*/
std::string getSequenceID()
{return mSequenceId;}
/**
* Return the command.
*/
std::string getCommand()
{return mCommand;}
/**
* Return the args.
*/
std::string getArgs()
{return mArgs;}
private:
const std::string mSequenceId;
const std::string mCommand;
const std::list< std::string > mArgs;
}
class CallRequest : public Request
{
public:
CallRequest(const std::string &sequenceId,
const std::string &callId,
const std::string &command,
const std::list< std::string > &args);
/**
* This function will be called when the request
* receive its answer, if the request didn't successfully
* ended.
*/
virtual void onError(Call call, int code, const std::string &message);
/**
* This function will be called when the request
* receive its answer, if the request successfully
* ended.
*/
virtual void onSuccess(Call call, const std::string &message);
private:
/**
* This function will be called when the request
* receive its answer, if the request didn't successfully
* ended. This function will call the onError, but with
* the call linked to this request.
*/
virtual void onError(int code, const std::string &message);
/**
* This function will be called when the request
* receive its answer, if the request successfully
* ended. This function will call the onSuccess function,
* but with the call linked to this request.
*/
virtual void onSuccess(int code, const std::string &message);
private:
const std::string mCallId;
}
#endif
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include <stdexcept>
#include "requesterimpl.h"
RequesterImpl::RequesterImpl()
: mCallIdCount(0)
, mSessionIdCount(0)
, mSequenceIdCount(0)
{}
SessionImpl *
getSessionImpl(const std::string &sessionId)
{
std::map< std::string, SessionImpl * >::iterator pos = mSessions.find(sessionId);
if(pos == mSessions.end()) {
throw std::runtime_error("The session is not valid.");
}
return (*pos).second;
}
std::string
RequesterImpl::sendCallCommand(const std::string &sessionId,
const std::string &callId,
const std::string &command)
{
// We retreive the internal of a session.
SessionImpl *session = getSessionImpl(sessionId);
// We ask the factory to create the request.
Request *request = mCallRequestFactory.create(command, sequenceId, callId)
std::string sequenceId = generateSequenceId();
registerRequest(sessionId, sequenceId, request);
s->send(request);
return sequenceId;
}
void
RequesterImpl::receiveCallCommand
std::string
RequesterImpl::generateCallId()
{
std::ostream id;
id << "cCallID:" << mCallIdCount;
mCallIdCount++;
return id.str();
}
std::string
RequesterImpl::generateSessionId()
{
std::ostream id;
id << "cSessionID:" << mSessionIdCount;
mSessionIdCount++;
return id.str();
}
std::string
RequesterImpl::generateSequenceId()
{
std::ostream id;
id << "cSequenceID:" << mSequenceIdCount;
mSequenceIdCount++;
return id.str();
}
/**
* Copyright (C) 2004-2005 Savoir-Faire Linux inc.
* Author: Jean-Philippe Barrette-LaPierre
* <jean-philippe.barrette-lapierre@savoirfairelinux.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef SFLPHONEGUI_REQUESTERIMPL_H
#define SFLPHONEGUI_REQUESTERIMPL_H
class Call;
class RequesterImpl
{
public:
RequesterImpl();
/**
* Will send the command to the sflphone's server.
* This command is non-blocking. The command linked
* to this command will be executed.
*/
void sendCallCommand(const std::string &sessionId,
const std::string &callId,
const std::string &command);
void sendCallCommand(const std::string &sessionId,
const std::string &callId,
char *command);
private:
/**
* Generate a unique call ID.
*/
std::string generateCallId();
/**
* Generate a unique account ID.
*/
std::string generateAccountId();
/**
* Generate a unique session ID.
*/
std::string generateSessionId();
/**
* Generate a unique sequence ID.
*/
std::string generateSequenceId();
private:
std::map< std::string, SessionImpl * > mSessions;
/**
* This map is used to map accounts ids to session ids.
*/
std::map< std::string, std::string > mAccountToSessionMap;
/**
* This map is used to map call ids to session ids.
*/
std::map< std::string, std::string > mCallToSessionMap;
/**
* This is the list of all accounts in each session.
*/
std::map< std::string, std::list< std::string > > mSessionAccounts;
/**
* This is the list of all calls ids in each accounts.
*/
std::map< std::string, std::list< std::string > > mAccountCalls;
/**
* Those maps are used to create a request from a request
* string.
*/
std::map< std::string, * CallRequestCreator > mCallCommandCreators;
std::map< std::string, * AccountRequestCreator > mAccountRequestCreators;
std::map< std::string, * SessionRequestCreator > mSessionRequestCreators;
std::map< std::string, * SessionListRequestCreator > mSessionListRequestCreators;
/**
* This is the integer used to generate the call IDs.
*/
unsigned long mCallIdCount;
}
#endif
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment