2006-06-08 18:31:00 +00:00
|
|
|
/*
|
2005-03-18 18:16:59 +00:00
|
|
|
* yatephone.h
|
2004-05-22 00:05:20 +00:00
|
|
|
* This file is part of the YATE Project http://YATE.null.ro
|
2004-11-29 03:56:41 +00:00
|
|
|
*
|
2005-04-08 10:55:22 +00:00
|
|
|
* Drivers, channels and telephony related classes
|
|
|
|
*
|
2004-11-29 03:56:41 +00:00
|
|
|
* Yet Another Telephony Engine - a fully featured software PBX and IVR
|
2006-05-27 15:08:43 +00:00
|
|
|
* Copyright (C) 2004-2006 Null Team
|
2004-11-29 03:56:41 +00:00
|
|
|
*
|
|
|
|
* 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
|
2006-05-27 15:08:43 +00:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
|
2004-05-22 00:05:20 +00:00
|
|
|
*/
|
2004-11-29 03:56:41 +00:00
|
|
|
|
2005-03-18 18:16:59 +00:00
|
|
|
#ifndef __YATEPHONE_H
|
|
|
|
#define __YATEPHONE_H
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
#ifndef __cplusplus
|
|
|
|
#error C++ is required
|
|
|
|
#endif
|
|
|
|
|
2005-03-18 18:16:59 +00:00
|
|
|
#include <yatengine.h>
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Holds all Telephony Engine related classes.
|
|
|
|
*/
|
|
|
|
namespace TelEngine {
|
|
|
|
|
2005-03-25 01:05:44 +00:00
|
|
|
/**
|
|
|
|
* A structure to hold information about a static picture or video frame.
|
|
|
|
*/
|
2006-01-05 21:33:15 +00:00
|
|
|
struct YATE_API ImageInfo {
|
2005-03-25 01:05:44 +00:00
|
|
|
/**
|
|
|
|
* Width of the image in pixels
|
|
|
|
*/
|
|
|
|
int width;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Height of the image in pixels
|
|
|
|
*/
|
|
|
|
int height;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bit depth of the image, 0 for unknown/irrelevant
|
|
|
|
*/
|
|
|
|
int depth;
|
|
|
|
};
|
|
|
|
|
2004-05-24 00:38:23 +00:00
|
|
|
/**
|
|
|
|
* A structure to hold information about a data format.
|
|
|
|
*/
|
2005-10-07 22:03:19 +00:00
|
|
|
struct YATE_API FormatInfo {
|
2005-02-06 20:13:21 +00:00
|
|
|
/**
|
|
|
|
* Standard no-blanks lowercase format name
|
|
|
|
*/
|
|
|
|
const char* name;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format type: "audio", "video", "text"
|
|
|
|
*/
|
|
|
|
const char* type;
|
|
|
|
|
|
|
|
/**
|
2005-06-14 20:53:20 +00:00
|
|
|
* Frame size in octets/frame, 0 for non-framed formats
|
2005-02-06 20:13:21 +00:00
|
|
|
*/
|
2005-06-14 20:53:20 +00:00
|
|
|
int frameSize;
|
2005-02-06 20:13:21 +00:00
|
|
|
|
|
|
|
/**
|
2005-06-14 20:53:20 +00:00
|
|
|
* Frame time in microseconds, 0 for variable
|
2005-02-06 20:13:21 +00:00
|
|
|
*/
|
2005-06-14 20:53:20 +00:00
|
|
|
int frameTime;
|
2005-02-06 20:13:21 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Rate in samples/second (audio) or 1e-6 frames/second (video), 0 for unknown
|
|
|
|
*/
|
|
|
|
int sampleRate;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of channels, typically 1
|
|
|
|
*/
|
|
|
|
int numChannels;
|
|
|
|
|
2006-05-25 20:40:58 +00:00
|
|
|
/**
|
|
|
|
* If this is a valid candidate for conversion
|
|
|
|
*/
|
|
|
|
bool converter;
|
|
|
|
|
2005-02-06 20:13:21 +00:00
|
|
|
/**
|
|
|
|
* Guess the number of samples in an encoded data block
|
|
|
|
* @param len Length of the data block in octets
|
|
|
|
* @return Number of samples or 0 if unknown
|
|
|
|
*/
|
|
|
|
int guessSamples(int len) const;
|
|
|
|
|
2005-06-14 20:53:20 +00:00
|
|
|
/**
|
|
|
|
* Get the data rate in bytes/s
|
|
|
|
* @return Data rate or 0 if variable/undefined
|
|
|
|
*/
|
|
|
|
int dataRate() const;
|
|
|
|
|
2005-02-06 20:13:21 +00:00
|
|
|
/**
|
|
|
|
* Default constructor - used to initialize arrays
|
|
|
|
*/
|
|
|
|
inline FormatInfo()
|
|
|
|
: name(0), type("audio"),
|
2005-06-14 20:53:20 +00:00
|
|
|
frameSize(0), frameTime(0),
|
2006-05-25 20:40:58 +00:00
|
|
|
sampleRate(8000), numChannels(1),
|
|
|
|
converter(false)
|
2005-02-06 20:13:21 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Normal constructor
|
|
|
|
*/
|
2005-06-14 20:53:20 +00:00
|
|
|
inline FormatInfo(const char* _name, int fsize = 0, int ftime = 10000,
|
2006-05-25 20:40:58 +00:00
|
|
|
const char* _type = "audio", int srate = 8000, int nchan = 1, bool convert = false)
|
2005-02-06 20:13:21 +00:00
|
|
|
: name(_name), type(_type),
|
2005-06-14 20:53:20 +00:00
|
|
|
frameSize(fsize), frameTime(ftime),
|
2006-05-25 20:40:58 +00:00
|
|
|
sampleRate(srate), numChannels(nchan),
|
|
|
|
converter(convert)
|
2005-02-06 20:13:21 +00:00
|
|
|
{ }
|
2004-11-29 21:15:59 +00:00
|
|
|
};
|
2004-05-24 00:38:23 +00:00
|
|
|
|
2005-04-25 22:19:54 +00:00
|
|
|
class CallEndpoint;
|
2005-03-28 22:27:26 +00:00
|
|
|
class Driver;
|
|
|
|
|
2004-05-24 00:38:23 +00:00
|
|
|
/**
|
|
|
|
* A structure to build (mainly static) translator capability tables.
|
|
|
|
* A table of such structures must end with an entry with null format names.
|
|
|
|
*/
|
2006-01-05 21:33:15 +00:00
|
|
|
struct YATE_API TranslatorCaps {
|
2004-05-24 00:38:23 +00:00
|
|
|
/** Description of source (input) data format */
|
2005-02-06 20:13:21 +00:00
|
|
|
const FormatInfo* src;
|
2004-05-24 00:38:23 +00:00
|
|
|
/** Description of destination (output) data format */
|
2005-02-06 20:13:21 +00:00
|
|
|
const FormatInfo* dest;
|
2004-05-24 00:38:23 +00:00
|
|
|
/** Computing cost in KIPS of converting a stream from src to dest */
|
|
|
|
int cost;
|
2004-11-29 21:15:59 +00:00
|
|
|
};
|
2004-05-24 00:38:23 +00:00
|
|
|
|
2005-02-06 20:13:21 +00:00
|
|
|
/**
|
|
|
|
* This is just a holder for the list of media formats supported by Yate
|
|
|
|
* @short A repository for media formats
|
|
|
|
*/
|
2005-04-02 00:49:38 +00:00
|
|
|
class YATE_API FormatRepository
|
2005-02-06 20:13:21 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
FormatRepository();
|
|
|
|
FormatRepository& operator=(const FormatRepository&);
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Retrieve a format by name and type
|
|
|
|
* @param name Standard name of the format to find
|
|
|
|
* @return Pointer to the format info or NULL if not found
|
|
|
|
*/
|
|
|
|
static const FormatInfo* getFormat(const String& name);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add a new format to the repository
|
|
|
|
* @param name Standard no-blanks lowercase format name
|
2005-06-14 20:53:20 +00:00
|
|
|
* @param fsize Data frame size in octets/frame, 0 for non-framed formats
|
|
|
|
* @param ftime Data frame duration in microseconds, 0 for variable
|
2005-02-06 20:13:21 +00:00
|
|
|
* @param type Format type: "audio", "video", "text"
|
|
|
|
* @param srate Rate in samples/second (audio) or 1e-6 frames/second (video), 0 for unknown
|
|
|
|
* @param nchan Number of channels, typically 1
|
|
|
|
* @return Pointer to the format info or NULL if another incompatible
|
|
|
|
* format with the same name was already registered
|
|
|
|
*/
|
2005-06-14 20:53:20 +00:00
|
|
|
static const FormatInfo* addFormat(const String& name, int fsize, int ftime, const String& type = "audio", int srate = 8000, int nchan = 1);
|
2005-02-06 20:13:21 +00:00
|
|
|
};
|
|
|
|
|
2005-04-11 00:56:55 +00:00
|
|
|
/**
|
|
|
|
* An extension of a String that can parse data formats
|
|
|
|
* @short A Data format
|
|
|
|
*/
|
|
|
|
class YATE_API DataFormat : public String
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
2006-05-25 20:40:58 +00:00
|
|
|
* Creates a new, empty format string.
|
2005-04-11 00:56:55 +00:00
|
|
|
*/
|
|
|
|
inline DataFormat()
|
|
|
|
: m_parsed(0)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new initialized format.
|
|
|
|
* @param value Initial value of the format
|
|
|
|
*/
|
|
|
|
inline DataFormat(const char* value)
|
|
|
|
: String(value), m_parsed(0)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Copy constructor.
|
|
|
|
* @param value Initial value of the format
|
|
|
|
*/
|
2006-05-25 20:40:58 +00:00
|
|
|
inline DataFormat(const DataFormat& value)
|
|
|
|
: String(value), m_parsed(value.getInfo())
|
2005-04-11 00:56:55 +00:00
|
|
|
{ }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor from String reference
|
|
|
|
* @param value Initial value of the format
|
|
|
|
*/
|
2006-05-25 20:40:58 +00:00
|
|
|
inline DataFormat(const String& value)
|
2005-04-11 00:56:55 +00:00
|
|
|
: String(value), m_parsed(0)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor from String pointer.
|
|
|
|
* @param value Initial value of the format
|
|
|
|
*/
|
2006-05-25 20:40:58 +00:00
|
|
|
inline DataFormat(const String* value)
|
2005-04-11 00:56:55 +00:00
|
|
|
: String(value), m_parsed(0)
|
|
|
|
{ }
|
|
|
|
|
2006-05-25 20:40:58 +00:00
|
|
|
/**
|
|
|
|
* Constructor from format information
|
|
|
|
* @param format Pointer to existing FormatInfo
|
|
|
|
*/
|
|
|
|
inline DataFormat(const FormatInfo* format)
|
|
|
|
: String(format ? format->name : (const char*)0), m_parsed(format)
|
|
|
|
{ }
|
|
|
|
|
2005-04-11 00:56:55 +00:00
|
|
|
/**
|
|
|
|
* Assignment operator.
|
|
|
|
*/
|
|
|
|
inline DataFormat& operator=(const DataFormat& value)
|
|
|
|
{ String::operator=(value); return *this; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrive a pointer to the format information
|
|
|
|
* @return Pointer to the associated format info or NULL if error
|
|
|
|
*/
|
|
|
|
const FormatInfo* getInfo() const;
|
|
|
|
|
2006-05-25 20:40:58 +00:00
|
|
|
/**
|
|
|
|
* Retrive the frame size
|
|
|
|
* @param defValue Default value to return if format is unknown
|
|
|
|
* @return Frame size in octets/frame, 0 for non-framed, defValue if unknown
|
|
|
|
*/
|
|
|
|
inline int frameSize(int defValue = 0) const
|
|
|
|
{ return getInfo() ? getInfo()->frameSize : defValue; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrive the frame time
|
|
|
|
* @param defValue Default value to return if format is unknown
|
|
|
|
* @return Frame time in microseconds, 0 for variable, defValue if unknown
|
|
|
|
*/
|
|
|
|
inline int frameTime(int defValue = 0) const
|
|
|
|
{ return getInfo() ? getInfo()->frameTime : defValue; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrive the sample rate
|
|
|
|
* @param defValue Default value to return if format is unknown
|
|
|
|
* @return Rate in samples/second (audio) or 1e-6 frames/second (video),
|
|
|
|
* 0 for unknown, defValue if unknown format
|
|
|
|
*/
|
|
|
|
inline int sampleRate(int defValue = 0) const
|
|
|
|
{ return getInfo() ? getInfo()->sampleRate : defValue; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrive the number of channels
|
|
|
|
* @param defValue Default value to return if format is unknown
|
|
|
|
* @return Number of channels (typically 1), defValue if unknown format
|
|
|
|
*/
|
|
|
|
inline int numChannels(int defValue = 1) const
|
|
|
|
{ return getInfo() ? getInfo()->numChannels : defValue; }
|
|
|
|
|
2005-04-11 00:56:55 +00:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Called whenever the value changed (except in constructors).
|
|
|
|
*/
|
|
|
|
virtual void changed();
|
|
|
|
|
2006-05-25 20:40:58 +00:00
|
|
|
private:
|
2005-04-11 00:56:55 +00:00
|
|
|
mutable const FormatInfo* m_parsed;
|
|
|
|
};
|
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
/**
|
|
|
|
* A generic data handling object
|
|
|
|
*/
|
2005-04-02 00:49:38 +00:00
|
|
|
class YATE_API DataNode : public RefObject
|
2004-05-22 00:05:20 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Construct a DataNode
|
2005-03-25 01:05:44 +00:00
|
|
|
* @param format Description of the data format, default none
|
2004-05-22 00:05:20 +00:00
|
|
|
*/
|
2005-04-11 00:56:55 +00:00
|
|
|
inline DataNode(const char* format = 0)
|
|
|
|
: m_format(format), m_timestamp(0)
|
|
|
|
{ }
|
2005-03-25 01:05:44 +00:00
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
/**
|
|
|
|
* Get the computing cost of converting the data to the format asked
|
|
|
|
* @param format Name of the format to check for
|
|
|
|
* @return -1 if unsupported, 0 for native format else cost in KIPS
|
|
|
|
*/
|
2005-04-11 00:56:55 +00:00
|
|
|
virtual int costFormat(const DataFormat& format)
|
2004-05-22 00:05:20 +00:00
|
|
|
{ return -1; }
|
|
|
|
|
2005-03-25 01:05:44 +00:00
|
|
|
/**
|
|
|
|
* Change the format used to transfer data
|
|
|
|
* @param format Name of the format to set for data
|
|
|
|
* @return True if the format changed successfully, false if not changed
|
|
|
|
*/
|
2005-04-11 00:56:55 +00:00
|
|
|
virtual bool setFormat(const DataFormat& format)
|
|
|
|
{ return false; }
|
2005-03-25 01:05:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the description of the format currently in use
|
|
|
|
* @return Pointer to the data format
|
|
|
|
*/
|
2005-04-11 00:56:55 +00:00
|
|
|
inline const DataFormat& getFormat() const
|
2005-03-25 01:05:44 +00:00
|
|
|
{ return m_format; }
|
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
/**
|
2004-09-29 00:15:52 +00:00
|
|
|
* Get the current position in the data stream
|
|
|
|
* @return Timestamp of current data position
|
2004-05-22 00:05:20 +00:00
|
|
|
*/
|
2004-09-29 00:15:52 +00:00
|
|
|
inline unsigned long timeStamp() const
|
|
|
|
{ return m_timestamp; }
|
|
|
|
|
2006-09-13 18:52:25 +00:00
|
|
|
/**
|
|
|
|
* Get the internal representation of an invalid or unknown timestamp
|
|
|
|
* @return Invalid timestamp - unsigned long conversion of -1
|
|
|
|
*/
|
|
|
|
inline static unsigned long invalidStamp()
|
|
|
|
{ return (unsigned long)-1; }
|
|
|
|
|
2004-09-29 00:15:52 +00:00
|
|
|
protected:
|
2005-04-11 00:56:55 +00:00
|
|
|
DataFormat m_format;
|
2004-09-29 00:15:52 +00:00
|
|
|
unsigned long m_timestamp;
|
2004-05-22 00:05:20 +00:00
|
|
|
};
|
|
|
|
|
2005-07-17 11:51:51 +00:00
|
|
|
class DataSource;
|
|
|
|
class DataTranslator;
|
|
|
|
class TranslatorFactory;
|
|
|
|
class ThreadedSourcePrivate;
|
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
/**
|
|
|
|
* A data consumer
|
|
|
|
*/
|
2005-04-02 00:49:38 +00:00
|
|
|
class YATE_API DataConsumer : public DataNode
|
2004-05-22 00:05:20 +00:00
|
|
|
{
|
|
|
|
friend class DataSource;
|
2005-03-25 01:05:44 +00:00
|
|
|
|
2005-04-11 00:56:55 +00:00
|
|
|
public:
|
2004-05-22 00:05:20 +00:00
|
|
|
/**
|
|
|
|
* Consumer constructor
|
|
|
|
* @param format Name of the data format, default "slin" (Signed Linear)
|
|
|
|
*/
|
2005-04-11 00:56:55 +00:00
|
|
|
inline DataConsumer(const char* format = "slin")
|
2005-12-30 23:51:22 +00:00
|
|
|
: DataNode(format),
|
2006-06-28 17:39:15 +00:00
|
|
|
m_source(0), m_override(0),
|
|
|
|
m_regularTsDelta(0), m_overrideTsDelta(0), m_lastTsTime(0)
|
2005-12-30 23:51:22 +00:00
|
|
|
{ }
|
2004-05-22 00:05:20 +00:00
|
|
|
|
2005-12-28 22:27:53 +00:00
|
|
|
/**
|
2007-06-08 18:33:33 +00:00
|
|
|
* Destruct notification - complains loudly if still attached to a source
|
2005-12-28 22:27:53 +00:00
|
|
|
*/
|
2007-06-08 18:33:33 +00:00
|
|
|
virtual void destroyed();
|
2005-12-28 22:27:53 +00:00
|
|
|
|
2005-04-14 03:14:20 +00:00
|
|
|
/**
|
|
|
|
* Get a pointer to a derived class given that class name
|
|
|
|
* @param name Name of the class we are asking for
|
|
|
|
* @return Pointer to the requested class or NULL if this object doesn't implement it
|
|
|
|
*/
|
|
|
|
virtual void* getObject(const String& name) const;
|
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
/**
|
|
|
|
* Consumes the data sent to it from a source
|
|
|
|
* @param data The raw data block to process; an empty block ends data
|
2005-09-06 02:51:09 +00:00
|
|
|
* @param tStamp Timestamp of data - typically samples
|
2004-05-22 00:05:20 +00:00
|
|
|
*/
|
2005-09-06 02:51:09 +00:00
|
|
|
virtual void Consume(const DataBlock& data, unsigned long tStamp) = 0;
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the data source of this object if it's connected
|
|
|
|
* @return A pointer to the DataSource object or NULL
|
|
|
|
*/
|
2005-03-25 01:05:44 +00:00
|
|
|
inline DataSource* getConnSource() const
|
2004-05-22 00:05:20 +00:00
|
|
|
{ return m_source; }
|
|
|
|
|
2005-09-28 17:41:31 +00:00
|
|
|
/**
|
|
|
|
* Get the override data source of this object if it's connected
|
|
|
|
* @return A pointer to the DataSource object or NULL
|
|
|
|
*/
|
|
|
|
inline DataSource* getOverSource() const
|
|
|
|
{ return m_override; }
|
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
/**
|
|
|
|
* Get the data source of a translator object
|
|
|
|
* @return A pointer to the DataSource object or NULL
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
virtual DataSource* getTransSource() const
|
2004-05-22 00:05:20 +00:00
|
|
|
{ return 0; }
|
|
|
|
|
2006-06-28 17:39:15 +00:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Synchronize the consumer with a source
|
|
|
|
* @param source Data source to copy the timestamp from
|
|
|
|
* @return True if we could synchronize with the source
|
|
|
|
*/
|
|
|
|
virtual bool synchronize(DataSource* source);
|
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
private:
|
2005-09-28 17:41:31 +00:00
|
|
|
void Consume(const DataBlock& data, unsigned long tStamp, DataSource* source);
|
2005-03-20 03:11:53 +00:00
|
|
|
DataSource* m_source;
|
2005-09-28 17:41:31 +00:00
|
|
|
DataSource* m_override;
|
2006-06-28 17:39:15 +00:00
|
|
|
long m_regularTsDelta;
|
2005-09-28 17:41:31 +00:00
|
|
|
long m_overrideTsDelta;
|
2005-12-30 23:51:22 +00:00
|
|
|
u_int64_t m_lastTsTime;
|
2004-05-22 00:05:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A data source
|
|
|
|
*/
|
2005-04-02 00:49:38 +00:00
|
|
|
class YATE_API DataSource : public DataNode
|
2004-05-22 00:05:20 +00:00
|
|
|
{
|
|
|
|
friend class DataTranslator;
|
2005-03-25 01:05:44 +00:00
|
|
|
|
2005-04-11 00:56:55 +00:00
|
|
|
public:
|
2004-05-22 00:05:20 +00:00
|
|
|
/**
|
|
|
|
* Source constructor
|
|
|
|
* @param format Name of the data format, default "slin" (Signed Linear)
|
|
|
|
*/
|
2005-04-11 00:56:55 +00:00
|
|
|
inline DataSource(const char* format = "slin")
|
2006-09-13 18:52:25 +00:00
|
|
|
: DataNode(format), m_nextStamp(invalidStamp()), m_translator(0) { }
|
2004-05-22 00:05:20 +00:00
|
|
|
|
2004-09-29 00:15:52 +00:00
|
|
|
/**
|
2007-06-08 18:33:33 +00:00
|
|
|
* Source's destruct notification - detaches all consumers
|
2004-09-29 00:15:52 +00:00
|
|
|
*/
|
2007-06-08 18:33:33 +00:00
|
|
|
virtual void destroyed();
|
2005-04-14 03:14:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a pointer to a derived class given that class name
|
|
|
|
* @param name Name of the class we are asking for
|
|
|
|
* @return Pointer to the requested class or NULL if this object doesn't implement it
|
|
|
|
*/
|
|
|
|
virtual void* getObject(const String& name) const;
|
2004-09-25 18:22:40 +00:00
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
/**
|
|
|
|
* Forwards the data to its consumers
|
|
|
|
* @param data The raw data block to forward; an empty block ends data
|
2005-09-06 02:51:09 +00:00
|
|
|
* @param tStamp Timestamp of data - typically samples
|
2004-05-22 00:05:20 +00:00
|
|
|
*/
|
2006-09-13 18:52:25 +00:00
|
|
|
void Forward(const DataBlock& data, unsigned long tStamp = invalidStamp());
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Attach a data consumer
|
|
|
|
* @param consumer Data consumer to attach
|
2005-09-28 17:41:31 +00:00
|
|
|
* @param override Attach as temporary source override
|
2004-05-22 00:05:20 +00:00
|
|
|
* @return True on success, false on failure
|
|
|
|
*/
|
2005-09-28 17:41:31 +00:00
|
|
|
bool attach(DataConsumer* consumer, bool override = false);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Detach a data consumer
|
|
|
|
* @param consumer Data consumer to detach
|
|
|
|
* @return True on success, false on failure
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
bool detach(DataConsumer* consumer);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Detach all data consumers
|
|
|
|
*/
|
2005-12-29 17:49:52 +00:00
|
|
|
void clear();
|
2004-05-22 00:05:20 +00:00
|
|
|
|
2005-05-16 15:03:44 +00:00
|
|
|
/**
|
|
|
|
* Get the mutex that serializes access to this data source
|
2005-07-28 01:37:19 +00:00
|
|
|
* @return Pointer to DataSource's mutex object
|
2005-05-16 15:03:44 +00:00
|
|
|
*/
|
2005-07-28 01:37:19 +00:00
|
|
|
inline Mutex* mutex()
|
|
|
|
{ return &m_mutex; }
|
2005-05-16 15:03:44 +00:00
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
/**
|
|
|
|
* Get the master translator object if this source is part of a translator
|
|
|
|
* @return A pointer to the DataTranslator object or NULL
|
|
|
|
*/
|
2005-03-25 01:05:44 +00:00
|
|
|
inline DataTranslator* getTranslator() const
|
2004-05-22 00:05:20 +00:00
|
|
|
{ return m_translator; }
|
|
|
|
|
2006-06-28 17:39:15 +00:00
|
|
|
/**
|
|
|
|
* Synchronize the source and attached consumers with another timestamp
|
|
|
|
* @param tStamp New timestamp of data - typically samples
|
|
|
|
*/
|
|
|
|
void synchronize(unsigned long tStamp);
|
|
|
|
|
2006-09-13 18:52:25 +00:00
|
|
|
/**
|
|
|
|
* Get the next expected position in the data stream
|
|
|
|
* @return Timestamp of next expected data position, may be invalid/unknown
|
|
|
|
*/
|
|
|
|
inline unsigned long nextStamp() const
|
|
|
|
{ return m_nextStamp; }
|
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
protected:
|
2006-09-13 18:52:25 +00:00
|
|
|
unsigned long m_nextStamp;
|
2005-03-20 03:11:53 +00:00
|
|
|
DataTranslator* m_translator;
|
2004-05-22 00:05:20 +00:00
|
|
|
ObjList m_consumers;
|
|
|
|
Mutex m_mutex;
|
2005-12-29 17:49:52 +00:00
|
|
|
private:
|
|
|
|
inline void setTranslator(DataTranslator* translator)
|
|
|
|
{ m_translator = translator; }
|
|
|
|
bool detachInternal(DataConsumer* consumer);
|
2004-05-22 00:05:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A data source with a thread of its own
|
|
|
|
*/
|
2005-04-02 00:49:38 +00:00
|
|
|
class YATE_API ThreadedSource : public DataSource
|
2004-05-22 00:05:20 +00:00
|
|
|
{
|
|
|
|
friend class ThreadedSourcePrivate;
|
|
|
|
public:
|
|
|
|
/**
|
2007-06-08 18:33:33 +00:00
|
|
|
* The destruction notification, stops the thread
|
2004-05-22 00:05:20 +00:00
|
|
|
*/
|
2007-06-08 18:33:33 +00:00
|
|
|
virtual void destroyed();
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
2004-11-01 00:07:00 +00:00
|
|
|
* Starts the worker thread
|
2005-04-28 22:46:59 +00:00
|
|
|
* @param name Static name of this thread
|
|
|
|
* @param prio Thread's priority
|
2004-11-01 00:07:00 +00:00
|
|
|
* @return True if started, false if an error occured
|
2004-05-22 00:05:20 +00:00
|
|
|
*/
|
2005-04-28 22:46:59 +00:00
|
|
|
bool start(const char* name = "ThreadedSource", Thread::Priority prio = Thread::Normal);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
2004-12-20 04:11:29 +00:00
|
|
|
/**
|
|
|
|
* Stops and destroys the worker thread if running
|
|
|
|
*/
|
|
|
|
void stop();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return a pointer to the worker thread
|
|
|
|
* @return Pointer to running worker thread or NULL
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
Thread* thread() const;
|
2004-12-20 04:11:29 +00:00
|
|
|
|
2007-01-12 22:16:38 +00:00
|
|
|
/**
|
|
|
|
* Check if the data thread is running
|
|
|
|
* @return True if the data thread was started and is running
|
|
|
|
*/
|
|
|
|
bool running() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the current status of the asynchronous deletion flag
|
|
|
|
*/
|
|
|
|
inline bool asyncDelete() const
|
|
|
|
{ return m_asyncDelete; }
|
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Threaded Source constructor
|
|
|
|
* @param format Name of the data format, default "slin" (Signed Linear)
|
|
|
|
*/
|
2005-04-11 00:56:55 +00:00
|
|
|
inline ThreadedSource(const char* format = "slin")
|
2007-01-12 22:16:38 +00:00
|
|
|
: DataSource(format), m_thread(0), m_asyncDelete(false)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Derived classes should call this method to let the source to be
|
|
|
|
* destroyed asynchronously in the data thread
|
|
|
|
*/
|
|
|
|
inline void asyncDelete(bool async)
|
|
|
|
{ m_asyncDelete = async; }
|
2004-05-22 00:05:20 +00:00
|
|
|
|
2007-06-08 18:33:33 +00:00
|
|
|
/**
|
|
|
|
* Clear the worker thread pointer
|
|
|
|
*/
|
|
|
|
inline void clearThread()
|
|
|
|
{ m_thread = 0; }
|
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
/**
|
|
|
|
* The worker method. You have to reimplement it as you need
|
|
|
|
*/
|
|
|
|
virtual void run() = 0;
|
|
|
|
|
|
|
|
/**
|
2007-01-12 22:16:38 +00:00
|
|
|
* The cleanup after thread method, deletes the source if already
|
|
|
|
* dereferenced and set for asynchronous deletion
|
2004-05-22 00:05:20 +00:00
|
|
|
*/
|
|
|
|
virtual void cleanup();
|
|
|
|
|
2007-01-12 22:16:38 +00:00
|
|
|
/**
|
|
|
|
* Override so destruction can be delayed after all references were lost
|
|
|
|
* to let the data pumping thread end normally
|
2007-06-08 18:33:33 +00:00
|
|
|
* @return True to delete the source right away, false to defer
|
2007-01-12 22:16:38 +00:00
|
|
|
*/
|
2007-06-08 18:33:33 +00:00
|
|
|
virtual bool zeroRefsTest();
|
2007-01-12 22:16:38 +00:00
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
private:
|
2005-03-20 03:11:53 +00:00
|
|
|
ThreadedSourcePrivate* m_thread;
|
2007-01-12 22:16:38 +00:00
|
|
|
bool m_asyncDelete;
|
2005-03-20 03:11:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The DataTranslator holds a translator (codec) capable of unidirectional
|
|
|
|
* conversion of data from one type to another.
|
|
|
|
* @short An unidirectional data translator (codec)
|
|
|
|
*/
|
2005-04-02 00:49:38 +00:00
|
|
|
class YATE_API DataTranslator : public DataConsumer
|
2005-03-20 03:11:53 +00:00
|
|
|
{
|
|
|
|
friend class TranslatorFactory;
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Construct a data translator.
|
|
|
|
* @param sFormat Name of the source format (data received from the consumer)
|
|
|
|
* @param dFormat Name of the destination format (data supplied to the source)
|
|
|
|
*/
|
|
|
|
DataTranslator(const char* sFormat, const char* dFormat);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a data translator from an existing source,
|
|
|
|
* does not increment the source's reference counter.
|
|
|
|
* @param sFormat Name of the source format (data received from the consumer)
|
|
|
|
* @param source Optional pointer to a DataSource object
|
|
|
|
*/
|
|
|
|
DataTranslator(const char* sFormat, DataSource* source = 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroys the translator and its source
|
|
|
|
*/
|
|
|
|
~DataTranslator();
|
|
|
|
|
2005-04-14 03:14:20 +00:00
|
|
|
/**
|
|
|
|
* Get a pointer to a derived class given that class name
|
|
|
|
* @param name Name of the class we are asking for
|
|
|
|
* @return Pointer to the requested class or NULL if this object doesn't implement it
|
|
|
|
*/
|
|
|
|
virtual void* getObject(const String& name) const;
|
|
|
|
|
2005-03-20 03:11:53 +00:00
|
|
|
/**
|
|
|
|
* Get the data source of a translator object
|
|
|
|
* @return A pointer to the DataSource object or NULL
|
|
|
|
*/
|
|
|
|
virtual DataSource* getTransSource() const
|
|
|
|
{ return m_tsource; }
|
|
|
|
|
|
|
|
/**
|
2006-05-25 20:40:58 +00:00
|
|
|
* Get the first translator from a chain
|
|
|
|
* @return Pointer to the first translator in a chain
|
|
|
|
*/
|
|
|
|
DataTranslator* getFirstTranslator();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constant version to get the first translator from a chain
|
|
|
|
* @return Pointer to the first translator in a chain
|
|
|
|
*/
|
|
|
|
const DataTranslator* getFirstTranslator() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of formats supported for a given output format.
|
2005-03-20 03:11:53 +00:00
|
|
|
* @param dFormat Name of destination format
|
2006-05-25 20:40:58 +00:00
|
|
|
* @param maxCost Maximum cost of candidates to consider, -1 to accept all
|
|
|
|
* @param maxLen Maximum length of codec chains to consider, 0 to accept all
|
|
|
|
* @param lst Initial list, will append to it if not empty
|
|
|
|
* @return List of source format names, must be freed by the caller
|
2005-03-20 03:11:53 +00:00
|
|
|
*/
|
2006-05-25 20:40:58 +00:00
|
|
|
static ObjList* srcFormats(const DataFormat& dFormat = "slin", int maxCost = -1, unsigned int maxLen = 0, ObjList* lst = 0);
|
2005-03-20 03:11:53 +00:00
|
|
|
|
|
|
|
/**
|
2006-05-25 20:40:58 +00:00
|
|
|
* Get a list of formats supported for a given input format
|
2005-03-20 03:11:53 +00:00
|
|
|
* @param sFormat Name of source format
|
2006-05-25 20:40:58 +00:00
|
|
|
* @param maxCost Maximum cost of candidates to consider, -1 to accept all
|
|
|
|
* @param maxLen Maximum length of codec chains to consider, 0 to accept all
|
|
|
|
* @param lst Initial list, will append to it if not empty
|
|
|
|
* @return List of destination format names, must be freed by the caller
|
2005-03-20 03:11:53 +00:00
|
|
|
*/
|
2006-05-25 20:40:58 +00:00
|
|
|
static ObjList* destFormats(const DataFormat& sFormat = "slin", int maxCost = -1, unsigned int maxLen = 0, ObjList* lst = 0);
|
2005-03-20 03:11:53 +00:00
|
|
|
|
2007-03-26 17:20:34 +00:00
|
|
|
/**
|
|
|
|
* Get a list of formats supported by transcoding for a given format list
|
|
|
|
* @param formats List of data format names
|
|
|
|
* @param existing Also return formats already existing in the initial list
|
|
|
|
* @param sameRate Only return formats with same sampling rate
|
|
|
|
* @param sameChans Only return formats with same number of channels
|
|
|
|
* @return List of format names, must be freed by the caller
|
|
|
|
*/
|
|
|
|
static ObjList* allFormats(const ObjList* formats, bool existing = true, bool sameRate = true, bool sameChans = true);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of formats supported by transcoding for a given format list
|
|
|
|
* @param formats Data format names as comma separated list
|
|
|
|
* @param existing Also return formats already existing in the initial list
|
|
|
|
* @param sameRate Only return formats with same sampling rate
|
|
|
|
* @param sameChans Only return formats with same number of channels
|
|
|
|
* @return List of format names, must be freed by the caller
|
|
|
|
*/
|
|
|
|
static ObjList* allFormats(const String& formats, bool existing = true, bool sameRate = true, bool sameChans = true);
|
|
|
|
|
2005-05-31 19:42:44 +00:00
|
|
|
/**
|
|
|
|
* Check if bidirectional conversion can be performed by installed translators
|
|
|
|
* @param fmt1 Name of the first data format
|
|
|
|
* @param fmt2 Name of the second data format
|
|
|
|
* @return True if translators can be created for both directions
|
|
|
|
*/
|
|
|
|
static bool canConvert(const DataFormat& fmt1, const DataFormat& fmt2 = "slin");
|
|
|
|
|
2005-03-20 03:11:53 +00:00
|
|
|
/**
|
|
|
|
* Finds the cost of a translator given the source and destination format names
|
|
|
|
* @param sFormat Name of the source format (data received from the consumer)
|
|
|
|
* @param dFormat Name of the destination format (data supplied to the source)
|
|
|
|
* @return Cost of best (cheapest) codec or -1 if no known codec exists
|
|
|
|
*/
|
2005-04-11 00:56:55 +00:00
|
|
|
static int cost(const DataFormat& sFormat, const DataFormat& dFormat);
|
2005-03-20 03:11:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a translator given the source and destination format names
|
|
|
|
* @param sFormat Name of the source format (data received from the consumer)
|
|
|
|
* @param dFormat Name of the destination format (data supplied to the source)
|
|
|
|
* @return A pointer to a DataTranslator object or NULL if no known codec exists
|
|
|
|
*/
|
2005-04-11 00:56:55 +00:00
|
|
|
static DataTranslator* create(const DataFormat& sFormat, const DataFormat& dFormat);
|
2005-03-20 03:11:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Attach a consumer to a source, possibly trough a chain of translators
|
|
|
|
* @param source Source to attach the chain to
|
|
|
|
* @param consumer Consumer where the chain ends
|
2005-09-28 17:41:31 +00:00
|
|
|
* @param override Attach chain for temporary source override
|
2005-03-20 03:11:53 +00:00
|
|
|
* @return True if successfull, false if no translator chain could be built
|
|
|
|
*/
|
2005-09-28 17:41:31 +00:00
|
|
|
static bool attachChain(DataSource* source, DataConsumer* consumer, bool override = false);
|
2005-03-20 03:11:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Detach a consumer from a source, possibly trough a chain of translators
|
|
|
|
* @param source Source to dettach the chain from
|
|
|
|
* @param consumer Consumer where the chain ends
|
|
|
|
* @return True if successfull, false if source and consumers were not attached
|
|
|
|
*/
|
|
|
|
static bool detachChain(DataSource* source, DataConsumer* consumer);
|
|
|
|
|
2006-05-25 20:40:58 +00:00
|
|
|
/**
|
|
|
|
* Set the length of the longest translator chain we are allowed to create
|
|
|
|
* @param maxChain Desired longest chain length
|
|
|
|
*/
|
|
|
|
static void setMaxChain(unsigned int maxChain);
|
|
|
|
|
2005-03-20 03:11:53 +00:00
|
|
|
protected:
|
2006-06-28 17:39:15 +00:00
|
|
|
/**
|
|
|
|
* Synchronize the consumer with a source
|
|
|
|
* @param source Data source to copy the timestamp from
|
|
|
|
* @return True if we could synchronize with the source
|
|
|
|
*/
|
|
|
|
virtual bool synchronize(DataSource* source);
|
|
|
|
|
2005-03-20 03:11:53 +00:00
|
|
|
/**
|
|
|
|
* Install a Translator Factory in the list of known codecs
|
|
|
|
* @param factory A pointer to a TranslatorFactory instance
|
|
|
|
*/
|
|
|
|
static void install(TranslatorFactory* factory);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a Translator Factory from the list of known codecs
|
|
|
|
* @param factory A pointer to a TranslatorFactory instance
|
|
|
|
*/
|
|
|
|
static void uninstall(TranslatorFactory* factory);
|
|
|
|
|
|
|
|
private:
|
|
|
|
DataTranslator(); // No default constructor please
|
2006-05-25 20:40:58 +00:00
|
|
|
static void compose();
|
|
|
|
static void compose(TranslatorFactory* factory);
|
|
|
|
static bool canConvert(const FormatInfo* fmt1, const FormatInfo* fmt2);
|
2005-03-20 03:11:53 +00:00
|
|
|
DataSource* m_tsource;
|
|
|
|
static Mutex s_mutex;
|
|
|
|
static ObjList s_factories;
|
2006-05-25 20:40:58 +00:00
|
|
|
static unsigned int s_maxChain;
|
2005-03-20 03:11:53 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A factory for constructing data translators by format name
|
|
|
|
* conversion of data from one type to another
|
|
|
|
* @short An unidirectional data translator (codec)
|
|
|
|
*/
|
2005-04-02 00:49:38 +00:00
|
|
|
class YATE_API TranslatorFactory : public GenObject
|
2005-03-20 03:11:53 +00:00
|
|
|
{
|
2006-05-25 20:40:58 +00:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Constructor - registers the factory in the global list
|
|
|
|
*/
|
|
|
|
inline TranslatorFactory()
|
2005-03-20 03:11:53 +00:00
|
|
|
{ DataTranslator::install(this); }
|
|
|
|
|
2006-05-25 20:40:58 +00:00
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Destructor - unregisters from the global list
|
|
|
|
*/
|
|
|
|
virtual ~TranslatorFactory();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notification that another factory was removed from the list
|
|
|
|
* @param factory Pointer to the factory that just got removed
|
|
|
|
*/
|
|
|
|
virtual void removed(const TranslatorFactory* factory);
|
2005-03-20 03:11:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a translator given the source and destination format names
|
|
|
|
* @param sFormat Name of the source format (data received from the consumer)
|
|
|
|
* @param dFormat Name of the destination format (data supplied to the source)
|
2006-05-25 20:40:58 +00:00
|
|
|
* @return A pointer to the end of a DataTranslator chain or NULL
|
2005-03-20 03:11:53 +00:00
|
|
|
*/
|
2005-04-11 00:56:55 +00:00
|
|
|
virtual DataTranslator* create(const DataFormat& sFormat, const DataFormat& dFormat) = 0;
|
2005-03-20 03:11:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the capabilities table of this translator
|
|
|
|
* @return A pointer to the first element of the capabilities table
|
|
|
|
*/
|
|
|
|
virtual const TranslatorCaps* getCapabilities() const = 0;
|
2006-05-25 20:40:58 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if this factory can build a translator for given data formats
|
|
|
|
* @param sFormat Name of the source format
|
|
|
|
* @param dFormat Name of the destination format
|
|
|
|
* @return True if a conversion between formats is possible
|
|
|
|
*/
|
|
|
|
virtual bool converts(const DataFormat& sFormat, const DataFormat& dFormat) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the length of the translator chain built by this factory
|
|
|
|
* @return How many translators will build the factory
|
|
|
|
*/
|
|
|
|
virtual unsigned int length() const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if a data format is used as intermediate in a translator chain
|
|
|
|
* @param info Format to check for
|
|
|
|
* @return True if the format is used internally as intermediate
|
|
|
|
*/
|
|
|
|
virtual bool intermediate(const FormatInfo* info) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the intermediate format used by a translator chain
|
|
|
|
* @return Pointer to intermediate format or NULL
|
|
|
|
*/
|
|
|
|
virtual const FormatInfo* intermediate() const;
|
2004-05-22 00:05:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The DataEndpoint holds an endpoint capable of performing unidirectional
|
|
|
|
* or bidirectional data transfers
|
|
|
|
* @short A data transfer endpoint capable of sending and/or receiving data
|
|
|
|
*/
|
2005-04-02 00:49:38 +00:00
|
|
|
class YATE_API DataEndpoint : public RefObject
|
2004-05-22 00:05:20 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
/**
|
2005-03-28 22:27:26 +00:00
|
|
|
* Creates an empty data endpoint
|
2004-05-22 00:05:20 +00:00
|
|
|
*/
|
2005-04-25 22:19:54 +00:00
|
|
|
DataEndpoint(CallEndpoint* call = 0, const char* name = "audio");
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
2007-06-08 18:33:33 +00:00
|
|
|
* Endpoint destruct notification, clears source and consumer
|
2004-05-22 00:05:20 +00:00
|
|
|
*/
|
2007-06-08 18:33:33 +00:00
|
|
|
virtual void destroyed();
|
2004-05-22 00:05:20 +00:00
|
|
|
|
2005-04-14 03:14:20 +00:00
|
|
|
/**
|
|
|
|
* Get a pointer to a derived class given that class name
|
|
|
|
* @param name Name of the class we are asking for
|
|
|
|
* @return Pointer to the requested class or NULL if this object doesn't implement it
|
|
|
|
*/
|
|
|
|
virtual void* getObject(const String& name) const;
|
|
|
|
|
2005-03-28 22:27:26 +00:00
|
|
|
/**
|
|
|
|
* Get a string identification of the endpoint
|
|
|
|
* @return A reference to this endpoint's name
|
|
|
|
*/
|
|
|
|
virtual const String& toString() const;
|
|
|
|
|
2005-08-02 02:20:00 +00:00
|
|
|
/**
|
|
|
|
* Get the mutex that serializes access to this data endpoint, if any
|
|
|
|
* @return Pointer to the call's mutex object or NULL
|
|
|
|
*/
|
|
|
|
Mutex* mutex() const;
|
|
|
|
|
2006-01-19 21:13:49 +00:00
|
|
|
/**
|
|
|
|
* Get the big mutex that serializes access to all data endpoints
|
|
|
|
* @return A reference to the mutex
|
|
|
|
*/
|
|
|
|
static Mutex& commonMutex();
|
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
/**
|
|
|
|
* Connect the source and consumer of the endpoint to a peer
|
|
|
|
* @param peer Pointer to the peer data endpoint
|
|
|
|
* @return True if connected, false if incompatible source/consumer
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
bool connect(DataEndpoint* peer);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Disconnect from the connected endpoint
|
2005-08-02 02:20:00 +00:00
|
|
|
* @return True if the object was deleted, false if it still exists
|
2004-05-22 00:05:20 +00:00
|
|
|
*/
|
2005-08-02 02:20:00 +00:00
|
|
|
bool disconnect();
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the data source of this object
|
|
|
|
* @param source A pointer to the new source or NULL
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
void setSource(DataSource* source = 0);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the data source of this object
|
|
|
|
* @return A pointer to the DataSource object or NULL
|
|
|
|
*/
|
2005-03-28 22:27:26 +00:00
|
|
|
inline DataSource* getSource() const
|
2004-05-22 00:05:20 +00:00
|
|
|
{ return m_source; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the data consumer of this object
|
|
|
|
* @param consumer A pointer to the new consumer or NULL
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
void setConsumer(DataConsumer* consumer = 0);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the data consumer of this object
|
|
|
|
* @return A pointer to the DataConsumer object or NULL
|
|
|
|
*/
|
2005-03-28 22:27:26 +00:00
|
|
|
inline DataConsumer* getConsumer() const
|
2004-05-22 00:05:20 +00:00
|
|
|
{ return m_consumer; }
|
|
|
|
|
2005-05-30 15:13:02 +00:00
|
|
|
/**
|
|
|
|
* Set the data consumer for recording peer generated data.
|
|
|
|
* This will be connected to the peer data source.
|
|
|
|
* @param consumer A pointer to the new consumer or NULL
|
|
|
|
*/
|
|
|
|
void setPeerRecord(DataConsumer* consumer = 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the data consumer used for recording peer generated data.
|
|
|
|
* @return A pointer to the DataConsumer object or NULL
|
|
|
|
*/
|
|
|
|
inline DataConsumer* getPeerRecord() const
|
|
|
|
{ return m_peerRecord; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the data consumer for recording local call generated data
|
|
|
|
* This will be connected to the local data source.
|
|
|
|
* @param consumer A pointer to the new consumer or NULL
|
|
|
|
*/
|
|
|
|
void setCallRecord(DataConsumer* consumer = 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the data consumer used for recording local call generated data.
|
|
|
|
* @return A pointer to the DataConsumer object or NULL
|
|
|
|
*/
|
|
|
|
inline DataConsumer* getCallRecord() const
|
|
|
|
{ return m_callRecord; }
|
|
|
|
|
2006-09-08 09:50:19 +00:00
|
|
|
/**
|
|
|
|
* Adds a data consumer to the list of sniffers of the local call data
|
|
|
|
* @param sniffer Pointer to the DataConsumer to add to sniffer list
|
|
|
|
* @return True if the sniffer was added to list, false if NULL or already added
|
|
|
|
*/
|
|
|
|
bool addSniffer(DataConsumer* sniffer);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove a data consumer from the list of sniffers of the local call data
|
|
|
|
* @param sniffer Pointer to the DataConsumer to remove from sniffer list
|
|
|
|
* @return True if the sniffer was removed from list
|
|
|
|
*/
|
|
|
|
bool delSniffer(DataConsumer* sniffer);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Find a sniffer by name
|
|
|
|
* @param name Name of the sniffer to find
|
|
|
|
* @return Pointer to DataConsumer or NULL if not found
|
|
|
|
*/
|
|
|
|
inline DataConsumer* getSniffer(const String& name)
|
|
|
|
{ return static_cast<DataConsumer*>(m_sniffers[name]); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes all sniffers from the list and dereferences them
|
|
|
|
*/
|
|
|
|
void clearSniffers();
|
|
|
|
|
2006-06-08 18:31:00 +00:00
|
|
|
/**
|
2004-05-22 00:05:20 +00:00
|
|
|
* Get a pointer to the peer endpoint
|
|
|
|
* @return A pointer to the peer endpoint or NULL
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
inline DataEndpoint* getPeer() const
|
2004-05-22 00:05:20 +00:00
|
|
|
{ return m_peer; }
|
|
|
|
|
2006-06-08 18:31:00 +00:00
|
|
|
/**
|
2005-04-25 22:19:54 +00:00
|
|
|
* Get a pointer to the owner call
|
|
|
|
* @return A pointer to the owner call or NULL
|
2005-03-28 22:27:26 +00:00
|
|
|
*/
|
2005-04-25 22:19:54 +00:00
|
|
|
inline CallEndpoint* getCall() const
|
|
|
|
{ return m_call; }
|
2005-03-28 22:27:26 +00:00
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
/**
|
|
|
|
* Get the name set in constructor
|
|
|
|
* @return A reference to the name as hashed string
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
inline const String& name() const
|
2004-05-22 00:05:20 +00:00
|
|
|
{ return m_name; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Attempt to connect the endpoint to a peer of the same type
|
|
|
|
* @param peer Pointer to the endpoint data driver
|
|
|
|
* @return True if connected, false if failed native connection
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
virtual bool nativeConnect(DataEndpoint* peer)
|
2004-05-22 00:05:20 +00:00
|
|
|
{ return false; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
String m_name;
|
2005-03-20 03:11:53 +00:00
|
|
|
DataSource* m_source;
|
|
|
|
DataConsumer* m_consumer;
|
|
|
|
DataEndpoint* m_peer;
|
2005-04-25 22:19:54 +00:00
|
|
|
CallEndpoint* m_call;
|
2005-05-30 15:13:02 +00:00
|
|
|
DataConsumer* m_peerRecord;
|
|
|
|
DataConsumer* m_callRecord;
|
2006-09-08 09:50:19 +00:00
|
|
|
ObjList m_sniffers;
|
2005-04-25 22:19:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A class that holds common call control and data related features
|
|
|
|
* @short An abstract call endpoint
|
|
|
|
*/
|
|
|
|
class YATE_API CallEndpoint : public RefObject
|
|
|
|
{
|
|
|
|
friend class DataEndpoint;
|
|
|
|
|
|
|
|
private:
|
|
|
|
CallEndpoint* m_peer;
|
2005-12-09 21:33:10 +00:00
|
|
|
String m_id;
|
2005-04-25 22:19:54 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
ObjList m_data;
|
2005-07-28 01:37:19 +00:00
|
|
|
Mutex* m_mutex;
|
2005-04-25 22:19:54 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
2007-06-08 18:33:33 +00:00
|
|
|
* Destruct notification, performs cleanups
|
2005-04-25 22:19:54 +00:00
|
|
|
*/
|
2007-06-08 18:33:33 +00:00
|
|
|
virtual void destroyed();
|
2005-04-25 22:19:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a pointer to a derived class given that class name
|
|
|
|
* @param name Name of the class we are asking for
|
|
|
|
* @return Pointer to the requested class or NULL if this object doesn't implement it
|
|
|
|
*/
|
|
|
|
virtual void* getObject(const String& name) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a string representation of this channel
|
|
|
|
* @return A reference to the name of this object
|
|
|
|
*/
|
|
|
|
virtual const String& toString() const
|
|
|
|
{ return m_id; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the unique channel identifier
|
|
|
|
* @return A String holding the unique channel id
|
|
|
|
*/
|
|
|
|
inline const String& id() const
|
|
|
|
{ return m_id; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the connected peer call
|
|
|
|
* @return Pointer to connected peer call or NULL
|
|
|
|
*/
|
|
|
|
inline CallEndpoint* getPeer() const
|
|
|
|
{ return m_peer; }
|
|
|
|
|
|
|
|
/**
|
2005-06-17 18:34:16 +00:00
|
|
|
* Get the connected peer call id
|
|
|
|
* @return Connected peer call id or empty string
|
|
|
|
*/
|
|
|
|
inline const String& getPeerId() const
|
|
|
|
{ return m_peer ? m_peer->id() : String::empty(); }
|
|
|
|
|
2005-07-28 01:37:19 +00:00
|
|
|
/**
|
|
|
|
* Get the mutex that serializes access to this call endpoint, if any
|
|
|
|
* @return Pointer to the call's mutex object or NULL
|
|
|
|
*/
|
2005-08-02 02:20:00 +00:00
|
|
|
inline Mutex* mutex() const
|
2005-07-28 01:37:19 +00:00
|
|
|
{ return m_mutex; }
|
|
|
|
|
2006-01-12 05:32:06 +00:00
|
|
|
/**
|
|
|
|
* Get the big mutex that serializes access to all call endpoints
|
|
|
|
* @return A reference to the mutex
|
|
|
|
*/
|
|
|
|
static Mutex& commonMutex();
|
|
|
|
|
2005-06-17 18:34:16 +00:00
|
|
|
/**
|
2005-04-25 22:19:54 +00:00
|
|
|
* Connect the call endpoint to a peer.
|
|
|
|
* @param peer Pointer to the peer call endpoint.
|
2005-08-02 02:20:00 +00:00
|
|
|
* @param reason Text that describes connect reason.
|
2006-03-28 22:10:35 +00:00
|
|
|
* @param notify Call disconnected() notification method on old peer
|
2005-04-25 22:19:54 +00:00
|
|
|
* @return True if connected, false if an error occured.
|
|
|
|
*/
|
2006-03-28 22:10:35 +00:00
|
|
|
bool connect(CallEndpoint* peer, const char* reason = 0, bool notify = true);
|
2005-04-25 22:19:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Disconnect from the connected peer call endpoint.
|
|
|
|
* @param reason Text that describes disconnect reason.
|
2006-03-28 22:10:35 +00:00
|
|
|
* @param notify Call disconnected() notification method on old peer
|
2005-08-02 02:20:00 +00:00
|
|
|
* @return True if the object was deleted, false if it still exists
|
2005-04-25 22:19:54 +00:00
|
|
|
*/
|
2006-03-28 22:10:35 +00:00
|
|
|
inline bool disconnect(const char* reason = 0, bool notify = true)
|
|
|
|
{ return disconnect(false,reason,notify); }
|
2005-04-25 22:19:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a data endpoint of this object
|
|
|
|
* @param type Type of data endpoint: "audio", "video", "text"
|
|
|
|
* @return A pointer to the DataEndpoint object or NULL if not found
|
|
|
|
*/
|
|
|
|
DataEndpoint* getEndpoint(const char* type = "audio") const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a data endpoint of this object, create if required
|
|
|
|
* @param type Type of data endpoint: "audio", "video", "text"
|
|
|
|
* @return A pointer to the DataEndpoint object or NULL if an error occured
|
|
|
|
*/
|
|
|
|
DataEndpoint* setEndpoint(const char* type = "audio");
|
|
|
|
|
2005-09-06 02:51:09 +00:00
|
|
|
/**
|
|
|
|
* Clear one or all data endpoints of this object
|
|
|
|
* @param type Type of data endpoint: "audio", "video", "text", NULL to clear all
|
|
|
|
*/
|
|
|
|
void clearEndpoint(const char* type = 0);
|
|
|
|
|
2005-04-25 22:19:54 +00:00
|
|
|
/**
|
|
|
|
* Set a data source of this object
|
|
|
|
* @param source A pointer to the new source or NULL
|
|
|
|
* @param type Type of data node: "audio", "video", "text"
|
|
|
|
*/
|
|
|
|
void setSource(DataSource* source = 0, const char* type = "audio");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a data source of this object
|
|
|
|
* @param type Type of data node: "audio", "video", "text"
|
|
|
|
* @return A pointer to the DataSource object or NULL
|
|
|
|
*/
|
|
|
|
DataSource* getSource(const char* type = "audio") const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the data consumer of this object
|
|
|
|
* @param consumer A pointer to the new consumer or NULL
|
|
|
|
* @param type Type of data node: "audio", "video", "text"
|
|
|
|
*/
|
|
|
|
void setConsumer(DataConsumer* consumer = 0, const char* type = "audio");
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the data consumer of this object
|
|
|
|
* @param type Type of data node: "audio", "video", "text"
|
|
|
|
* @return A pointer to the DataConsumer object or NULL
|
|
|
|
*/
|
|
|
|
DataConsumer* getConsumer(const char* type = "audio") const;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
*/
|
|
|
|
CallEndpoint(const char* id = 0);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Connect notification method.
|
2005-08-02 02:20:00 +00:00
|
|
|
* @param reason Text that describes connect reason.
|
2005-04-25 22:19:54 +00:00
|
|
|
*/
|
2005-08-02 02:20:00 +00:00
|
|
|
virtual void connected(const char* reason) { }
|
2005-04-25 22:19:54 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Disconnect notification method.
|
|
|
|
* @param final True if this disconnect was called from the destructor.
|
|
|
|
* @param reason Text that describes disconnect reason.
|
|
|
|
*/
|
|
|
|
virtual void disconnected(bool final, const char* reason) { }
|
|
|
|
|
2005-12-09 21:33:10 +00:00
|
|
|
/**
|
2005-04-25 22:19:54 +00:00
|
|
|
* Set the peer call endpoint pointer.
|
|
|
|
* @param peer A pointer to the new peer or NULL.
|
|
|
|
* @param reason Text describing the reason in case of disconnect.
|
2006-03-28 22:10:35 +00:00
|
|
|
* @param notify Call notification methods - connected() or disconnected()
|
2005-04-25 22:19:54 +00:00
|
|
|
*/
|
2006-03-28 22:10:35 +00:00
|
|
|
void setPeer(CallEndpoint* peer, const char* reason = 0, bool notify = true);
|
2005-04-25 22:19:54 +00:00
|
|
|
|
2006-12-22 16:48:51 +00:00
|
|
|
/**
|
|
|
|
* Set a foreign data endpoint in this object
|
|
|
|
* @param endPoint Data endpoint to set, will replace one with same type
|
|
|
|
*/
|
|
|
|
void setEndpoint(DataEndpoint* endPoint);
|
|
|
|
|
2005-12-09 21:33:10 +00:00
|
|
|
/**
|
|
|
|
* Set a new ID for this call endpoint
|
|
|
|
* @param newId New ID to set to this call
|
|
|
|
*/
|
|
|
|
virtual void setId(const char* newId);
|
|
|
|
|
2005-04-25 22:19:54 +00:00
|
|
|
private:
|
2006-03-28 22:10:35 +00:00
|
|
|
bool disconnect(bool final, const char* reason, bool notify);
|
2004-05-22 00:05:20 +00:00
|
|
|
};
|
|
|
|
|
2005-03-28 22:27:26 +00:00
|
|
|
/**
|
|
|
|
* Module is a descendent of Plugin specialized in implementing modules
|
|
|
|
* @short A Plugin that implements a module
|
|
|
|
*/
|
2005-04-02 00:49:38 +00:00
|
|
|
class YATE_API Module : public Plugin, public Mutex, public MessageReceiver, public DebugEnabler
|
2005-03-28 22:27:26 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
bool m_init;
|
2005-04-07 20:31:22 +00:00
|
|
|
int m_relays;
|
2005-03-28 22:27:26 +00:00
|
|
|
String m_name;
|
|
|
|
String m_type;
|
2005-12-09 21:33:10 +00:00
|
|
|
Regexp m_filter;
|
2005-04-02 00:49:38 +00:00
|
|
|
u_int64_t m_changed;
|
2005-03-28 22:27:26 +00:00
|
|
|
static unsigned int s_delay;
|
|
|
|
|
|
|
|
public:
|
2005-04-14 03:14:20 +00:00
|
|
|
/**
|
|
|
|
* Get a pointer to a derived class given that class name
|
|
|
|
* @param name Name of the class we are asking for
|
|
|
|
* @return Pointer to the requested class or NULL if this object doesn't implement it
|
|
|
|
*/
|
|
|
|
virtual void* getObject(const String& name) const;
|
|
|
|
|
2005-03-28 22:27:26 +00:00
|
|
|
/**
|
|
|
|
* Retrive the name of the module
|
|
|
|
* @return The module's name as String
|
|
|
|
*/
|
|
|
|
inline const String& name() const
|
|
|
|
{ return m_name; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrive the type of the module
|
|
|
|
* @return The module's type as String
|
|
|
|
*/
|
|
|
|
inline const String& type() const
|
|
|
|
{ return m_type; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark the driver statistics "dirty" therefore triggring a delayed
|
|
|
|
* status update.
|
|
|
|
*/
|
|
|
|
void changed();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrive the global update notification delay
|
2005-04-11 21:20:12 +00:00
|
|
|
* @return Update delay value in seconds
|
2005-03-28 22:27:26 +00:00
|
|
|
*/
|
|
|
|
inline static unsigned int updateDelay()
|
|
|
|
{ return s_delay; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the global update notification delay
|
2005-04-11 21:20:12 +00:00
|
|
|
* @param delay New update delay value in seconds, 0 to disable
|
2005-03-28 22:27:26 +00:00
|
|
|
*/
|
|
|
|
inline static void updateDelay(unsigned int delay)
|
|
|
|
{ s_delay = delay; }
|
|
|
|
|
2005-12-09 21:33:10 +00:00
|
|
|
/**
|
|
|
|
* Check if a debug filter is installed
|
|
|
|
* @return True if debugging should be filtered
|
|
|
|
*/
|
|
|
|
inline bool filterInstalled() const
|
|
|
|
{ return !m_filter.null(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check by filter rule if debugging should be active
|
|
|
|
* @param item Value of the item to match
|
|
|
|
* @return True if debugging should be activated
|
|
|
|
*/
|
|
|
|
bool filterDebug(const String& item) const;
|
|
|
|
|
2005-03-28 22:27:26 +00:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* IDs of the installed relays
|
|
|
|
*/
|
|
|
|
enum {
|
|
|
|
// Module messages
|
2006-01-23 15:57:47 +00:00
|
|
|
Status = 0x00000001,
|
|
|
|
Timer = 0x00000002,
|
|
|
|
Level = 0x00000004,
|
|
|
|
Command = 0x00000008,
|
|
|
|
Help = 0x00000010,
|
|
|
|
Halt = 0x00000020,
|
|
|
|
Route = 0x00000040,
|
2005-03-28 22:27:26 +00:00
|
|
|
// Driver messages
|
2006-01-23 15:57:47 +00:00
|
|
|
Execute = 0x00000100,
|
|
|
|
Drop = 0x00000200,
|
2005-03-28 22:27:26 +00:00
|
|
|
// Channel messages
|
2006-01-23 15:57:47 +00:00
|
|
|
Locate = 0x00000400,
|
|
|
|
Masquerade = 0x00000800,
|
|
|
|
Ringing = 0x00001000,
|
|
|
|
Answered = 0x00002000,
|
|
|
|
Tone = 0x00004000,
|
|
|
|
Text = 0x00008000,
|
|
|
|
Progress = 0x00010000,
|
|
|
|
Update = 0x00020000,
|
|
|
|
Transfer = 0x00040000,
|
2005-04-07 20:31:22 +00:00
|
|
|
// Last possible public ID
|
2006-01-23 15:57:47 +00:00
|
|
|
PubLast = 0x0fffffff,
|
2005-04-07 20:31:22 +00:00
|
|
|
// Private messages base ID
|
2006-01-23 15:57:47 +00:00
|
|
|
Private = 0x10000000
|
2005-03-28 22:27:26 +00:00
|
|
|
} RelayID;
|
|
|
|
|
2005-04-07 20:31:22 +00:00
|
|
|
/**
|
|
|
|
* Find the name of a specific Relay ID
|
|
|
|
* @param id RelayID of the message
|
|
|
|
* @return Pointer to name of the message or NULL if not found
|
|
|
|
*/
|
|
|
|
static const char* messageName(int id);
|
|
|
|
|
2005-03-28 22:27:26 +00:00
|
|
|
/**
|
|
|
|
* Constructor
|
|
|
|
* @param name Plugin name of this driver
|
|
|
|
* @param type Type of the driver: "misc", "route", etc.
|
2007-11-26 23:56:37 +00:00
|
|
|
* @param earlyInit True to attempt to initialize module before others
|
2005-03-28 22:27:26 +00:00
|
|
|
*/
|
2007-11-26 23:56:37 +00:00
|
|
|
Module(const char* name, const char* type = 0, bool earlyInit = false);
|
2005-03-28 22:27:26 +00:00
|
|
|
|
2005-06-20 20:51:17 +00:00
|
|
|
/**
|
|
|
|
* Destructor
|
|
|
|
*/
|
|
|
|
virtual ~Module();
|
|
|
|
|
2005-03-29 01:50:20 +00:00
|
|
|
/**
|
|
|
|
* This method is called to initialize the loaded module
|
|
|
|
*/
|
|
|
|
virtual void initialize();
|
|
|
|
|
2005-04-09 22:10:00 +00:00
|
|
|
/**
|
|
|
|
* Install standard message relays
|
|
|
|
*/
|
|
|
|
void setup();
|
|
|
|
|
2005-04-07 20:31:22 +00:00
|
|
|
/**
|
|
|
|
* Install a standard message relay
|
|
|
|
* @param id RelayID of the new relay to create
|
|
|
|
* @param priority Priority of the handler, 0 = top
|
|
|
|
* @return True if installed or already was one installed
|
|
|
|
*/
|
|
|
|
bool installRelay(int id, unsigned priority = 100);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Install a standard message relay
|
|
|
|
* @param name Name of the relay to create, must match a RelayID
|
|
|
|
* @param priority Priority of the handler, 0 = top
|
|
|
|
* @return True if installed or already was one installed
|
|
|
|
*/
|
|
|
|
bool installRelay(const char* name, unsigned priority = 100);
|
|
|
|
|
2008-01-28 17:24:55 +00:00
|
|
|
/**
|
|
|
|
* Install a custom message relay
|
|
|
|
* @param id RelayID of the new relay to create
|
|
|
|
* @param name Name of the custom relay to create
|
|
|
|
* @param priority Priority of the handler, 0 = top
|
|
|
|
* @return True if installed or already was one installed
|
|
|
|
*/
|
|
|
|
bool installRelay(int id, const char* name, unsigned priority = 100);
|
|
|
|
|
2008-01-26 20:43:05 +00:00
|
|
|
/**
|
|
|
|
* Install a custom message relay
|
|
|
|
* @param relay Custom message relay
|
|
|
|
* @return True if installed, false if there was already one with same ID
|
|
|
|
*/
|
|
|
|
bool installRelay(MessageRelay* relay);
|
|
|
|
|
2008-01-27 10:04:42 +00:00
|
|
|
/**
|
|
|
|
* Uninstall a message relay
|
|
|
|
* @param relay Pointer to message relay
|
|
|
|
* @param delRelay True to delete the relay after removing it
|
|
|
|
* @return True if uninstalled, false if if was not present
|
|
|
|
*/
|
|
|
|
bool uninstallRelay(MessageRelay* relay, bool delRelay = true);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Uninstall a message relay
|
|
|
|
* @param id RelayID to uninstall, relay will be deleted
|
|
|
|
* @param delRelay True to delete the relay after removing it
|
|
|
|
* @return True if uninstalled, false if if was not present
|
|
|
|
*/
|
|
|
|
bool uninstallRelay(int id, bool delRelay = true);
|
|
|
|
|
2008-01-26 20:43:05 +00:00
|
|
|
/**
|
|
|
|
* Uninstall all installed relays in preparation for unloading
|
|
|
|
* @return True if all relays were uninstalled, false if something wrong
|
|
|
|
*/
|
|
|
|
bool uninstallRelays();
|
|
|
|
|
2005-03-28 22:27:26 +00:00
|
|
|
/**
|
|
|
|
* Message receiver handler
|
|
|
|
* @param msg The received message
|
|
|
|
* @param id The identifier with which the relay was created
|
|
|
|
* @return True to stop processing, false to try other handlers
|
|
|
|
*/
|
|
|
|
virtual bool received(Message &msg, int id);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Opportunity to modify the update message
|
|
|
|
* @param msg Status update message
|
|
|
|
*/
|
|
|
|
virtual void genUpdate(Message& msg);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Timer message handler.
|
|
|
|
* @param msg Time message
|
|
|
|
*/
|
|
|
|
virtual void msgTimer(Message& msg);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Status message handler that is invoked only for matching messages.
|
|
|
|
* @param msg Status message
|
|
|
|
*/
|
|
|
|
virtual void msgStatus(Message& msg);
|
|
|
|
|
2006-01-23 15:57:47 +00:00
|
|
|
/**
|
|
|
|
* Routing message handler that is invoked for all call.route messages.
|
|
|
|
* @param msg Call routing message
|
2006-10-17 20:40:01 +00:00
|
|
|
* @return True to stop processing the message, false to try other handlers
|
2006-01-23 15:57:47 +00:00
|
|
|
*/
|
|
|
|
virtual bool msgRoute(Message& msg);
|
|
|
|
|
2006-10-17 20:40:01 +00:00
|
|
|
/**
|
|
|
|
* Handler for special commands and line completion requests.
|
|
|
|
* By default it calls @ref commandExecute() or @ref commandComplete().
|
|
|
|
* @param msg Command message
|
|
|
|
* @return True to stop processing the message, false to try other handlers
|
|
|
|
*/
|
|
|
|
virtual bool msgCommand(Message& msg);
|
|
|
|
|
2005-03-28 22:27:26 +00:00
|
|
|
/**
|
|
|
|
* Build the module identification part of the status answer
|
|
|
|
* @param str String variable to fill up
|
|
|
|
*/
|
|
|
|
virtual void statusModule(String& str);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build the parameter reporting part of the status answer
|
|
|
|
* @param str String variable to fill up
|
|
|
|
*/
|
|
|
|
virtual void statusParams(String& str);
|
|
|
|
|
2006-09-26 09:54:11 +00:00
|
|
|
/**
|
|
|
|
* Build the details reporting part of the status answer
|
|
|
|
* @param str String variable to fill up
|
|
|
|
*/
|
|
|
|
virtual void statusDetail(String& str);
|
|
|
|
|
2006-10-17 20:40:01 +00:00
|
|
|
/**
|
|
|
|
* Execute a specific command
|
|
|
|
* @param retVal String to append the textual command output to
|
|
|
|
* @param line Command line to attempt to execute
|
|
|
|
* @return True to stop processing the message, false to try other handlers
|
|
|
|
*/
|
|
|
|
virtual bool commandExecute(String& retVal, const String& line);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Complete a command line
|
|
|
|
* @param msg Message to return completion into
|
|
|
|
* @param partLine Partial line to complete, excluding the last word
|
|
|
|
* @param partWord Partial word to complete
|
|
|
|
* @return True to stop processing the message, false to try other handlers
|
|
|
|
*/
|
|
|
|
virtual bool commandComplete(Message& msg, const String& partLine, const String& partWord);
|
|
|
|
|
2005-03-28 22:27:26 +00:00
|
|
|
/**
|
|
|
|
* Set the local debugging level
|
|
|
|
* @param msg Debug setting message
|
|
|
|
* @param target String to match for local settings
|
|
|
|
*/
|
|
|
|
virtual bool setDebug(Message& msg, const String& target);
|
|
|
|
|
|
|
|
private:
|
|
|
|
Module(); // no default constructor please
|
2005-04-07 20:31:22 +00:00
|
|
|
static TokenDict s_messages[];
|
2008-01-26 20:43:05 +00:00
|
|
|
ObjList m_relayList;
|
2005-03-28 22:27:26 +00:00
|
|
|
};
|
2005-03-20 03:11:53 +00:00
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
/**
|
2005-03-20 03:11:53 +00:00
|
|
|
* A class that holds common channel related features (a.k.a. call leg)
|
|
|
|
* @short An abstract communication channel
|
2004-05-22 00:05:20 +00:00
|
|
|
*/
|
2005-04-25 22:19:54 +00:00
|
|
|
class YATE_API Channel : public CallEndpoint, public DebugEnabler
|
2004-05-22 00:05:20 +00:00
|
|
|
{
|
2005-03-28 22:27:26 +00:00
|
|
|
friend class Driver;
|
|
|
|
friend class Router;
|
|
|
|
|
2005-03-20 03:11:53 +00:00
|
|
|
private:
|
|
|
|
Driver* m_driver;
|
|
|
|
bool m_outgoing;
|
2005-04-28 22:46:59 +00:00
|
|
|
u_int64_t m_timeout;
|
2005-11-04 19:30:47 +00:00
|
|
|
u_int64_t m_maxcall;
|
2006-12-19 17:48:57 +00:00
|
|
|
mutable unsigned int m_sequence;
|
2005-03-28 22:27:26 +00:00
|
|
|
|
|
|
|
protected:
|
2005-03-20 03:11:53 +00:00
|
|
|
String m_status;
|
2005-03-28 00:58:26 +00:00
|
|
|
String m_address;
|
2005-03-28 22:27:26 +00:00
|
|
|
String m_targetid;
|
|
|
|
String m_billid;
|
2006-01-05 21:33:15 +00:00
|
|
|
bool m_answered;
|
2005-03-20 03:11:53 +00:00
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
public:
|
|
|
|
/**
|
2005-03-20 03:11:53 +00:00
|
|
|
* Destructor
|
2004-05-22 00:05:20 +00:00
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
virtual ~Channel();
|
2004-05-22 00:05:20 +00:00
|
|
|
|
2005-04-14 03:14:20 +00:00
|
|
|
/**
|
|
|
|
* Get a pointer to a derived class given that class name
|
|
|
|
* @param name Name of the class we are asking for
|
|
|
|
* @return Pointer to the requested class or NULL if this object doesn't implement it
|
|
|
|
*/
|
|
|
|
virtual void* getObject(const String& name) const;
|
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
/**
|
2005-03-20 03:11:53 +00:00
|
|
|
* Put channel variables into a message
|
|
|
|
* @param msg Message to fill in
|
2005-03-28 22:27:26 +00:00
|
|
|
* @param minimal True to fill in only a minimum of parameters
|
|
|
|
*/
|
|
|
|
virtual void complete(Message& msg, bool minimal = false) const;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a filled notification message
|
|
|
|
* @param name Name of the message to create
|
|
|
|
* @param minimal Set to true to fill in only a minimum of parameters
|
2005-06-14 20:53:20 +00:00
|
|
|
* @param data Set the channel as message data
|
2005-03-28 22:27:26 +00:00
|
|
|
* @return A new allocated and parameter filled message
|
2004-05-22 00:05:20 +00:00
|
|
|
*/
|
2005-06-14 20:53:20 +00:00
|
|
|
Message* message(const char* name, bool minimal = false, bool data = false);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
2007-01-23 00:17:11 +00:00
|
|
|
/**
|
|
|
|
* Create a filled notification message, copy some parameters from another message
|
|
|
|
* @param name Name of the message to create
|
|
|
|
* @param original Parameters to copy from, can be NULL
|
|
|
|
* @param params Comma separated list of parameters to copy,
|
|
|
|
* if NULL will be taken from the "copyparams" parameter of original
|
|
|
|
* @param minimal Set to true to fill in only a minimum of parameters
|
|
|
|
* @param data Set the channel as message data
|
|
|
|
* @return A new allocated and parameter filled message
|
|
|
|
*/
|
|
|
|
Message* message(const char* name, const NamedList* original, const char* params = 0, bool minimal = false, bool data = false);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a filled notification message, copy some parameters from another message
|
|
|
|
* @param name Name of the message to create
|
|
|
|
* @param original Parameters to copy from
|
|
|
|
* @param params Comma separated list of parameters to copy,
|
|
|
|
* if NULL will be taken from the "copyparams" parameter of original
|
|
|
|
* @param minimal Set to true to fill in only a minimum of parameters
|
|
|
|
* @param data Set the channel as message data
|
|
|
|
* @return A new allocated and parameter filled message
|
|
|
|
*/
|
|
|
|
inline Message* message(const char* name, const NamedList& original, const char* params = 0, bool minimal = false, bool data = false)
|
|
|
|
{ return message(name,&original,params,minimal,data); }
|
|
|
|
|
2005-07-12 16:05:29 +00:00
|
|
|
/**
|
|
|
|
* Notification on remote call making some progress, not enabled by default
|
|
|
|
* @param msg Notification message
|
|
|
|
* @return True to stop processing the message, false to let it flow
|
|
|
|
*/
|
|
|
|
virtual bool msgProgress(Message& msg);
|
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
/**
|
2005-03-20 03:11:53 +00:00
|
|
|
* Notification on remote ringing
|
|
|
|
* @param msg Notification message
|
|
|
|
* @return True to stop processing the message, false to let it flow
|
2004-05-22 00:05:20 +00:00
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
virtual bool msgRinging(Message& msg);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
2004-06-03 22:26:29 +00:00
|
|
|
/**
|
2006-01-05 21:33:15 +00:00
|
|
|
* Notification on remote answered. Note that the answered flag will be set
|
2005-03-20 03:11:53 +00:00
|
|
|
* @param msg Notification message
|
|
|
|
* @return True to stop processing the message, false to let it flow
|
2004-06-03 22:26:29 +00:00
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
virtual bool msgAnswered(Message& msg);
|
2004-06-03 22:26:29 +00:00
|
|
|
|
|
|
|
/**
|
2005-03-20 03:11:53 +00:00
|
|
|
* Notification on remote tone(s)
|
|
|
|
* @param msg Notification message
|
2006-06-08 18:31:00 +00:00
|
|
|
* @param tone Pointer to the received tone(s)
|
2005-03-20 03:11:53 +00:00
|
|
|
* @return True to stop processing the message, false to let it flow
|
2004-06-03 22:26:29 +00:00
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
virtual bool msgTone(Message& msg, const char* tone);
|
2004-06-03 22:26:29 +00:00
|
|
|
|
|
|
|
/**
|
2005-03-20 03:11:53 +00:00
|
|
|
* Notification on remote text messaging (sms)
|
|
|
|
* @param msg Notification message
|
|
|
|
* @param text Pointer to the received text
|
|
|
|
* @return True to stop processing the message, false to let it flow
|
2004-06-03 22:26:29 +00:00
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
virtual bool msgText(Message& msg, const char* text);
|
2004-06-03 22:26:29 +00:00
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
/**
|
2005-03-20 03:11:53 +00:00
|
|
|
* Notification on current call drop request
|
|
|
|
* @param msg Notification message
|
2005-04-09 22:10:00 +00:00
|
|
|
* @param reason Pointer to drop reason text or NULL if none provided
|
2005-03-20 03:11:53 +00:00
|
|
|
* @return True if initiated call drop, false if failed
|
2004-05-22 00:05:20 +00:00
|
|
|
*/
|
2005-04-09 22:10:00 +00:00
|
|
|
virtual bool msgDrop(Message& msg, const char* reason);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notification on native transfer request
|
|
|
|
* @param msg Notification message
|
|
|
|
* @return True to stop processing the message, false to let it flow
|
|
|
|
*/
|
|
|
|
virtual bool msgTransfer(Message& msg);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
2006-01-23 15:57:47 +00:00
|
|
|
/**
|
|
|
|
* Notification on call parameters update request
|
|
|
|
* @param msg Notification message
|
|
|
|
* @return True to stop processing the message, false to let it flow
|
|
|
|
*/
|
|
|
|
virtual bool msgUpdate(Message& msg);
|
|
|
|
|
2006-12-19 17:48:57 +00:00
|
|
|
/**
|
|
|
|
* Notification on message masquerade as channel request
|
|
|
|
* @param msg Message already modified to masquerade as this channel
|
|
|
|
* @return True to stop processing the message, false to masquerade it
|
|
|
|
*/
|
|
|
|
virtual bool msgMasquerade(Message& msg);
|
|
|
|
|
2006-02-17 15:39:36 +00:00
|
|
|
/**
|
|
|
|
* Status message handler that is invoked only for messages to this channel
|
|
|
|
* @param msg Status message
|
|
|
|
*/
|
|
|
|
virtual void msgStatus(Message& msg);
|
|
|
|
|
2006-02-28 15:12:12 +00:00
|
|
|
/**
|
|
|
|
* Timer check method, by default handles channel timeouts
|
|
|
|
* @param msg Timer message
|
|
|
|
* @param tmr Current time against which timers are compared
|
|
|
|
*/
|
|
|
|
virtual void checkTimers(Message& msg, const Time& tmr);
|
|
|
|
|
2006-01-30 20:44:03 +00:00
|
|
|
/**
|
|
|
|
* Notification on progress of prerouting incoming call
|
|
|
|
* @param msg Notification call.preroute message just after being dispatched
|
|
|
|
* @param handled True if a handler claimed having handled prerouting
|
|
|
|
* @return True to continue with the call, false to abort the route
|
|
|
|
*/
|
|
|
|
virtual bool callPrerouted(Message& msg, bool handled);
|
|
|
|
|
2005-04-29 21:07:41 +00:00
|
|
|
/**
|
2005-07-12 16:05:29 +00:00
|
|
|
* Notification on progress of routing incoming call
|
2005-04-29 21:07:41 +00:00
|
|
|
* @param msg Notification call.route message just after being dispatched
|
2005-05-14 20:03:38 +00:00
|
|
|
* @return True to continue with the call, false to abort the route
|
2005-04-29 21:07:41 +00:00
|
|
|
*/
|
2005-05-14 20:03:38 +00:00
|
|
|
virtual bool callRouted(Message& msg);
|
2005-04-29 21:07:41 +00:00
|
|
|
|
2005-03-28 22:27:26 +00:00
|
|
|
/**
|
|
|
|
* Notification on success of incoming call
|
2005-04-29 21:07:41 +00:00
|
|
|
* @param msg Notification call.execute message just after being dispatched
|
2005-03-28 22:27:26 +00:00
|
|
|
*/
|
|
|
|
virtual void callAccept(Message& msg);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notification on failure of incoming call
|
|
|
|
* @param error Standard error keyword
|
|
|
|
* @param reason Textual failure reason
|
2005-07-12 16:05:29 +00:00
|
|
|
* @param msg Pointer to message causing the rejection, if any
|
2005-03-28 22:27:26 +00:00
|
|
|
*/
|
2005-07-12 16:05:29 +00:00
|
|
|
virtual void callRejected(const char* error, const char* reason = 0, const Message* msg = 0);
|
2005-03-28 22:27:26 +00:00
|
|
|
|
2006-09-08 09:50:19 +00:00
|
|
|
/**
|
|
|
|
* Common processing after connecting the outgoing call, should be called
|
|
|
|
* from Driver's msgExecute()
|
|
|
|
* @param msg Notification call.execute message while being dispatched
|
|
|
|
*/
|
|
|
|
virtual void callConnect(Message& msg);
|
|
|
|
|
2005-03-28 22:27:26 +00:00
|
|
|
/**
|
|
|
|
* Set the local debugging level
|
|
|
|
* @param msg Debug setting message
|
|
|
|
*/
|
|
|
|
virtual bool setDebug(Message& msg);
|
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
/**
|
2005-03-20 03:11:53 +00:00
|
|
|
* Get the current status of the channel
|
|
|
|
* @return The current status as String
|
2004-05-22 00:05:20 +00:00
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
inline const String& status() const
|
|
|
|
{ return m_status; }
|
2004-05-22 00:05:20 +00:00
|
|
|
|
2005-03-28 00:58:26 +00:00
|
|
|
/**
|
|
|
|
* Get the current link address of the channel
|
2005-03-28 22:27:26 +00:00
|
|
|
* @return The protocol dependent address as String
|
2005-03-28 00:58:26 +00:00
|
|
|
*/
|
|
|
|
inline const String& address() const
|
|
|
|
{ return m_address; }
|
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
/**
|
2005-03-20 03:11:53 +00:00
|
|
|
* Get the direction of the channel
|
|
|
|
* @return True if the channel is an outgoing call (generated locally)
|
|
|
|
*/
|
2006-01-05 21:33:15 +00:00
|
|
|
inline bool isOutgoing() const
|
2005-03-20 03:11:53 +00:00
|
|
|
{ return m_outgoing; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the direction of the channel
|
|
|
|
* @return True if the channel is an incoming call (generated remotely)
|
|
|
|
*/
|
2006-01-05 21:33:15 +00:00
|
|
|
inline bool isIncoming() const
|
2005-03-20 03:11:53 +00:00
|
|
|
{ return !m_outgoing; }
|
|
|
|
|
2006-01-05 21:33:15 +00:00
|
|
|
/**
|
|
|
|
* Check if the call was answered or not
|
|
|
|
* @return True if the call was answered
|
|
|
|
*/
|
|
|
|
inline bool isAnswered() const
|
|
|
|
{ return m_answered; }
|
|
|
|
|
2005-03-28 22:27:26 +00:00
|
|
|
/**
|
|
|
|
* Get the direction of the channel as string
|
|
|
|
* @return "incoming" or "outgoing" according to the direction
|
|
|
|
*/
|
|
|
|
const char* direction() const;
|
|
|
|
|
2005-04-09 22:10:00 +00:00
|
|
|
/**
|
|
|
|
* Get the driver of this channel
|
|
|
|
* @return Pointer to this channel's driver
|
|
|
|
*/
|
|
|
|
inline Driver* driver() const
|
|
|
|
{ return m_driver; }
|
|
|
|
|
2005-04-28 22:46:59 +00:00
|
|
|
/**
|
|
|
|
* Get the time this channel will time out
|
|
|
|
* @return Timeout time or zero if no timeout
|
|
|
|
*/
|
|
|
|
inline u_int64_t timeout() const
|
|
|
|
{ return m_timeout; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the time this channel will time out
|
|
|
|
* @param tout New timeout time or zero to disable
|
|
|
|
*/
|
|
|
|
inline void timeout(u_int64_t tout)
|
|
|
|
{ m_timeout = tout; }
|
|
|
|
|
2005-11-04 19:30:47 +00:00
|
|
|
/**
|
|
|
|
* Get the time this channel will time out on outgoing calls
|
|
|
|
* @return Timeout time or zero if no timeout
|
|
|
|
*/
|
|
|
|
inline u_int64_t maxcall() const
|
|
|
|
{ return m_maxcall; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the time this channel will time out on outgoing calls
|
|
|
|
* @param tout New timeout time or zero to disable
|
|
|
|
*/
|
|
|
|
inline void maxcall(u_int64_t tout)
|
|
|
|
{ m_maxcall = tout; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the time this channel will time out on outgoing calls
|
|
|
|
* @param msg Reference of message possibly holding "maxcall" parameter
|
|
|
|
*/
|
|
|
|
inline void setMaxcall(const Message& msg)
|
|
|
|
{ setMaxcall(&msg); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the time this channel will time out on outgoing calls
|
|
|
|
* @param msg Pointer to message possibly holding "maxcall" parameter
|
|
|
|
*/
|
|
|
|
void setMaxcall(const Message* msg);
|
|
|
|
|
2005-03-20 03:11:53 +00:00
|
|
|
/**
|
|
|
|
* Get the connected channel identifier.
|
|
|
|
* @return A String holding the unique channel id of the target or an empty
|
|
|
|
* string if this channel is not connected to a target.
|
|
|
|
*/
|
|
|
|
inline const String& targetid() const
|
|
|
|
{ return m_targetid; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the billing identifier.
|
|
|
|
* @return An identifier of the call or account that will be billed for
|
|
|
|
* calls made by this channel.
|
|
|
|
*/
|
|
|
|
inline const String& billid() const
|
|
|
|
{ return m_billid; }
|
|
|
|
|
2005-03-28 22:27:26 +00:00
|
|
|
/**
|
2005-04-23 23:52:08 +00:00
|
|
|
* Start a routing thread for this channel, dereference dynamic channels
|
2005-04-09 22:10:00 +00:00
|
|
|
* @param msg Pointer to message to route, typically a "call.route", will be
|
|
|
|
* destroyed after routing fails or completes
|
|
|
|
* @return True if routing thread started successfully, false if failed
|
2005-03-28 22:27:26 +00:00
|
|
|
*/
|
2005-04-23 23:52:08 +00:00
|
|
|
bool startRouter(Message* msg);
|
2005-03-28 22:27:26 +00:00
|
|
|
|
2005-11-26 18:26:46 +00:00
|
|
|
/**
|
|
|
|
* Allocate an unique (per engine run) call ID
|
|
|
|
* @return Unique call ID number
|
|
|
|
*/
|
|
|
|
static unsigned int allocId();
|
|
|
|
|
2005-12-09 21:33:10 +00:00
|
|
|
/**
|
|
|
|
* Enable or disable debugging according to driver's filter rules
|
|
|
|
* @param item Value of the item to match
|
|
|
|
*/
|
|
|
|
void filterDebug(const String& item);
|
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
protected:
|
|
|
|
/**
|
2005-03-20 03:11:53 +00:00
|
|
|
* Constructor
|
2004-05-22 00:05:20 +00:00
|
|
|
*/
|
2005-03-29 01:50:20 +00:00
|
|
|
Channel(Driver* driver, const char* id = 0, bool outgoing = false);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Alternate constructor provided for convenience
|
|
|
|
*/
|
|
|
|
Channel(Driver& driver, const char* id = 0, bool outgoing = false);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
2005-08-02 02:20:00 +00:00
|
|
|
/**
|
|
|
|
* Perform destruction time cleanup. You can call this method earlier
|
|
|
|
* if destruction is to be postponed.
|
|
|
|
*/
|
|
|
|
void cleanup();
|
|
|
|
|
2005-06-14 20:53:20 +00:00
|
|
|
/**
|
|
|
|
* Remove the channel from the parent driver list
|
|
|
|
*/
|
2005-07-18 21:47:18 +00:00
|
|
|
void dropChan();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is overriden to safely remove the channel from the parent
|
|
|
|
* driver list before actually destroying the channel.
|
|
|
|
*/
|
|
|
|
virtual void zeroRefs();
|
2005-06-14 20:53:20 +00:00
|
|
|
|
2005-11-26 18:26:46 +00:00
|
|
|
/**
|
|
|
|
* Connect notification method.
|
|
|
|
* @param reason Text that describes connect reason.
|
|
|
|
*/
|
|
|
|
virtual void connected(const char* reason);
|
|
|
|
|
2005-04-28 22:46:59 +00:00
|
|
|
/**
|
|
|
|
* Disconnect notification method.
|
|
|
|
* @param final True if this disconnect was called from the destructor.
|
|
|
|
* @param reason Text that describes disconnect reason.
|
|
|
|
*/
|
|
|
|
virtual void disconnected(bool final, const char* reason);
|
|
|
|
|
2005-12-09 21:33:10 +00:00
|
|
|
/**
|
|
|
|
* Set a new ID for this channel
|
|
|
|
* @param newId New ID to set to this channel
|
|
|
|
*/
|
|
|
|
virtual void setId(const char* newId);
|
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
/**
|
2006-01-05 21:33:15 +00:00
|
|
|
* Set the current status of the channel.
|
|
|
|
* Note that a value of "answered" will set the answered flag
|
2005-03-20 03:11:53 +00:00
|
|
|
* @param newstat The new status as String
|
|
|
|
*/
|
2006-01-05 21:33:15 +00:00
|
|
|
void status(const char* newstat);
|
2005-03-20 03:11:53 +00:00
|
|
|
|
2006-02-17 16:57:22 +00:00
|
|
|
/**
|
|
|
|
* Build the parameter reporting part of the status answer
|
|
|
|
* @param str String variable to fill up
|
|
|
|
*/
|
|
|
|
virtual void statusParams(String& str);
|
|
|
|
|
2005-04-15 23:40:25 +00:00
|
|
|
/**
|
|
|
|
* Set the current direction of the channel
|
|
|
|
* @param outgoing True if this is an outgoing call channel
|
|
|
|
*/
|
|
|
|
inline void setOutgoing(bool outgoing = true)
|
|
|
|
{ m_outgoing = outgoing; }
|
|
|
|
|
2005-11-09 22:12:28 +00:00
|
|
|
/**
|
|
|
|
* Attempt to install an override data source to send DTMF inband.
|
|
|
|
* Needs a tone generator module capable to override with "tone/dtmfstr/xyz"
|
|
|
|
* @param tone Pointer to the tone sequence to send
|
|
|
|
* @return True on success
|
|
|
|
*/
|
|
|
|
bool dtmfInband(const char* tone);
|
|
|
|
|
2006-09-08 09:50:19 +00:00
|
|
|
/**
|
|
|
|
* Attempt to install a data sniffer to detect inband tones
|
|
|
|
* Needs a tone detector module capable of attaching sniffer consumers.
|
2006-10-17 20:40:01 +00:00
|
|
|
* @param sniffer Name of the sniffer to install, default will detect all tones
|
2006-09-08 09:50:19 +00:00
|
|
|
* @return True on success
|
|
|
|
*/
|
2006-10-17 20:40:01 +00:00
|
|
|
bool toneDetect(const char* sniffer = 0);
|
2006-09-08 09:50:19 +00:00
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
private:
|
2005-03-29 01:50:20 +00:00
|
|
|
void init();
|
2005-03-20 03:11:53 +00:00
|
|
|
Channel(); // no default constructor please
|
2004-05-22 00:05:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2005-03-28 22:27:26 +00:00
|
|
|
* Driver is a module specialized for implementing channel drivers
|
|
|
|
* @short A Channel driver module
|
2004-05-22 00:05:20 +00:00
|
|
|
*/
|
2005-04-02 00:49:38 +00:00
|
|
|
class YATE_API Driver : public Module
|
2004-05-22 00:05:20 +00:00
|
|
|
{
|
2005-03-28 22:27:26 +00:00
|
|
|
friend class Router;
|
2005-06-14 20:53:20 +00:00
|
|
|
friend class Channel;
|
2005-03-28 00:58:26 +00:00
|
|
|
|
2005-03-20 03:11:53 +00:00
|
|
|
private:
|
|
|
|
bool m_init;
|
2005-04-23 23:52:08 +00:00
|
|
|
bool m_varchan;
|
2005-03-20 03:11:53 +00:00
|
|
|
String m_prefix;
|
|
|
|
ObjList m_chans;
|
2005-03-28 22:27:26 +00:00
|
|
|
int m_routing;
|
|
|
|
int m_routed;
|
2005-06-14 20:53:20 +00:00
|
|
|
int m_total;
|
2005-03-29 01:50:20 +00:00
|
|
|
unsigned int m_nextid;
|
2005-04-28 22:46:59 +00:00
|
|
|
int m_timeout;
|
2005-04-29 21:07:41 +00:00
|
|
|
int m_maxroute;
|
|
|
|
int m_maxchans;
|
2005-03-20 03:11:53 +00:00
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
public:
|
2005-04-14 03:14:20 +00:00
|
|
|
/**
|
|
|
|
* Get a pointer to a derived class given that class name
|
|
|
|
* @param name Name of the class we are asking for
|
|
|
|
* @return Pointer to the requested class or NULL if this object doesn't implement it
|
|
|
|
*/
|
|
|
|
virtual void* getObject(const String& name) const;
|
|
|
|
|
2005-03-20 03:11:53 +00:00
|
|
|
/**
|
|
|
|
* Retrive the prefix that is used as base for all channels
|
|
|
|
* @return The driver's prefix
|
|
|
|
*/
|
|
|
|
inline const String& prefix() const
|
|
|
|
{ return m_prefix; }
|
2004-05-22 00:05:20 +00:00
|
|
|
|
2005-04-23 23:52:08 +00:00
|
|
|
/**
|
|
|
|
* Check if this driver is for dynamic (variable number) channels
|
|
|
|
* @return True if the channels are dynamic, false for fixed
|
|
|
|
*/
|
|
|
|
inline bool varchan() const
|
|
|
|
{ return m_varchan; }
|
|
|
|
|
2005-03-20 03:11:53 +00:00
|
|
|
/**
|
|
|
|
* Get the list of channels of this driver
|
|
|
|
* @return A reference to the channel list
|
|
|
|
*/
|
|
|
|
inline ObjList& channels()
|
|
|
|
{ return m_chans; }
|
2004-05-22 00:05:20 +00:00
|
|
|
|
2005-03-28 22:27:26 +00:00
|
|
|
/**
|
|
|
|
* Find a channel by id
|
|
|
|
* @param id Unique identifier of the channel to find
|
|
|
|
* @return Pointer to the channel or NULL if not found
|
|
|
|
*/
|
|
|
|
virtual Channel* find(const String& id) const;
|
|
|
|
|
2005-03-28 00:58:26 +00:00
|
|
|
/**
|
|
|
|
* Check if the driver is actively used.
|
|
|
|
* @return True if the driver is in use, false if should be ok to restart
|
|
|
|
*/
|
|
|
|
virtual bool isBusy() const;
|
|
|
|
|
2005-04-09 22:10:00 +00:00
|
|
|
/**
|
|
|
|
* Drop all current channels
|
2005-04-28 22:46:59 +00:00
|
|
|
* @param msg Notification message
|
2005-04-09 22:10:00 +00:00
|
|
|
*/
|
2005-04-28 22:46:59 +00:00
|
|
|
virtual void dropAll(Message &msg);
|
2005-04-09 22:10:00 +00:00
|
|
|
|
2005-04-29 21:07:41 +00:00
|
|
|
/**
|
|
|
|
* Check if new connections can be accepted
|
2005-08-03 02:02:50 +00:00
|
|
|
* @param routers Set to true to check routing threads for incoming connections
|
2005-04-29 21:07:41 +00:00
|
|
|
* @return True if at least one new connection can be accepted, false if not
|
|
|
|
*/
|
2005-08-03 02:02:50 +00:00
|
|
|
virtual bool canAccept(bool routers = true);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if new incoming connections can be routed
|
|
|
|
* @return True if at least one new connection can be routed, false if not
|
|
|
|
*/
|
|
|
|
virtual bool canRoute();
|
2005-04-29 21:07:41 +00:00
|
|
|
|
2005-03-29 01:50:20 +00:00
|
|
|
/**
|
|
|
|
* Get the next unique numeric id from a sequence
|
2005-04-03 21:29:45 +00:00
|
|
|
* @return A driver unique number that increments by 1 at each call
|
2005-03-29 01:50:20 +00:00
|
|
|
*/
|
|
|
|
unsigned int nextid();
|
|
|
|
|
2005-04-03 21:29:45 +00:00
|
|
|
/**
|
|
|
|
* Get the current (last used) unique numeric id from a sequence
|
|
|
|
* @return The driver unique number
|
|
|
|
*/
|
|
|
|
inline unsigned int lastid() const
|
|
|
|
{ return m_nextid; }
|
|
|
|
|
2005-04-28 22:46:59 +00:00
|
|
|
/**
|
|
|
|
* Get the default driver timeout
|
|
|
|
* @return Timeout value in milliseconds
|
|
|
|
*/
|
|
|
|
inline int timeout() const
|
|
|
|
{ return m_timeout; }
|
|
|
|
|
2005-04-29 21:07:41 +00:00
|
|
|
/**
|
|
|
|
* Get the number of calls currently in the routing stage
|
|
|
|
* @return Number of router threads currently running
|
|
|
|
*/
|
|
|
|
inline int routing() const
|
|
|
|
{ return m_routing; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the number of calls successfully routed
|
|
|
|
* @return Number of calls that have gone past the routing stage
|
|
|
|
*/
|
|
|
|
inline int routed() const
|
|
|
|
{ return m_routed; }
|
|
|
|
|
2005-06-14 20:53:20 +00:00
|
|
|
/**
|
|
|
|
* Get the total number of calls ever created
|
|
|
|
* @return Number of channels ever created for this driver
|
|
|
|
*/
|
|
|
|
inline int total() const
|
|
|
|
{ return m_total; }
|
|
|
|
|
2005-03-20 03:11:53 +00:00
|
|
|
protected:
|
2004-05-24 00:38:23 +00:00
|
|
|
/**
|
2005-03-20 03:11:53 +00:00
|
|
|
* Constructor
|
|
|
|
* @param name Plugin name of this driver
|
2005-04-15 23:40:25 +00:00
|
|
|
* @param type Type of the driver: "fixchans", "varchans", etc.
|
2004-05-24 00:38:23 +00:00
|
|
|
*/
|
2005-03-28 00:58:26 +00:00
|
|
|
Driver(const char* name, const char* type = 0);
|
2005-03-20 03:11:53 +00:00
|
|
|
|
2005-04-09 22:10:00 +00:00
|
|
|
/**
|
|
|
|
* This method is called to initialize the loaded module
|
|
|
|
*/
|
|
|
|
virtual void initialize();
|
|
|
|
|
2005-03-20 03:11:53 +00:00
|
|
|
/**
|
|
|
|
* Install standard message relays and set up the prefix
|
|
|
|
* @param prefix Prefix to use with channels of this driver
|
2005-04-09 22:10:00 +00:00
|
|
|
* @param minimal Install just a minimal set of message relays
|
2005-03-20 03:11:53 +00:00
|
|
|
*/
|
2005-04-09 22:10:00 +00:00
|
|
|
void setup(const char* prefix = 0, bool minimal = false);
|
2005-03-20 03:11:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Message receiver handler
|
|
|
|
* @param msg The received message
|
|
|
|
* @param id The identifier with which the relay was created
|
|
|
|
* @return True to stop processing, false to try other handlers
|
|
|
|
*/
|
|
|
|
virtual bool received(Message &msg, int id);
|
|
|
|
|
2005-03-28 22:27:26 +00:00
|
|
|
/**
|
|
|
|
* Opportunity to modify the update message
|
|
|
|
* @param msg Status update message
|
|
|
|
*/
|
|
|
|
virtual void genUpdate(Message& msg);
|
|
|
|
|
2005-03-20 03:11:53 +00:00
|
|
|
/**
|
|
|
|
* Create an outgoing calling channel
|
|
|
|
* @param msg Call execute message
|
|
|
|
* @param dest Destination of the new call
|
|
|
|
* @return True if outgoing call was created
|
|
|
|
*/
|
|
|
|
virtual bool msgExecute(Message& msg, String& dest) = 0;
|
|
|
|
|
2006-10-17 20:40:01 +00:00
|
|
|
/**
|
|
|
|
* Complete a command line
|
|
|
|
* @param msg Message to return completion into
|
|
|
|
* @param partLine Partial line to complete, excluding the last word
|
|
|
|
* @param partWord Partial word to complete
|
|
|
|
* @return True to stop processing the message, false to try other handlers
|
|
|
|
*/
|
|
|
|
virtual bool commandComplete(Message& msg, const String& partLine, const String& partWord);
|
|
|
|
|
2005-03-28 00:58:26 +00:00
|
|
|
/**
|
|
|
|
* Build the module identification part of the status answer
|
|
|
|
* @param str String variable to fill up
|
|
|
|
*/
|
|
|
|
virtual void statusModule(String& str);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Build the parameter reporting part of the status answer
|
|
|
|
* @param str String variable to fill up
|
|
|
|
*/
|
|
|
|
virtual void statusParams(String& str);
|
|
|
|
|
|
|
|
/**
|
2006-09-26 09:54:11 +00:00
|
|
|
* Build the channel list part of the status answer
|
2005-03-28 00:58:26 +00:00
|
|
|
* @param str String variable to fill up
|
|
|
|
*/
|
2006-10-17 20:40:01 +00:00
|
|
|
virtual void statusDetail(String& str);
|
2005-03-28 00:58:26 +00:00
|
|
|
|
2005-03-28 22:27:26 +00:00
|
|
|
/**
|
|
|
|
* Set the local debugging level
|
|
|
|
* @param msg Debug setting message
|
|
|
|
* @param target String to match for local settings
|
|
|
|
*/
|
|
|
|
virtual bool setDebug(Message& msg, const String& target);
|
|
|
|
|
2006-01-09 23:19:36 +00:00
|
|
|
/**
|
|
|
|
* Load the global limits from the main config file
|
|
|
|
*/
|
|
|
|
virtual void loadLimits();
|
|
|
|
|
2005-04-23 23:52:08 +00:00
|
|
|
/**
|
|
|
|
* Set if this driver is for dynamic (variable number) channels
|
|
|
|
* @param variable True if the channels are dynamic, false for fixed
|
|
|
|
*/
|
|
|
|
inline void varchan(bool variable)
|
|
|
|
{ m_varchan = variable; }
|
|
|
|
|
2005-04-28 22:46:59 +00:00
|
|
|
/**
|
|
|
|
* Set the default driver timeout
|
|
|
|
* @param tout New timeout in milliseconds or zero to disable
|
|
|
|
*/
|
|
|
|
inline void timeout(int tout)
|
|
|
|
{ m_timeout = tout; }
|
|
|
|
|
2005-04-29 21:07:41 +00:00
|
|
|
/**
|
|
|
|
* Set the maximum number of routing messages for this driver
|
|
|
|
* @param ncalls Number of calls to route simultaneously, zero to accept all
|
|
|
|
*/
|
|
|
|
inline void maxRoute(int ncalls)
|
|
|
|
{ m_maxroute = ncalls; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the maximum number of running channels for this driver
|
|
|
|
* @param ncalls Number of calls to run simultaneously, zero to accept all
|
|
|
|
*/
|
|
|
|
inline void maxChans(int ncalls)
|
|
|
|
{ m_maxchans = ncalls; }
|
|
|
|
|
2005-03-20 03:11:53 +00:00
|
|
|
private:
|
|
|
|
Driver(); // no default constructor please
|
2004-05-22 00:05:20 +00:00
|
|
|
};
|
|
|
|
|
2005-03-28 22:27:26 +00:00
|
|
|
/**
|
|
|
|
* Asynchronous call routing thread
|
|
|
|
* @short Call routing thread
|
|
|
|
*/
|
2005-04-02 00:49:38 +00:00
|
|
|
class YATE_API Router : public Thread
|
2005-03-28 22:27:26 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
Driver* m_driver;
|
|
|
|
String m_id;
|
|
|
|
Message* m_msg;
|
|
|
|
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Constructor - creates a new routing thread
|
|
|
|
* @param driver Pointer to the driver that asked for routing
|
|
|
|
* @param id Unique identifier of the channel being routed
|
|
|
|
* @param msg Pointer to an already filled message
|
|
|
|
*/
|
|
|
|
Router(Driver* driver, const char* id, Message* msg);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Main thread running method
|
|
|
|
*/
|
|
|
|
virtual void run();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Actual routing method
|
|
|
|
* @return True if call was successfully routed
|
|
|
|
*/
|
|
|
|
virtual bool route();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Thread cleanup handler
|
|
|
|
*/
|
|
|
|
virtual void cleanup();
|
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Get the routed channel identifier
|
|
|
|
* @return Unique id of the channel being routed
|
|
|
|
*/
|
|
|
|
const String& id() const
|
|
|
|
{ return m_id; }
|
|
|
|
};
|
|
|
|
|
2006-06-10 17:35:56 +00:00
|
|
|
/**
|
|
|
|
* Find if a string appears to be an E164 phone number
|
|
|
|
* @param str String to check
|
|
|
|
* @return True if str appears to be a valid E164 number
|
|
|
|
*/
|
|
|
|
YATE_API bool isE164(const char* str);
|
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
}; // namespace TelEngine
|
|
|
|
|
2005-03-18 18:16:59 +00:00
|
|
|
#endif /* __YATEPHONE_H */
|
2005-04-28 22:46:59 +00:00
|
|
|
|
|
|
|
/* vi: set ts=8 sw=4 sts=4 noet: */
|