2004-05-22 00:05:20 +00:00
|
|
|
/**
|
2005-03-18 18:16:59 +00:00
|
|
|
* yatengine.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
|
|
|
* Engine, plugins and messages related classes
|
|
|
|
*
|
|
|
|
* Yet Another Telephony Engine - a fully featured software PBX and IVR
|
|
|
|
* Copyright (C) 2004 Null Team
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
2005-02-28 14:09:40 +00:00
|
|
|
*/
|
|
|
|
|
2005-04-08 10:55:22 +00:00
|
|
|
#ifndef __YATENGINE_H
|
|
|
|
#define __YATENGINE_H
|
2005-02-28 14:09:40 +00:00
|
|
|
|
2005-04-08 10:55:22 +00:00
|
|
|
#ifndef __cplusplus
|
|
|
|
#error C++ is required
|
|
|
|
#endif
|
2005-02-28 14:09:40 +00:00
|
|
|
|
2005-04-08 10:55:22 +00:00
|
|
|
#include <yateclass.h>
|
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
/**
|
2005-04-08 10:55:22 +00:00
|
|
|
* Holds all Telephony Engine related classes.
|
2004-05-22 00:05:20 +00:00
|
|
|
*/
|
2005-04-08 10:55:22 +00:00
|
|
|
namespace TelEngine {
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* A class for parsing and quickly accessing INI style configuration files
|
|
|
|
* @short Configuration file handling
|
|
|
|
*/
|
2005-04-02 00:49:38 +00:00
|
|
|
class YATE_API Configuration : public String
|
2004-05-22 00:05:20 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Create an empty configuration
|
|
|
|
*/
|
|
|
|
Configuration();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create a configuration from a file
|
|
|
|
* @param filename Name of file to initialize from
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
Configuration(const char* filename);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Assignment from string operator
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
inline Configuration& operator=(const String& value)
|
2004-05-22 00:05:20 +00:00
|
|
|
{ String::operator=(value); return *this; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the number of sections
|
|
|
|
* @return Count of sections
|
|
|
|
*/
|
|
|
|
inline unsigned int sections() const
|
|
|
|
{ return m_sections.length(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrive an entire section
|
|
|
|
* @param index Index of the section
|
|
|
|
* @return The section's content or NULL if no such section
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
NamedList* getSection(unsigned int index) const;
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrive an entire section
|
|
|
|
* @param sect Name of the section
|
|
|
|
* @return The section's content or NULL if no such section
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
NamedList* getSection(const String& sect) const;
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Locate a key/value pair in the section.
|
|
|
|
* @param sect Name of the section
|
|
|
|
* @param key Name of the key in section
|
|
|
|
* @return A pointer to the key/value pair or NULL.
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
NamedString* getKey(const String& sect, const String& key) const;
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrive the value of a key in a section.
|
|
|
|
* @param sect Name of the section
|
|
|
|
* @param key Name of the key in section
|
|
|
|
* @param defvalue Default value to return if not found
|
|
|
|
* @return The string contained in the key or the default
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
const char* getValue(const String& sect, const String& key, const char* defvalue = 0) const;
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrive the numeric value of a key in a section.
|
|
|
|
* @param sect Name of the section
|
|
|
|
* @param key Name of the key in section
|
|
|
|
* @param defvalue Default value to return if not found
|
|
|
|
* @return The number contained in the key or the default
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
int getIntValue(const String& sect, const String& key, int defvalue = 0) const;
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrive the numeric value of a key in a section trying first a table lookup.
|
|
|
|
* @param sect Name of the section
|
|
|
|
* @param key Name of the key in section
|
|
|
|
* @param tokens A pointer to an array of tokens to try to lookup
|
|
|
|
* @param defvalue Default value to return if not found
|
|
|
|
* @return The number contained in the key or the default
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
int getIntValue(const String& sect, const String& key, const TokenDict* tokens, int defvalue = 0) const;
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrive the boolean value of a key in a section.
|
|
|
|
* @param sect Name of the section
|
|
|
|
* @param key Name of the key in section
|
|
|
|
* @param defvalue Default value to return if not found
|
|
|
|
* @return The boolean value contained in the key or the default
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
bool getBoolValue(const String& sect, const String& key, bool defvalue = false) const;
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes an entire section
|
|
|
|
* @param sect Name of section to delete, NULL to delete all
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
void clearSection(const char* sect = 0);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Deletes a key/value pair
|
|
|
|
* @param sect Name of section
|
|
|
|
* @param key Name of the key to delete
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
void clearKey(const String& sect, const String& key);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
2004-12-01 00:54:04 +00:00
|
|
|
/**
|
|
|
|
* Add the value of a key in a section.
|
|
|
|
* @param sect Name of the section, will be created if missing
|
|
|
|
* @param key Name of the key to add in the section
|
|
|
|
* @param value Value to set in the key
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
void addValue(const String& sect, const char* key, const char* value = 0);
|
2004-12-01 00:54:04 +00:00
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
/**
|
|
|
|
* Set the value of a key in a section.
|
|
|
|
* @param sect Name of the section, will be created if missing
|
|
|
|
* @param key Name of the key in section, will be created if missing
|
|
|
|
* @param value Value to set in the key
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
void setValue(const String& sect, const char* key, const char* value = 0);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the numeric value of a key in a section.
|
|
|
|
* @param sect Name of the section, will be created if missing
|
|
|
|
* @param key Name of the key in section, will be created if missing
|
|
|
|
* @param value Value to set in the key
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
void setValue(const String& sect, const char* key, int value);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the boolean value of a key in a section.
|
|
|
|
* @param sect Name of the section, will be created if missing
|
|
|
|
* @param key Name of the key in section, will be created if missing
|
|
|
|
* @param value Value to set in the key
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
void setValue(const String& sect, const char* key, bool value);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Load the configuration from file
|
|
|
|
* @return True if successfull, false for failure
|
|
|
|
*/
|
|
|
|
bool load();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Save the configuration to file
|
|
|
|
* @return True if successfull, false for failure
|
|
|
|
*/
|
|
|
|
bool save() const;
|
|
|
|
|
|
|
|
private:
|
2005-03-20 03:11:53 +00:00
|
|
|
Configuration(const Configuration& value); // no copy constructor
|
|
|
|
Configuration& operator=(const Configuration& value); // no assignment please
|
|
|
|
ObjList *getSectHolder(const String& sect) const;
|
|
|
|
ObjList *makeSectHolder(const String& sect);
|
2004-05-22 00:05:20 +00:00
|
|
|
ObjList m_sections;
|
|
|
|
};
|
|
|
|
|
|
|
|
class MessageDispatcher;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class holds the messages that are moved around in the engine.
|
|
|
|
* @short A message container class
|
|
|
|
*/
|
2005-04-02 00:49:38 +00:00
|
|
|
class YATE_API Message : public NamedList
|
2004-05-22 00:05:20 +00:00
|
|
|
{
|
|
|
|
friend class MessageDispatcher;
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Creates a new message.
|
|
|
|
*
|
|
|
|
* @param name Name of the message - must not be NULL or empty
|
|
|
|
* @param retval Default return value
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
Message(const char* name, const char* retval = 0);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
2005-03-28 22:27:26 +00:00
|
|
|
/**
|
|
|
|
* Destruct the message and dereferences any user data
|
|
|
|
*/
|
|
|
|
~Message();
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Retrive a reference to the value returned by the message.
|
|
|
|
* @return A reference to the value the message will return
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
inline String& retValue()
|
2004-05-22 00:05:20 +00:00
|
|
|
{ return m_return; }
|
|
|
|
|
|
|
|
/**
|
2005-03-28 22:27:26 +00:00
|
|
|
* Retrive the object associated with the message
|
|
|
|
* @return Pointer to arbitrary user RefObject
|
2004-05-22 00:05:20 +00:00
|
|
|
*/
|
2005-03-28 22:27:26 +00:00
|
|
|
inline RefObject* userData() const
|
2004-05-22 00:05:20 +00:00
|
|
|
{ return m_data; }
|
|
|
|
|
|
|
|
/**
|
2005-03-28 22:27:26 +00:00
|
|
|
* Set obscure data associated with the message.
|
|
|
|
* The user data is reference counted to avoid stray pointers.
|
|
|
|
* @param data Pointer to arbitrary user data
|
2004-05-22 00:05:20 +00:00
|
|
|
*/
|
2005-03-28 22:27:26 +00:00
|
|
|
void userData(RefObject* data);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrive a reference to the creation time of the message.
|
|
|
|
* @return A reference to the Time when the message was created
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
inline Time& msgTime()
|
2004-05-22 00:05:20 +00:00
|
|
|
{ return m_time; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Name assignment operator
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
inline Message& operator=(const char* value)
|
2004-05-22 00:05:20 +00:00
|
|
|
{ String::operator=(value); return *this; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Encode the message into a string adequate for sending for processing
|
|
|
|
* to an external communication interface
|
|
|
|
* @param id Unique identifier to add to the string
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
String encode(const char* id) const;
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Encode the message into a string adequate for sending as answer
|
|
|
|
* to an external communication interface
|
|
|
|
* @param received True if message was processed locally
|
|
|
|
* @param id Unique identifier to add to the string
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
String encode(bool received, const char* id) const;
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Decode a string from an external communication interface for processing
|
|
|
|
* in the engine. The message is modified accordingly.
|
|
|
|
* @param str String to decode
|
|
|
|
* @param id A String object in which the identifier is stored
|
|
|
|
* @return -2 for success, -1 if the string was not a text form of a
|
|
|
|
* message, index of first erroneous character if failed
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
int decode(const char* str, String& id);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Decode a string from an external communication interface that is an
|
|
|
|
* answer to a specific external processing request.
|
|
|
|
* @param str String to decode
|
|
|
|
* @param received Pointer to variable to store the dispatch return value
|
|
|
|
* @param id The identifier expected
|
|
|
|
* @return -2 for success, -1 if the string was not the expected answer,
|
|
|
|
* index of first erroneous character if failed
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
int decode(const char* str, bool& received, const char* id);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Notify the message it has been dispatched
|
|
|
|
*/
|
|
|
|
virtual void dispatched(bool accepted)
|
|
|
|
{ }
|
|
|
|
|
|
|
|
private:
|
|
|
|
Message(); // no default constructor please
|
2005-03-20 03:11:53 +00:00
|
|
|
Message(const Message& value); // no copy constructor
|
|
|
|
Message& operator=(const Message& value); // no assignment please
|
2004-05-22 00:05:20 +00:00
|
|
|
String m_return;
|
|
|
|
Time m_time;
|
2005-03-28 22:27:26 +00:00
|
|
|
RefObject* m_data;
|
2005-03-20 03:11:53 +00:00
|
|
|
void commonEncode(String& str) const;
|
|
|
|
int commonDecode(const char* str, int offs);
|
2004-05-22 00:05:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2004-12-08 00:04:26 +00:00
|
|
|
* The purpose of this class is to hold a message received method that is
|
|
|
|
* called for matching messages. It holds as well the matching criteria
|
|
|
|
* and priority among other handlers.
|
|
|
|
* @short A message handler
|
2004-05-22 00:05:20 +00:00
|
|
|
*/
|
2005-04-02 00:49:38 +00:00
|
|
|
class YATE_API MessageHandler : public String
|
2004-05-22 00:05:20 +00:00
|
|
|
{
|
|
|
|
friend class MessageDispatcher;
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Creates a new message handler.
|
|
|
|
* @param name Name of the handled message - may be NULL
|
|
|
|
* @param priority Priority of the handler, 0 = top
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
MessageHandler(const char* name, unsigned priority = 100);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Handler destructor.
|
|
|
|
*/
|
|
|
|
virtual ~MessageHandler();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is called whenever the registered name matches the message.
|
|
|
|
* @param msg The received message
|
|
|
|
* @return True to stop processing, false to try other handlers
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
virtual bool received(Message& msg) = 0;
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Find out the priority of the handler
|
|
|
|
* @return Stored priority of the handler, 0 = top
|
|
|
|
*/
|
|
|
|
inline unsigned priority() const
|
|
|
|
{ return m_priority; }
|
|
|
|
|
2005-04-23 19:33:37 +00:00
|
|
|
/**
|
|
|
|
* Retrive the filter (if installed) associated to this handler
|
|
|
|
*/
|
|
|
|
inline const NamedString* filter() const
|
|
|
|
{ return m_filter; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a filter for this handler
|
|
|
|
* @param filter Pointer to the filter to install, will be owned and
|
|
|
|
* destroyed by the handler
|
|
|
|
*/
|
|
|
|
void setFilter(NamedString* filter);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set a filter for this handler
|
|
|
|
* @param name Name of the parameter to filter
|
|
|
|
* @param value Value of the parameter to filter
|
|
|
|
*/
|
|
|
|
inline void setFilter(const char* name, const char* value)
|
|
|
|
{ setFilter(new NamedString(name,value)); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove and destroy any filter associated to this handler
|
|
|
|
*/
|
|
|
|
void clearFilter();
|
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
private:
|
|
|
|
unsigned m_priority;
|
2005-03-20 03:11:53 +00:00
|
|
|
MessageDispatcher* m_dispatcher;
|
2005-04-23 19:33:37 +00:00
|
|
|
NamedString* m_filter;
|
2004-05-22 00:05:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2004-12-08 00:04:26 +00:00
|
|
|
* A multiple message receiver to be invoked by a message relay
|
|
|
|
* @short A multiple message receiver
|
2004-05-22 00:05:20 +00:00
|
|
|
*/
|
2005-04-02 00:49:38 +00:00
|
|
|
class YATE_API MessageReceiver : public GenObject
|
2004-05-22 00:05:20 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* This method is called from the message relay.
|
|
|
|
* @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
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
virtual bool received(Message& msg, int id) = 0;
|
2004-05-22 00:05:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* A message handler that allows to relay several messages to a single receiver
|
2004-12-08 00:04:26 +00:00
|
|
|
* @short A message handler relay
|
2004-05-22 00:05:20 +00:00
|
|
|
*/
|
2005-04-02 00:49:38 +00:00
|
|
|
class YATE_API MessageRelay : public MessageHandler
|
2004-05-22 00:05:20 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Creates a new message relay.
|
|
|
|
* @param name Name of the handled message - may be NULL
|
|
|
|
* @param receiver Receiver of th relayed messages
|
|
|
|
* @param id Numeric identifier to pass to receiver
|
|
|
|
* @param priority Priority of the handler, 0 = top
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
MessageRelay(const char* name, MessageReceiver* receiver, int id, int priority = 100)
|
2004-05-22 00:05:20 +00:00
|
|
|
: MessageHandler(name,priority), m_receiver(receiver), m_id(id) { }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This method is called whenever the registered name matches the message.
|
|
|
|
* @param msg The received message
|
|
|
|
* @return True to stop processing, false to try other handlers
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
virtual bool received(Message& msg)
|
2004-05-22 00:05:20 +00:00
|
|
|
{ return m_receiver ? m_receiver->received(msg,m_id) : false; }
|
|
|
|
|
|
|
|
private:
|
2005-03-20 03:11:53 +00:00
|
|
|
MessageReceiver* m_receiver;
|
2004-05-22 00:05:20 +00:00
|
|
|
int m_id;
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
2004-12-08 00:04:26 +00:00
|
|
|
* The dispatcher class is a hub that holds a list of handlers to be called
|
|
|
|
* for the messages that pass trough the hub. It can also handle a queue of
|
|
|
|
* messages that are typically dispatched by a separate thread.
|
|
|
|
* @short A message dispatching hub
|
2004-05-22 00:05:20 +00:00
|
|
|
*/
|
2005-04-02 00:49:38 +00:00
|
|
|
class YATE_API MessageDispatcher : public GenObject
|
2004-05-22 00:05:20 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Creates a new message dispatcher.
|
|
|
|
*/
|
|
|
|
MessageDispatcher();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroys the dispatcher and the installed handlers.
|
|
|
|
*/
|
|
|
|
~MessageDispatcher();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Installs a handler in the dispatcher.
|
|
|
|
* @param handler A pointer to the handler to install
|
|
|
|
* @return True on success, false on failure
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
bool install(MessageHandler* handler);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Uninstalls a handler from the dispatcher.
|
|
|
|
* @param handler A pointer to the handler to uninstall
|
|
|
|
* @return True on success, false on failure
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
bool uninstall(MessageHandler* handler);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatch a message to the installed handlers
|
|
|
|
* @param msg The message to dispatch
|
|
|
|
* @return True if one handler accepted it, false if all ignored
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
bool dispatch(Message& msg);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the number of messages waiting in the queue
|
|
|
|
* @return Count of messages in the queue
|
|
|
|
*/
|
|
|
|
inline unsigned int queueLength() const
|
|
|
|
{ return m_messages.count(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Put a message in the waiting queue
|
|
|
|
* @param msg The message to enqueue, will be destroyed after dispatching
|
|
|
|
* @return True if successfully queued, false otherwise
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
bool enqueue(Message* msg);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatch all messages from the waiting queue
|
|
|
|
*/
|
|
|
|
void dequeue();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatch one message from the waiting queue
|
|
|
|
* @return True if success, false if the queue is empty
|
|
|
|
*/
|
|
|
|
bool dequeueOne();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clear all the message handlers
|
|
|
|
*/
|
|
|
|
inline void clear()
|
|
|
|
{ m_handlers.clear(); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Install or remove a hook to catch messages after being dispatched
|
|
|
|
* @param hookFunc Pointer to a callback function
|
|
|
|
*/
|
|
|
|
inline void setHook(void (*hookFunc)(Message &, bool) = 0)
|
|
|
|
{ m_hook = hookFunc; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
ObjList m_handlers;
|
|
|
|
ObjList m_messages;
|
|
|
|
Mutex m_mutex;
|
2005-04-22 20:07:26 +00:00
|
|
|
unsigned int m_changes;
|
2004-05-22 00:05:20 +00:00
|
|
|
void (*m_hook)(Message &, bool);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialization and information about plugins.
|
|
|
|
* Plugins are located in @em shared libraries that are loaded at runtime.
|
|
|
|
*
|
|
|
|
*<pre>
|
|
|
|
* // Create static Plugin object by using the provided macro
|
|
|
|
* INIT_PLUGIN(Plugin);
|
|
|
|
*</pre>
|
|
|
|
* @short Plugin support
|
|
|
|
*/
|
2005-04-02 00:49:38 +00:00
|
|
|
class YATE_API Plugin : public GenObject
|
2004-05-22 00:05:20 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Creates a new Plugin container.
|
|
|
|
* @param name the undecorated name of the library that contains the plugin
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
Plugin(const char* name);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a new Plugin container.
|
|
|
|
* Alternate constructor which is also the default.
|
|
|
|
*/
|
|
|
|
Plugin();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destroys the plugin.
|
|
|
|
* The destructor must never be called directly - the Loader will do it when @ref refCount() reaches zero.
|
|
|
|
*/
|
|
|
|
virtual ~Plugin();
|
|
|
|
|
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
|
|
|
/**
|
|
|
|
* Initialize the plugin after it was loaded and registered.
|
|
|
|
*/
|
|
|
|
virtual void initialize() = 0;
|
2004-11-01 00:07:00 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the module is actively used.
|
|
|
|
* @return True if the plugin is in use, false if should be ok to restart
|
|
|
|
*/
|
|
|
|
virtual bool isBusy() const
|
|
|
|
{ return false; }
|
2004-05-22 00:05:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Macro to create static instance of the plugin
|
|
|
|
* @param pclass Class of the plugin to create
|
|
|
|
*/
|
|
|
|
#define INIT_PLUGIN(pclass) static pclass __plugin
|
|
|
|
|
|
|
|
/**
|
|
|
|
* This class holds global information about the engine.
|
|
|
|
* Note: this is a singleton class.
|
|
|
|
*
|
|
|
|
* @short Engine globals
|
|
|
|
*/
|
2005-04-02 00:49:38 +00:00
|
|
|
class YATE_API Engine
|
2004-05-22 00:05:20 +00:00
|
|
|
{
|
|
|
|
friend class EnginePrivate;
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Main entry point to be called directly from a wrapper program
|
|
|
|
* @param argc Argument count
|
|
|
|
* @param argv Argument array
|
2005-04-14 03:14:20 +00:00
|
|
|
* @param env Environment variables
|
2004-05-22 00:05:20 +00:00
|
|
|
* @return Program exit code
|
|
|
|
*/
|
2005-04-14 03:14:20 +00:00
|
|
|
static int main(int argc, const char** argv, const char** env);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Run the engine.
|
|
|
|
* @return Error code, 0 for success
|
|
|
|
*/
|
|
|
|
int run();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a pointer to the unique instance.
|
|
|
|
* @return A pointer to the singleton instance of the engine
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
static Engine* self();
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Register or unregister a plugin to the engine.
|
|
|
|
* @param plugin A pointer to the plugin to (un)register
|
|
|
|
* @param reg True to register (default), false to unregister
|
|
|
|
* @return True on success, false on failure
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
static bool Register(const Plugin* plugin, bool reg = true);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The configuration directory path
|
|
|
|
*/
|
2005-04-02 00:49:38 +00:00
|
|
|
static String configFile(const char* name);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The configuration directory path
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
inline static String& configPath()
|
2004-05-22 00:05:20 +00:00
|
|
|
{ return s_cfgpath; }
|
|
|
|
|
2005-04-28 22:46:59 +00:00
|
|
|
/**
|
|
|
|
* The configuration file suffix
|
|
|
|
*/
|
|
|
|
inline static String& configSuffix()
|
|
|
|
{ return s_cfgsuffix; }
|
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
/**
|
|
|
|
* The module loading path
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
inline static String& modulePath()
|
2004-05-22 00:05:20 +00:00
|
|
|
{ return s_modpath; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The module suffix
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
inline static String& moduleSuffix()
|
2004-05-22 00:05:20 +00:00
|
|
|
{ return s_modsuffix; }
|
|
|
|
|
2005-04-28 22:46:59 +00:00
|
|
|
/**
|
|
|
|
* The global configuration of the engine.
|
|
|
|
* You must use this resource with caution.
|
|
|
|
* Note that sections [general] [modules] [preload] and [postload] are
|
|
|
|
* reserved by the engine. Also [telephony] is reserved by the drivers.
|
|
|
|
* @return A reference to the read-only engine configuration
|
|
|
|
*/
|
|
|
|
static const Configuration& config();
|
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
/**
|
|
|
|
* Reinitialize the plugins
|
|
|
|
*/
|
|
|
|
static void init();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop the engine and the entire program
|
|
|
|
* @param code Return code of the program
|
|
|
|
*/
|
|
|
|
static void halt(unsigned int code);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the engine is currently exiting
|
|
|
|
* @return True if exiting, false in normal operation
|
|
|
|
*/
|
|
|
|
static bool exiting()
|
|
|
|
{ return (s_haltcode != -1); }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Installs a handler in the dispatcher.
|
|
|
|
* @param handler A pointer to the handler to install
|
|
|
|
* @return True on success, false on failure
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
static bool install(MessageHandler* handler);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Uninstalls a handler drom the dispatcher.
|
|
|
|
* @param handler A pointer to the handler to uninstall
|
|
|
|
* @return True on success, false on failure
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
static bool uninstall(MessageHandler* handler);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Enqueue a message in the message queue
|
2004-12-08 00:04:26 +00:00
|
|
|
* @param msg The message to enqueue, will be destroyed after dispatching
|
2004-05-22 00:05:20 +00:00
|
|
|
* @return True if enqueued, false on error (already queued)
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
static bool enqueue(Message* msg);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience function.
|
|
|
|
* Enqueue a new parameterless message in the message queue
|
2004-12-08 00:04:26 +00:00
|
|
|
* @param name Name of the parameterless message to put in queue
|
2004-05-22 00:05:20 +00:00
|
|
|
* @return True if enqueued, false on error (already queued)
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
inline static bool enqueue(const char* name)
|
2004-05-22 00:05:20 +00:00
|
|
|
{ return (name && *name) ? enqueue(new Message(name)) : false; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatch a message to the registered handlers
|
|
|
|
* @param msg Pointer to the message to dispatch
|
|
|
|
* @return True if one handler accepted it, false if all ignored
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
static bool dispatch(Message* msg);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Dispatch a message to the registered handlers
|
|
|
|
* @param msg The message to dispatch
|
|
|
|
* @return True if one handler accepted it, false if all ignored
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
static bool dispatch(Message& msg);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience function.
|
|
|
|
* Dispatch a parameterless message to the registered handlers
|
|
|
|
* @param name The name of the message to create and dispatch
|
|
|
|
* @return True if one handler accepted it, false if all ignored
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
static bool dispatch(const char* name);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Install or remove a hook to catch messages after being dispatched
|
|
|
|
* @param hookFunc Pointer to a callback function
|
|
|
|
*/
|
|
|
|
inline void setHook(void (*hookFunc)(Message &, bool) = 0)
|
|
|
|
{ m_dispatcher.setHook(hookFunc); }
|
|
|
|
|
2004-11-01 00:07:00 +00:00
|
|
|
/**
|
|
|
|
* Get a count of plugins that are actively in use
|
|
|
|
* @return Count of plugins in use
|
|
|
|
*/
|
|
|
|
int usedPlugins();
|
|
|
|
|
2004-05-22 00:05:20 +00:00
|
|
|
protected:
|
|
|
|
/**
|
|
|
|
* Destroys the engine and everything. You must not call it directly,
|
|
|
|
* @ref run() will do it for you.
|
|
|
|
*/
|
|
|
|
~Engine();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads one plugin from a shared object file
|
|
|
|
* @return True if success, false on failure
|
|
|
|
*/
|
2005-03-20 03:11:53 +00:00
|
|
|
bool loadPlugin(const char* file);
|
2004-05-22 00:05:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the plugins from the plugins directory
|
|
|
|
*/
|
|
|
|
void loadPlugins();
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initialize all registered plugins
|
|
|
|
*/
|
|
|
|
void initPlugins();
|
|
|
|
|
|
|
|
private:
|
|
|
|
Engine();
|
|
|
|
ObjList m_libs;
|
|
|
|
MessageDispatcher m_dispatcher;
|
2005-03-20 03:11:53 +00:00
|
|
|
static Engine* s_self;
|
2004-05-22 00:05:20 +00:00
|
|
|
static String s_cfgpath;
|
|
|
|
static String s_cfgsuffix;
|
|
|
|
static String s_modpath;
|
|
|
|
static String s_modsuffix;
|
|
|
|
static int s_haltcode;
|
|
|
|
};
|
|
|
|
|
|
|
|
}; // namespace TelEngine
|
|
|
|
|
2005-03-18 18:16:59 +00:00
|
|
|
#endif /* __YATENGINE_H */
|
2005-04-28 22:46:59 +00:00
|
|
|
|
|
|
|
/* vi: set ts=8 sw=4 sts=4 noet: */
|