00001 00008 /*************************************************************************** 00009 * * 00010 * This program is free software; you can redistribute it and/or modify * 00011 * it under the terms of the GNU General Public License as published by * 00012 * the Free Software Foundation; either version 2 of the License, or * 00013 * (at your option) any later version. * 00014 * * 00015 ***************************************************************************/ 00016 00017 #ifndef CONNECTION_H 00018 #define CONNECTION_H 00019 00020 #include <capi20.h> 00021 #include <string> 00022 #include <fstream> 00023 #include "capiexception.h" 00024 00025 class CallInterface; 00026 class Capi; 00027 00028 using namespace std; 00029 00048 class Connection 00049 { 00050 friend class Capi; 00051 00052 public: 00063 enum service_t { 00064 VOICE, 00065 FAXG3, 00066 OTHER 00067 }; 00068 00087 Connection (Capi* capi, _cdword controller, string call_from, bool clir, string call_to, service_t service, string faxStationID, string faxHeadline) throw (CapiExternalError, CapiMsgError); 00088 00099 ~Connection(); 00100 00105 void registerCallInterface(CallInterface *call_if); 00106 00125 void changeProtocol (service_t desired_service, string faxStationID, string faxHeadline) throw (CapiMsgError, CapiExternalError, CapiWrongState); 00126 00139 void start_file_transmission(string filename) throw (CapiWrongState, CapiExternalError, CapiMsgError); 00140 00145 void stop_file_transmission(); 00146 00158 void start_file_reception(string filename) throw (CapiWrongState, CapiExternalError); 00159 00164 void stop_file_reception(); 00165 00168 enum disconnect_mode_t { 00169 ALL, 00170 PHYSICAL_ONLY, 00171 LOGICAL_ONLY 00172 }; 00173 00192 void disconnectCall(disconnect_mode_t disconnect_mode=ALL) throw (CapiMsgError); 00193 00205 void connectWaiting(service_t desired_service, string faxStationID="", string faxHeadline="") throw (CapiWrongState, CapiExternalError, CapiMsgError); 00206 00216 void rejectWaiting(_cword reject) throw (CapiWrongState, CapiMsgError, CapiExternalError); 00217 00227 void acceptWaiting() throw (CapiMsgError, CapiWrongState); 00228 00238 void enableDTMF() throw (CapiWrongState, CapiMsgError); 00239 00245 void disableDTMF() throw (CapiWrongState, CapiMsgError); 00246 00253 string getDTMF(); 00254 00257 void clearDTMF(); 00258 00263 string getCalledPartyNumber(); 00264 00269 string getCallingPartyNumber(); 00270 00275 service_t getService(); 00276 00284 _cword getCause(); 00285 00293 _cword getCauseB3(); 00294 00295 00298 enum connection_state_t { 00299 DOWN, 00300 WAITING, 00301 UP, 00302 OTHER_STATE 00303 }; 00304 00309 connection_state_t getState(); 00310 00316 struct fax_info_t { 00317 int rate; 00318 bool hiRes; 00319 unsigned short format; 00320 int pages; 00321 std::string stationID; 00322 }; 00323 00328 fax_info_t* getFaxInfo(); 00329 00337 void errorMessage(string message); 00338 00339 00348 void debugMessage(string message, unsigned short level); 00349 00350 protected: 00351 00362 Connection (_cmsg& message, Capi *capi); 00363 00364 /********************************************************************************/ 00365 /* methods handling CAPI messages - called by the Capi class */ 00366 /********************************************************************************/ 00367 00368 /*************************** INDICATIONS ****************************************/ 00369 00379 void connect_active_ind(_cmsg& message) throw (CapiWrongState, CapiMsgError); 00380 00389 void connect_b3_ind(_cmsg& message) throw (CapiWrongState, CapiMsgError); 00390 00399 void connect_b3_active_ind(_cmsg& message) throw (CapiWrongState, CapiExternalError); 00400 00409 void data_b3_ind(_cmsg& message) throw (CapiWrongState,CapiMsgError); 00410 00419 void facility_ind_DTMF(_cmsg& message) throw (CapiWrongState); 00420 00428 void info_ind_alerting(_cmsg& message) throw (CapiWrongState); 00429 00438 void disconnect_b3_ind(_cmsg& message) throw (CapiWrongState); 00439 00448 void disconnect_ind(_cmsg& message) throw (CapiWrongState, CapiMsgError); 00449 00450 /*************************** CONFIRMATIONS **************************************/ 00451 00458 void connect_conf(_cmsg& message) throw (CapiWrongState, CapiMsgError); 00459 00466 void connect_b3_conf(_cmsg& message) throw (CapiWrongState, CapiMsgError); 00467 00474 void select_b_protocol_conf(_cmsg& message) throw (CapiWrongState, CapiMsgError); 00475 00482 void alert_conf(_cmsg& message) throw (CapiWrongState, CapiMsgError); 00483 00493 void data_b3_conf(_cmsg& message) throw (CapiWrongState, CapiMsgError, CapiExternalError); 00494 00501 void facility_conf_DTMF(_cmsg& message) throw (CapiWrongState, CapiMsgError); 00502 00509 void disconnect_b3_conf(_cmsg& message) throw (CapiWrongState, CapiMsgError); 00510 00517 void disconnect_conf(_cmsg& message) throw (CapiWrongState, CapiMsgError); 00518 00519 /********************************************************************************/ 00520 /* internal methods */ 00521 /********************************************************************************/ 00522 00527 string prefix(); 00528 00535 string getNumber (_cstruct capi_input, bool isCallingNr); 00536 00549 void send_block() throw (CapiWrongState, CapiExternalError, CapiMsgError); 00550 00571 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); 00572 00582 void convertToCP437(string &text); 00583 00584 /********************************************************************************/ 00585 /* attributes */ 00586 /********************************************************************************/ 00587 00593 enum plci_state_t { 00594 P0, 00595 P01, 00596 P1, 00597 P2, 00598 P3, 00599 P4, 00600 P5, 00601 P6, 00602 PACT 00603 } plci_state; 00604 00609 enum ncci_state_t { 00610 N0, 00611 N01, 00612 N1, 00613 N2, 00614 N3, 00615 N4, 00616 N5, 00617 NACT 00618 } ncci_state; 00619 00620 _cdword plci; 00621 _cdword ncci; 00622 00623 service_t service; 00624 00625 _cword connect_ind_msg_nr; 00626 00627 _cword disconnect_cause, 00628 disconnect_cause_b3; 00629 00630 string call_from; 00631 string call_to; 00632 00633 string received_dtmf; 00634 00635 bool keepPhysicalConnection, 00636 our_call; 00637 00638 CallInterface *call_if; 00639 Capi *capi; 00640 00641 pthread_mutex_t send_mutex, 00642 receive_mutex; 00643 00644 ofstream *file_for_reception; 00645 ifstream *file_to_send; 00646 00647 ostream &debug, 00648 &error; 00649 unsigned short debug_level; 00650 00659 char send_buffer[7][2048]; 00660 00661 unsigned short buffer_start, 00662 buffers_used; 00663 00664 fax_info_t* fax_info; 00665 }; 00666 00667 #endif 00668 00669 /* History 00670 00671 Old Log (for new changes see ChangeLog): 00672 Revision 1.6 2003/06/28 12:49:47 gernot 00673 - convert fax headline to CP437, so that german umlauts and other special 00674 characters will work now 00675 00676 Revision 1.5 2003/05/25 13:38:30 gernot 00677 - support reception of color fax documents 00678 00679 Revision 1.4 2003/05/24 13:48:54 gernot 00680 - get fax details (calling station ID, transfer format, ...), handle PLCI 00681 00682 Revision 1.3 2003/04/17 10:39:42 gernot 00683 - support ALERTING notification (to know when it's ringing on the other side) 00684 - cosmetical fixes in capi.cpp 00685 00686 Revision 1.2 2003/04/04 09:17:59 gernot 00687 - buildBconfiguration() now checks the abilities of the given controller 00688 and throws an error if it doesn't support the service 00689 - it also sets the fax protocol setting now the highest available ability 00690 (fax G3 or fax G3 extended) of the controller, thus preparing fax polling 00691 and *working around a severe bug in the AVM drivers producing a kernel 00692 oops* with some analog fax devices. AVM knows about this and analyzes it. 00693 00694 Revision 1.1.1.1 2003/02/19 08:19:53 gernot 00695 initial checkin of 0.4 00696 00697 Revision 1.30 2003/02/10 14:20:52 ghillie 00698 merged from NATIVE_PTHREADS to HEAD 00699 00700 Revision 1.29.2.1 2003/02/10 14:07:54 ghillie 00701 - use pthread_mutex_* instead of CommonC++ Semaphore 00702 00703 Revision 1.29 2003/01/04 16:08:22 ghillie 00704 - log improvements: log_level, timestamp 00705 - added methods debugMessage(), errorMessage(), removed get*Stream() 00706 - added some additional debug output for connection setup / finish 00707 00708 Revision 1.28 2002/12/16 13:13:47 ghillie 00709 - added getCauseB3 to return B3 cause 00710 00711 Revision 1.27 2002/12/13 11:46:59 ghillie 00712 - added attribute our_call to differ outgoing and incoming calls 00713 00714 Revision 1.26 2002/12/11 13:39:05 ghillie 00715 - added support for PHYSICAL_ONLY disconnect in disconnectCall() 00716 00717 Revision 1.25 2002/12/10 15:06:15 ghillie 00718 - new methods get*Stream() for use in capisuitemodule 00719 00720 Revision 1.24 2002/12/09 15:42:24 ghillie 00721 - save debug and error stream in own attributes 00722 00723 Revision 1.23 2002/12/06 15:25:47 ghillie 00724 - new return value for getState(): WAITING 00725 00726 Revision 1.22 2002/12/06 13:07:36 ghillie 00727 - update docs because application is now responsible to delete 00728 Connection object 00729 - new methods getCause() and getState() 00730 00731 Revision 1.21 2002/12/05 15:05:12 ghillie 00732 - moved constructor for incoming calls to "private:" 00733 00734 Revision 1.20 2002/12/02 12:31:36 ghillie 00735 renamed Connection::SPEECH to Connection::VOICE 00736 00737 Revision 1.19 2002/11/29 10:25:01 ghillie 00738 - updated comments, use doxygen format now 00739 00740 Revision 1.18 2002/11/27 16:03:20 ghillie 00741 updated comments for doxygen 00742 00743 Revision 1.17 2002/11/25 11:51:54 ghillie 00744 - removed the unhandy CIP parameters from the interface to the application layer, use service type instead 00745 - rejectWaiting() tests against cause!=0 now 00746 - removed isUp() method 00747 00748 Revision 1.16 2002/11/22 15:13:44 ghillie 00749 - new attribute keepPhysicalConnection which prevents disconnect_b3_ind() from sending disconnect_req() 00750 - moved the ugly B*configuration, B*protocol settings from some methods to private method buildBconfiguration 00751 - new methods changeProtocol(), select_b_protocol_conf(), clearDTMF() 00752 - disconnect_b3_ind sets ncci_state to N0 before calling the callbacks 00753 - added parameter disconnect_mode to disconnectCall() 00754 - getDTMF() does non-destructive read now 00755 00756 Revision 1.15 2002/11/21 15:30:28 ghillie 00757 - added new method Connection::acceptWaiting() - sends ALERT_REQ 00758 - updated description of Connection::connectWaiting() 00759 00760 Revision 1.14 2002/11/19 15:57:19 ghillie 00761 - Added missing throw() declarations 00762 - phew. Added error handling. All exceptions are caught now. 00763 00764 Revision 1.13 2002/11/18 14:24:09 ghillie 00765 - moved global severity_t to CapiError::severity_t 00766 - added throw() declarations 00767 00768 Revision 1.12 2002/11/18 12:24:33 ghillie 00769 - changed disconnectCall() so that it doesn't throw exceptions any more, 00770 so that we can call it in any state 00771 00772 Revision 1.11 2002/11/17 14:40:55 ghillie 00773 added isUp() 00774 00775 Revision 1.10 2002/11/15 15:25:53 ghillie 00776 added ALERT_REQ so we don't loose a call when we wait before connection establishment 00777 00778 Revision 1.9 2002/11/15 13:49:10 ghillie 00779 fix: callmodule wasn't aborted when call was only connected/disconnected physically 00780 00781 Revision 1.8 2002/11/14 17:05:19 ghillie 00782 major structural changes - much is easier, nicer and better prepared for the future now: 00783 - added DisconnectLogical handler to CallInterface 00784 - DTMF handling moved from CallControl to Connection 00785 - new call module ConnectModule for establishing connection 00786 - python script reduced from 2 functions to one (callWaiting, callConnected 00787 merged to callIncoming) 00788 - call modules implement the CallInterface now, not CallControl any more 00789 => this freed CallControl from nearly all communication stuff 00790 00791 Revision 1.7 2002/11/13 08:34:54 ghillie 00792 moved history to the bottom 00793 00794 Revision 1.6 2002/11/10 17:05:18 ghillie 00795 changed to support multiple buffers -> deadlock in stop_file_transmission!! 00796 00797 Revision 1.5 2002/11/08 07:57:07 ghillie 00798 added functions to initiate a call 00799 corrected FACILITY calls to use PLCI instead of NCCI in DTMF processing as told by Mr. Ortmann on comp.dcom.isdn.capi 00800 00801 Revision 1.4 2002/10/31 12:40:06 ghillie 00802 added DTMF support 00803 small fixes like making some unnecessary global variables local, removed some unnecessary else cases 00804 00805 Revision 1.3 2002/10/30 14:29:25 ghillie 00806 added getCIPvalue 00807 00808 Revision 1.2 2002/10/29 14:27:42 ghillie 00809 added stop_file_*, added semaphores 00810 00811 Revision 1.1 2002/10/25 13:29:38 ghillie 00812 grouped files into subdirectories 00813 00814 Revision 1.10 2002/10/10 12:45:40 gernot 00815 added AudioReceive module, some small details changed 00816 00817 Revision 1.9 2002/10/09 11:18:59 gernot 00818 cosmetic changes (again...) and changed info function of CAPI class 00819 00820 Revision 1.8 2002/10/04 15:48:03 gernot 00821 structure changes completed & compiles now! 00822 00823 Revision 1.7 2002/10/04 13:27:15 gernot 00824 some restructuring to get it to a working state ;-) 00825 00826 does not do anything useful yet nor does it even compile... 00827 00828 Revision 1.6 2002/10/01 09:02:04 gernot 00829 changes for compilation with gcc3.2 00830 00831 Revision 1.5 2002/09/22 14:22:53 gernot 00832 some cosmetic comment improvements ;-) 00833 00834 Revision 1.4 2002/09/19 12:08:19 gernot 00835 added magic CVS strings 00836 00837 * Sun Sep 15 2002 - gernot@hillier.de 00838 - put under CVS, cvs changelog follows above 00839 00840 * Sun May 20 2002 - gernot@hillier.de 00841 - first version 00842 00843 */