1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef _COMMUNI_HXX 29*cdf0e10cSrcweir #define _COMMUNI_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <svl/svarray.hxx> 32*cdf0e10cSrcweir #include <vos/thread.hxx> 33*cdf0e10cSrcweir #include <vos/mutex.hxx> 34*cdf0e10cSrcweir #include <vcl/timer.hxx> 35*cdf0e10cSrcweir #include <automation/simplecm.hxx> 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir class SvStream; 38*cdf0e10cSrcweir class SvMemoryStream; 39*cdf0e10cSrcweir //class Application; 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir class CommunicationManagerServerAcceptThread; 42*cdf0e10cSrcweir SV_DECL_PTRARR_SORT( CommunicationLinkList, CommunicationLink*, 1, 10 ) 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir class MultiCommunicationManager : public CommunicationManager 45*cdf0e10cSrcweir { 46*cdf0e10cSrcweir public: 47*cdf0e10cSrcweir MultiCommunicationManager( sal_Bool bUseMultiChannel = sal_False ); 48*cdf0e10cSrcweir virtual ~MultiCommunicationManager(); 49*cdf0e10cSrcweir virtual sal_Bool StopCommunication(); // H�lt alle CommunicationLinks an 50*cdf0e10cSrcweir virtual sal_Bool IsLinkValid( CommunicationLink* pCL ); 51*cdf0e10cSrcweir virtual sal_uInt16 GetCommunicationLinkCount(); 52*cdf0e10cSrcweir virtual CommunicationLinkRef GetCommunicationLink( sal_uInt16 nNr ); 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir void DoQuickShutdown( sal_Bool bQuickShutdown = sal_True) { bGracefullShutdown = !bQuickShutdown; } 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir protected: 57*cdf0e10cSrcweir virtual void CallConnectionOpened( CommunicationLink* pCL ); 58*cdf0e10cSrcweir virtual void CallConnectionClosed( CommunicationLink* pCL ); 59*cdf0e10cSrcweir CommunicationLinkList *ActiveLinks; 60*cdf0e10cSrcweir CommunicationLinkList *InactiveLinks; /// Hier sind die CommunicationLinks drin, die sich noch nicht selbst abgemeldet haben. 61*cdf0e10cSrcweir /// allerdings schon ein StopCommunication gekriegt haben, bzw ein ConnectionTerminated 62*cdf0e10cSrcweir virtual void DestroyingLink( CommunicationLink *pCL ); // Link tr�gt sich im Destruktor aus 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir sal_Bool bGracefullShutdown; 65*cdf0e10cSrcweir }; 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir class CommunicationManagerServer : public MultiCommunicationManager 68*cdf0e10cSrcweir { 69*cdf0e10cSrcweir public: 70*cdf0e10cSrcweir CommunicationManagerServer( sal_Bool bUseMultiChannel = sal_False ):MultiCommunicationManager( bUseMultiChannel ){;} 71*cdf0e10cSrcweir }; 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir class CommunicationManagerClient : public MultiCommunicationManager, public ICommunicationManagerClient 74*cdf0e10cSrcweir { 75*cdf0e10cSrcweir public: 76*cdf0e10cSrcweir CommunicationManagerClient( sal_Bool bUseMultiChannel = sal_False ); 77*cdf0e10cSrcweir }; 78*cdf0e10cSrcweir 79*cdf0e10cSrcweir class CommunicationLinkViaSocket : public SimpleCommunicationLinkViaSocket, public vos::OThread 80*cdf0e10cSrcweir { 81*cdf0e10cSrcweir public: 82*cdf0e10cSrcweir CommunicationLinkViaSocket( CommunicationManager *pMan, vos::OStreamSocket *pSocket ); 83*cdf0e10cSrcweir virtual ~CommunicationLinkViaSocket(); 84*cdf0e10cSrcweir 85*cdf0e10cSrcweir virtual sal_Bool IsCommunicationError(); 86*cdf0e10cSrcweir virtual sal_Bool DoTransferDataStream( SvStream *pDataStream, CMProtocol nProtocol = CM_PROTOCOL_OLDSTYLE ); 87*cdf0e10cSrcweir 88*cdf0e10cSrcweir // Diese sind Virtuelle Links!!!! 89*cdf0e10cSrcweir virtual long ConnectionClosed( void* = NULL ); 90*cdf0e10cSrcweir virtual long DataReceived( void* = NULL ); 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir virtual sal_Bool StopCommunication(); 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir void SetPutDataReceivedHdl( Link lPutDataReceived ){ mlPutDataReceived = lPutDataReceived; } 95*cdf0e10cSrcweir Link GetDataReceivedLink () {Link aLink = LINK( this, CommunicationLinkViaSocket, DataReceived ); return aLink;} 96*cdf0e10cSrcweir DECL_LINK( PutDataReceivedHdl, CommunicationLinkViaSocket* ); 97*cdf0e10cSrcweir 98*cdf0e10cSrcweir protected: 99*cdf0e10cSrcweir virtual void SAL_CALL run(); 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir virtual sal_Bool ShutdownCommunication(); 102*cdf0e10cSrcweir sal_uLong nConnectionClosedEventId; 103*cdf0e10cSrcweir sal_uLong nDataReceivedEventId; 104*cdf0e10cSrcweir vos::OMutex aMConnectionClosed; // Notwendig, da Event verarbeitet werden kann bevor Variable gesetzt ist 105*cdf0e10cSrcweir vos::OMutex aMDataReceived; // Notwendig, da Event verarbeitet werden kann bevor Variable gesetzt ist 106*cdf0e10cSrcweir virtual void WaitForShutdown(); 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir DECL_LINK( ShutdownLink, void* ); 109*cdf0e10cSrcweir Timer aShutdownTimer; 110*cdf0e10cSrcweir sal_Bool bShutdownStarted; 111*cdf0e10cSrcweir sal_Bool bDestroying; 112*cdf0e10cSrcweir Link mlPutDataReceived; 113*cdf0e10cSrcweir }; 114*cdf0e10cSrcweir 115*cdf0e10cSrcweir class CommunicationManagerServerViaSocket : public CommunicationManagerServer 116*cdf0e10cSrcweir { 117*cdf0e10cSrcweir friend class CommunicationManagerServerAcceptThread; 118*cdf0e10cSrcweir public: 119*cdf0e10cSrcweir using CommunicationManager::StartCommunication; 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir CommunicationManagerServerViaSocket( sal_uLong nPort, sal_uInt16 nMaxCon, sal_Bool bUseMultiChannel = sal_False ); 122*cdf0e10cSrcweir virtual ~CommunicationManagerServerViaSocket(); 123*cdf0e10cSrcweir 124*cdf0e10cSrcweir virtual sal_Bool StartCommunication(); 125*cdf0e10cSrcweir virtual sal_Bool StopCommunication(); 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir protected: 128*cdf0e10cSrcweir sal_uLong nPortToListen; 129*cdf0e10cSrcweir sal_uInt16 nMaxConnections; 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir private: 132*cdf0e10cSrcweir CommunicationManagerServerAcceptThread *pAcceptThread; 133*cdf0e10cSrcweir void AddConnection( CommunicationLink *pNewConnection ); 134*cdf0e10cSrcweir }; 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir class CommunicationManagerServerAcceptThread: public vos::OThread 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir public: 139*cdf0e10cSrcweir CommunicationManagerServerAcceptThread( CommunicationManagerServerViaSocket* pServer, sal_uLong nPort, sal_uInt16 nMaxCon = CM_UNLIMITED_CONNECTIONS ); 140*cdf0e10cSrcweir virtual ~CommunicationManagerServerAcceptThread(); 141*cdf0e10cSrcweir CommunicationLinkRef GetNewConnection(){ CommunicationLinkRef xTemp = xmNewConnection; xmNewConnection.Clear(); return xTemp; } 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir protected: 144*cdf0e10cSrcweir virtual void SAL_CALL run(); 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir private: 147*cdf0e10cSrcweir CommunicationManagerServerViaSocket* pMyServer; 148*cdf0e10cSrcweir vos::OAcceptorSocket *pAcceptorSocket; 149*cdf0e10cSrcweir sal_uLong nPortToListen; 150*cdf0e10cSrcweir sal_uInt16 nMaxConnections; 151*cdf0e10cSrcweir sal_uLong nAddConnectionEventId; 152*cdf0e10cSrcweir vos::OMutex aMAddConnection; // Notwendig, da Event verarbeitet werden kann bevor Variable gesetzt ist 153*cdf0e10cSrcweir void CallInfoMsg( InfoString aMsg ){ pMyServer->CallInfoMsg( aMsg ); } 154*cdf0e10cSrcweir CM_InfoType GetInfoType(){ return pMyServer->GetInfoType(); } 155*cdf0e10cSrcweir 156*cdf0e10cSrcweir // Diese beiden werden zum Transport der Connection vom Thread zum Mainthread verwendet. 157*cdf0e10cSrcweir CommunicationLinkRef xmNewConnection; 158*cdf0e10cSrcweir DECL_LINK( AddConnection, void* ); 159*cdf0e10cSrcweir }; 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir class CommunicationManagerClientViaSocket : public CommunicationManagerClient, CommonSocketFunctions 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir public: 164*cdf0e10cSrcweir using CommunicationManager::StartCommunication; 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir CommunicationManagerClientViaSocket( ByteString aHost, sal_uLong nPort, sal_Bool bUseMultiChannel = sal_False ); 167*cdf0e10cSrcweir CommunicationManagerClientViaSocket( sal_Bool bUseMultiChannel = sal_False ); 168*cdf0e10cSrcweir virtual ~CommunicationManagerClientViaSocket(); 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir virtual sal_Bool StartCommunication(){ return StartCommunication( aHostToTalk, nPortToTalk );} 171*cdf0e10cSrcweir virtual sal_Bool StartCommunication( ByteString aHost, sal_uLong nPort ){ return DoStartCommunication( this, (ICommunicationManagerClient*) this, aHost, nPort );} 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir private: 174*cdf0e10cSrcweir ByteString aHostToTalk; 175*cdf0e10cSrcweir sal_uLong nPortToTalk; 176*cdf0e10cSrcweir protected: 177*cdf0e10cSrcweir virtual CommunicationLink *CreateCommunicationLink( CommunicationManager *pCM, vos::OConnectorSocket *pCS ){ return new CommunicationLinkViaSocket( pCM, pCS ); } 178*cdf0e10cSrcweir }; 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir #endif 181