#include <connection.h>
Public Types | |
enum | service_t { VOICE, FAXG3, OTHER } |
Type for describing the service of incoming and outgoing calls. More... | |
enum | disconnect_mode_t { ALL, PHYSICAL_ONLY, LOGICAL_ONLY } |
Tells disconnectCall() method how to disconnect. More... | |
enum | connection_state_t { DOWN, WAITING, UP, OTHER_STATE } |
Represents the current connection state in an easy way. More... | |
Public Member Functions | |
Connection (Capi *capi, _cdword controller, string call_from, bool clir, string call_to, service_t service, string faxStationID, string faxHeadline) throw (CapiExternalError, CapiMsgError) | |
Constructor. Create an object to initiate an outgoing call. | |
~Connection () | |
. Destructor. Deletes the connection object. | |
void | registerCallInterface (CallInterface *call_if) |
Register the instance implementing the CallInterface. | |
void | changeProtocol (service_t desired_service, string faxStationID, string faxHeadline) throw (CapiMsgError, CapiExternalError, CapiWrongState) |
Change the used B protcols (e.g. switch from speech to faxG3). | |
void | start_file_transmission (string filename) throw (CapiError,CapiWrongState,CapiExternalError,CapiMsgError) |
called to start sending of a file | |
void | stop_file_transmission () |
called to stop sending of the current file, will block until file is really finished | |
void | start_file_reception (string filename) throw (CapiWrongState, CapiExternalError) |
called to activate receive mode | |
void | stop_file_reception () |
called to stop receive mode | |
void | disconnectCall (disconnect_mode_t disconnect_mode=ALL) throw (CapiMsgError) |
Terminate this connection. | |
void | connectWaiting (service_t desired_service, string faxStationID="", string faxHeadline="") throw (CapiWrongState,CapiExternalError,CapiMsgError) |
Accept a waiting incoming call. | |
void | rejectWaiting (_cword reject) throw (CapiWrongState, CapiMsgError, CapiExternalError) |
Reject a waiting incoming call. | |
void | acceptWaiting () throw (CapiMsgError, CapiWrongState) |
disable timeout for a pending call (i.e. send ALERT) | |
void | enableDTMF () throw (CapiWrongState, CapiMsgError) |
Enable indication for DTMF signals. | |
void | disableDTMF () throw (CapiWrongState, CapiMsgError) |
Disable indication for DTMF signals. | |
string | getDTMF () |
read the saved DTMF characters | |
void | clearDTMF () |
Delete the saved DTMF characters. | |
string | getCalledPartyNumber () |
Return number of the called party (the source of the call). | |
string | getCallingPartyNumber () |
Return number of calling party (the destination of the call). | |
service_t | getService () |
Return currently used service mode. | |
_cword | getCause () |
Return disconnection cause given by the CAPI. | |
_cword | getCauseB3 () |
Return disconnection cause given by the CAPI. | |
connection_state_t | getState () |
Return the connection state. | |
fax_info_t * | getFaxInfo () |
Return fax information. | |
void | errorMessage (string message) |
Output error message. | |
void | debugMessage (string message, unsigned short level) |
Output debug message. | |
Protected Types | |
enum | plci_state_t { P0, P01, P1, P2, P3, P4, P5, P6, PACT } |
State for the physical connection as defined in the CAPI spec. More... | |
enum | ncci_state_t { N0, N01, N1, N2, N3, N4, N5, NACT } |
State for logical connection as defined in the CAPI spec. More... | |
Protected Member Functions | |
Connection (_cmsg &message, Capi *capi, unsigned short DDILength=0, unsigned short DDIBaseLength=0, std::vector< std::string > DDIStopNumbers=std::vector< std::string >()) | |
Constructor. Create an object for an incoming call. | |
void | connect_active_ind (_cmsg &message) throw (CapiWrongState, CapiMsgError) |
Called when we get CONNECT_ACTIVE_IND from CAPI. | |
void | connect_b3_ind (_cmsg &message) throw (CapiWrongState, CapiMsgError) |
called when we get CONNECT_B3_IND from CAPI | |
void | connect_b3_active_ind (_cmsg &message) throw (CapiError,CapiWrongState,CapiExternalError) |
called when we get CONNECT_B3_ACTIVE_IND from CAPI | |
void | data_b3_ind (_cmsg &message) throw (CapiError,CapiWrongState,CapiMsgError) |
called when we get DATA_B3_IND from CAPI | |
void | facility_ind_DTMF (_cmsg &message) throw (CapiError,CapiWrongState) |
called when we get FACILITY_IND from CAPI with facility selector saying it's DTMF | |
void | info_ind_alerting (_cmsg &message) throw (CapiError,CapiWrongState) |
called when we get INFO_IND from CAPI with Info number saying it's ALERTING | |
bool | info_ind_called_party_nr (_cmsg &message) throw (CapiError,CapiWrongState) |
called when we get INFO_IND from CAPI with Info number saying it's ALERTING | |
void | disconnect_b3_ind (_cmsg &message) throw (CapiError,CapiWrongState) |
called when we get DISCONNECT_B3_IND from CAPI | |
void | disconnect_ind (_cmsg &message) throw (CapiError,CapiWrongState,CapiMsgError) |
called when we get DISCONNECT_IND from CAPI | |
void | connect_conf (_cmsg &message) throw (CapiWrongState, CapiMsgError) |
called when we get CONNECT_CONF from CAPI | |
void | connect_b3_conf (_cmsg &message) throw (CapiWrongState, CapiMsgError) |
called when we get CONNECT_B3_CONF from CAPI | |
void | select_b_protocol_conf (_cmsg &message) throw (CapiError,CapiWrongState,CapiMsgError) |
called when we get SELECT_B_PROTOCOL_CONF from CAPI | |
void | alert_conf (_cmsg &message) throw (CapiError,CapiWrongState,CapiMsgError) |
called when we get ALERT_CONF from CAPI | |
void | data_b3_conf (_cmsg &message) throw (CapiError,CapiWrongState, CapiMsgError, CapiExternalError) |
called when we get DATA_B3_CONF from CAPI | |
void | facility_conf_DTMF (_cmsg &message) throw (CapiError,CapiWrongState,CapiMsgError) |
called when we get FACILITY_CONF from CAPI with facility selector saying it's DTMF | |
void | disconnect_b3_conf (_cmsg &message) throw (CapiError,CapiWrongState,CapiMsgError) |
called when we get DISCONNECT_B3_CONF from CAPI | |
void | disconnect_conf (_cmsg &message) throw (CapiError,CapiWrongState,CapiMsgError) |
called when we get DISCONNECT_CONF from CAPI | |
string | prefix () |
return a prefix containing this pointer and date for log messages | |
string | getNumber (_cstruct capi_input, bool isCallingNr) |
format the CallingPartyNr or CalledPartyNr to readable string | |
void | send_block () throw (CapiError,CapiWrongState,CapiExternalError,CapiMsgError) |
called to send next block (2048 bytes) of file | |
void | buildBconfiguration (_cdword controller, service_t service, string faxStationID, string faxHeadline, _cword &B1proto, _cword &B2proto, _cword &B3proto, _cstruct &B1config, _cstruct &B2config, _cstruct &B3config) throw (CapiExternalError) |
called to build the B Configuration info elements out of given service | |
void | convertToCP437 (string &text) |
convert a String from ISO8859-1 to CP437 (IBM PC-DOS charset) | |
Protected Attributes | |
enum Connection::plci_state_t | plci_state |
State for the physical connection as defined in the CAPI spec. | |
enum Connection::ncci_state_t | ncci_state |
State for logical connection as defined in the CAPI spec. | |
_cdword | plci |
CAPI id for call. | |
_cdword | ncci |
id for logical connection | |
service_t | service |
as described in Connection::service_t, set to the last known service (either got from ISDN or set explicitly) | |
_cword | connect_ind_msg_nr |
this is needed as connect_resp is given in another function as connect_ind | |
_cword | disconnect_cause |
the disconnect cause as given by the CAPI in DISCONNECT_IND | |
_cword | disconnect_cause_b3 |
the disconnect cause as given by the CAPI in DISCONNECT_B3_IND | |
string | call_from |
CallingPartyNumber, formatted as string with leading '0' or '+' prefix. | |
string | call_to |
CalledPartyNumber, formatted as string. | |
string | received_dtmf |
accumulates the received DTMF data, see readDTMF() | |
bool | keepPhysicalConnection |
set to true to disable auto-physical disconnect after logical disconnect for one time | |
bool | our_call |
set to true if we initiated the call (needed to know as some messages must be sent if we initiated the call) | |
CallInterface * | call_if |
pointer to the object implementing CallInterface | |
Capi * | capi |
pointer to the Capi object | |
pthread_mutex_t | send_mutex |
to realize critical sections in transmission code | |
pthread_mutex_t | receive_mutex |
to realize critical sections in reception code | |
ofstream * | file_for_reception |
NULL if no file is received, pointer to the file otherwise. | |
ifstream * | file_to_send |
NULL if no file is sent, pointer to the file otherwise. | |
ostream & | debug |
debug stream | |
ostream & | error |
stream for error messages | |
unsigned short | debug_level |
debug level | |
char | send_buffer [7][2048] |
ring buffer for sending | |
unsigned short | buffer_start |
holds the index for the first buffer currently used | |
unsigned short | buffers_used |
holds the number of currently used buffers | |
fax_info_t * | fax_info |
holds some data about fax connections | |
unsigned short | DDILength |
the length of DDI extension numbers. 0 means DDI disabled | |
unsigned short | DDIBaseLength |
the length of the base number for a PtP interface | |
vector< string > | DDIStopNumbers |
list of complete DDI extensions shorter than DDILength |
This class encapsulates one ISDN connection (physical and logical). It has two groups of methods: methods which are supposed to be called from the application (declared public) which serve to access the connection, send data, clear it etc. Also there are many message handlers implemented (declared as private) which are called by Capi::readMessage() and do the most message handling stuff.
Only one logical connection per physical connection is supported.
To communicate with the application by callback functions, the application must implement the CallInterface. The methods of this class are called if different events occur like call completion or a finished data transfer.
There are two ways how Connection objects are created:
|
|
Tells disconnectCall() method how to disconnect.
|
|
State for logical connection as defined in the CAPI spec. For complete diagrams and state definition see CAPI 2.0 spec, chapter 7.2
|
|
State for the physical connection as defined in the CAPI spec. For complete diagrams and state definition see CAPI 2.0 spec, chapter 7.2
|
|
Type for describing the service of incoming and outgoing calls. Several similar services are grouped together so the application doesn't have to distinct between speech calls originating from the analog or digital network, between devices providing a High Layer compatibility and devices which only provide bearer capabilities and so on. For outgoing calls, the most specific value will be used. For exact details concerning the different services see the parameter CIP in the CAPI spec.
|
|
Constructor. Create an object to initiate an outgoing call. This constructor is used when the application creates a Connection object manually to initiate an outgoing connection. It constructs the necessary information elements (B channel protocol settings, Number elements) and calls Capi::connect_req to initiate a call.
|
|
. Destructor. Deletes the connection object. Can block if file transmission is still in progress and/or if connection is not cleared already. Please call as soon as you don't need the object any more as this will also free some CAPI resources associated to the call. Please disconnect before deleting a Connection object! The auto-disconnect here is only supported to prevent fatal errors and won't work very nicely!! |
|
Constructor. Create an object for an incoming call. This one is used by Capi when an incoming connection triggers the automatic creation of a Connection object, i.e. when we receive a CONNECT_IND message. It only extracts some data (numbers, services, etc.) from the message and saves it in private attributes. The answer to CONNECT_IND (i.e. CONNECT_RESP) is given later by the Connection object.
|
|
disable timeout for a pending call (i.e. send ALERT) Normally, a call is indicated from ISDN and timeouts after 4 (or 8) seconds if no answer is received. If you want to accept the call, not immediately, but some secods later, you must call acceptWaiting(). This tells ISDN that we will accept it some times later (i.e. send ALERT_REQ)
|
|
called when we get ALERT_CONF from CAPI
|
|
called to build the B Configuration info elements out of given service This is a convenience function to do the quite annoying enconding stuff for the 6 B configuration parameters. It also checks if the requested controller really has this abilities and throws an exception otherwise.
|
|
Change the used B protcols (e.g. switch from speech to faxG3). You have to disconnect the logical connection before calling this method. So to change from speech to fax do:
Does nothing if the requested service is already active. Otherwise the necessary information elements are built and Capi::select_b_protocol_req is called.
|
|
Delete the saved DTMF characters.
|
|
Called when we get CONNECT_ACTIVE_IND from CAPI. This method will also send a response to Capi and initiate a B3 connection if necessary.
|
|
called when we get CONNECT_B3_ACTIVE_IND from CAPI This method will also send a response to Capi and call CallInterface::callConnected().
|
|
called when we get CONNECT_B3_CONF from CAPI
|
|
called when we get CONNECT_B3_IND from CAPI This method will also send a response to Capi.
|
|
called when we get CONNECT_CONF from CAPI
|
|
Accept a waiting incoming call. Will update the saved service to the desired_service. Calls Capi::connect_resp().
|
|
convert a String from ISO8859-1 to CP437 (IBM PC-DOS charset) Unfortunately, some CAPI drivers expect the fax headline to be given in the IBM PC-DOS charset. This method can convert the string from the normal ISO8859-1 representation to this charset.
|
|
called when we get DATA_B3_CONF from CAPI This will trigger new send_block().
|
|
called when we get DATA_B3_IND from CAPI This method will also save the received data, send a response to Capi and call CallInterface::dataIn().
|
|
Output debug message. This is intended for external use if some other part of the application wants to make a log entry. For internal use in this class just output to the stream "debug".
|
|
Disable indication for DTMF signals.
|
|
called when we get DISCONNECT_B3_CONF from CAPI
|
|
called when we get DISCONNECT_B3_IND from CAPI This method will also send a response to Capi and stop_file_transmission and stop_file_reception(). It will call CallInterface::callDisconnectedLogical() and initiate termination of physical connection.
|
|
called when we get DISCONNECT_CONF from CAPI
|
|
called when we get DISCONNECT_IND from CAPI This method will also send a response to Capi and call CallInterface::callDisconnectedPhysical().
|
|
Terminate this connection. According to the current state and the given mode, the needed steps to disconnect will be executed. If you don't specify a mode, the connection will be completely cleared (first logical, then physical). It doesn't throw any error if you call it for an already cleared connection, so it's safe to call it more than one time. To reject a waiting call you haven't accepted earlier, use rejectWaiting(), not disconnectCall(). Attention: Connection objects will not be deleted after the disconnection. You must delete the Connection object explicitly. The reason for this behavior is to allow you to get connection related information (like disconnect cause, ...) after the connection has cleared. See also CallInterface::callDisconnectedPhysical().
|
|
Enable indication for DTMF signals. Normally you get no indication when the CAPI recognizes a DTMF signal. With enableDTMF() you enable these indications. DTMF signals will be saved locally and signalled by CallInterface::gotDTMF(). You can read the saved DTMF signales with getDTMF().
|
|
Output error message. This is intended for external use if some other part of the application wants to make a error-log entry. For internal use in this class just output to the stream "error".
|
|
called when we get FACILITY_CONF from CAPI with facility selector saying it's DTMF
|
|
called when we get FACILITY_IND from CAPI with facility selector saying it's DTMF This method will save the received DTMF to received_dtmf, send a response to Capi and call CallInterface::gotDTMF().
|
|
Return number of the called party (the source of the call).
|
|
Return number of calling party (the destination of the call).
|
|
Return disconnection cause given by the CAPI. 0x33xx=see CAPI spec 0x34xx=ISDN cause, for coding of xx see ETS 300102-1.
|
|
Return disconnection cause given by the CAPI. 0x33xx=see CAPI spec 0x34xx=ISDN cause, for coding of xx see ETS 300102-1.
|
|
read the saved DTMF characters DTMF characters will only be saved if you called enableDTMF() before.
|
|
Return fax information.
|
|
format the CallingPartyNr or CalledPartyNr to readable string
|
|
Return currently used service mode.
|
|
Return the connection state.
|
|
called when we get INFO_IND from CAPI with Info number saying it's ALERTING This method will call CallInterface::alerting().
|
|
called when we get INFO_IND from CAPI with Info number saying it's ALERTING This method will understand additional Called Party Number Info Elements to get the DDI (necessary for getting the whole number in PtP configuration as the DDI is signalled after* CONNECT_IND.
|
|
return a prefix containing this pointer and date for log messages
|
|
Register the instance implementing the CallInterface.
|
|
Reject a waiting incoming call. Only use for waiting calls - to disconnect an already connected call use disconnectCall().
|
|
called when we get SELECT_B_PROTOCOL_CONF from CAPI
|
|
called to send next block (2048 bytes) of file The transmission will be controlled automatically by Connection, so you don't need to call this method directly. send_block() will automatically send as much packets as the configured window size (conf_send_buffers) permits. Will call CallInterface::transmissionComplete() if the file was transferred completely.
|
|
called to activate receive mode This method doen't do anything active, it will only set the receive mode for this connection If you don't call this, all received data is discarded. If called, the data B3 stream received is written to this file w/o changes. So it's in the native format given by CAPI (i.e. inserved A-Law for speech, SFF for FaxG3).
|
|
called to start sending of a file The transmission will be controlled automatically by Connection - no further user interaction is necessary if the whole file should be sent. The file has to be in the correct format expected by CAPI, i.e. bit-reversed A-Law, 8 khz, mono (".la" for sox) for speech, SFF for faxG3
|
|
called to stop receive mode This closes the reception file and tells us to ignore further incoming B3 data. |
|
called to stop sending of the current file, will block until file is really finished If you stop the file transmission manually, CallInterface::transferCompleted won't be called. |
|
holds the index for the first buffer currently used
|
|
holds the number of currently used buffers
|
|
CallingPartyNumber, formatted as string with leading '0' or '+' prefix.
|
|
pointer to the object implementing CallInterface
|
|
CalledPartyNumber, formatted as string.
|
|
pointer to the Capi object
|
|
this is needed as connect_resp is given in another function as connect_ind
|
|
the length of the base number for a PtP interface
|
|
the length of DDI extension numbers. 0 means DDI disabled
|
|
list of complete DDI extensions shorter than DDILength
|
|
debug stream
|
|
debug level
|
|
the disconnect cause as given by the CAPI in DISCONNECT_IND
|
|
the disconnect cause as given by the CAPI in DISCONNECT_B3_IND
|
|
stream for error messages
|
|
holds some data about fax connections
|
|
NULL if no file is received, pointer to the file otherwise.
|
|
NULL if no file is sent, pointer to the file otherwise.
|
|
set to true to disable auto-physical disconnect after logical disconnect for one time
|
|
id for logical connection
|
|
State for logical connection as defined in the CAPI spec. For complete diagrams and state definition see CAPI 2.0 spec, chapter 7.2 |
|
set to true if we initiated the call (needed to know as some messages must be sent if we initiated the call)
|
|
CAPI id for call.
|
|
State for the physical connection as defined in the CAPI spec. For complete diagrams and state definition see CAPI 2.0 spec, chapter 7.2 |
|
to realize critical sections in reception code
|
|
accumulates the received DTMF data, see readDTMF()
|
|
ring buffer for sending 7 buffers a 2048 byte mark the maximal window size handled by CAPI is empty: buffer_used==0 / is full: buffers_used==7 to forget item: buffers_used--; buffer_start++; to remember item: send_buffer[ (buffer_start+buffers_used)8 ]=item; buffers_used++ |
|
to realize critical sections in transmission code
|
|
as described in Connection::service_t, set to the last known service (either got from ISDN or set explicitly)
|