1*3398c5b8SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*3398c5b8SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*3398c5b8SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*3398c5b8SAndrew Rist * distributed with this work for additional information 6*3398c5b8SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*3398c5b8SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*3398c5b8SAndrew Rist * "License"); you may not use this file except in compliance 9*3398c5b8SAndrew Rist * with the License. You may obtain a copy of the License at 10*3398c5b8SAndrew Rist * 11*3398c5b8SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*3398c5b8SAndrew Rist * 13*3398c5b8SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*3398c5b8SAndrew Rist * software distributed under the License is distributed on an 15*3398c5b8SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*3398c5b8SAndrew Rist * KIND, either express or implied. See the License for the 17*3398c5b8SAndrew Rist * specific language governing permissions and limitations 18*3398c5b8SAndrew Rist * under the License. 19*3398c5b8SAndrew Rist * 20*3398c5b8SAndrew Rist *************************************************************/ 21*3398c5b8SAndrew Rist 22*3398c5b8SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef _COMMUNI_HXX 25cdf0e10cSrcweir #define _COMMUNI_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <svl/svarray.hxx> 28cdf0e10cSrcweir #include <vos/thread.hxx> 29cdf0e10cSrcweir #include <vos/mutex.hxx> 30cdf0e10cSrcweir #include <vcl/timer.hxx> 31cdf0e10cSrcweir #include <automation/simplecm.hxx> 32cdf0e10cSrcweir 33cdf0e10cSrcweir class SvStream; 34cdf0e10cSrcweir class SvMemoryStream; 35cdf0e10cSrcweir //class Application; 36cdf0e10cSrcweir 37cdf0e10cSrcweir class CommunicationManagerServerAcceptThread; 38cdf0e10cSrcweir SV_DECL_PTRARR_SORT( CommunicationLinkList, CommunicationLink*, 1, 10 ) 39cdf0e10cSrcweir 40cdf0e10cSrcweir class MultiCommunicationManager : public CommunicationManager 41cdf0e10cSrcweir { 42cdf0e10cSrcweir public: 43cdf0e10cSrcweir MultiCommunicationManager( sal_Bool bUseMultiChannel = sal_False ); 44cdf0e10cSrcweir virtual ~MultiCommunicationManager(); 45cdf0e10cSrcweir virtual sal_Bool StopCommunication(); // H�lt alle CommunicationLinks an 46cdf0e10cSrcweir virtual sal_Bool IsLinkValid( CommunicationLink* pCL ); 47cdf0e10cSrcweir virtual sal_uInt16 GetCommunicationLinkCount(); 48cdf0e10cSrcweir virtual CommunicationLinkRef GetCommunicationLink( sal_uInt16 nNr ); 49cdf0e10cSrcweir DoQuickShutdown(sal_Bool bQuickShutdown=sal_True)50cdf0e10cSrcweir void DoQuickShutdown( sal_Bool bQuickShutdown = sal_True) { bGracefullShutdown = !bQuickShutdown; } 51cdf0e10cSrcweir 52cdf0e10cSrcweir protected: 53cdf0e10cSrcweir virtual void CallConnectionOpened( CommunicationLink* pCL ); 54cdf0e10cSrcweir virtual void CallConnectionClosed( CommunicationLink* pCL ); 55cdf0e10cSrcweir CommunicationLinkList *ActiveLinks; 56cdf0e10cSrcweir CommunicationLinkList *InactiveLinks; /// Hier sind die CommunicationLinks drin, die sich noch nicht selbst abgemeldet haben. 57cdf0e10cSrcweir /// allerdings schon ein StopCommunication gekriegt haben, bzw ein ConnectionTerminated 58cdf0e10cSrcweir virtual void DestroyingLink( CommunicationLink *pCL ); // Link tr�gt sich im Destruktor aus 59cdf0e10cSrcweir 60cdf0e10cSrcweir sal_Bool bGracefullShutdown; 61cdf0e10cSrcweir }; 62cdf0e10cSrcweir 63cdf0e10cSrcweir class CommunicationManagerServer : public MultiCommunicationManager 64cdf0e10cSrcweir { 65cdf0e10cSrcweir public: CommunicationManagerServer(sal_Bool bUseMultiChannel=sal_False)66cdf0e10cSrcweir CommunicationManagerServer( sal_Bool bUseMultiChannel = sal_False ):MultiCommunicationManager( bUseMultiChannel ){;} 67cdf0e10cSrcweir }; 68cdf0e10cSrcweir 69cdf0e10cSrcweir class CommunicationManagerClient : public MultiCommunicationManager, public ICommunicationManagerClient 70cdf0e10cSrcweir { 71cdf0e10cSrcweir public: 72cdf0e10cSrcweir CommunicationManagerClient( sal_Bool bUseMultiChannel = sal_False ); 73cdf0e10cSrcweir }; 74cdf0e10cSrcweir 75cdf0e10cSrcweir class CommunicationLinkViaSocket : public SimpleCommunicationLinkViaSocket, public vos::OThread 76cdf0e10cSrcweir { 77cdf0e10cSrcweir public: 78cdf0e10cSrcweir CommunicationLinkViaSocket( CommunicationManager *pMan, vos::OStreamSocket *pSocket ); 79cdf0e10cSrcweir virtual ~CommunicationLinkViaSocket(); 80cdf0e10cSrcweir 81cdf0e10cSrcweir virtual sal_Bool IsCommunicationError(); 82cdf0e10cSrcweir virtual sal_Bool DoTransferDataStream( SvStream *pDataStream, CMProtocol nProtocol = CM_PROTOCOL_OLDSTYLE ); 83cdf0e10cSrcweir 84cdf0e10cSrcweir // Diese sind Virtuelle Links!!!! 85cdf0e10cSrcweir virtual long ConnectionClosed( void* = NULL ); 86cdf0e10cSrcweir virtual long DataReceived( void* = NULL ); 87cdf0e10cSrcweir 88cdf0e10cSrcweir virtual sal_Bool StopCommunication(); 89cdf0e10cSrcweir SetPutDataReceivedHdl(Link lPutDataReceived)90cdf0e10cSrcweir void SetPutDataReceivedHdl( Link lPutDataReceived ){ mlPutDataReceived = lPutDataReceived; } GetDataReceivedLink()91cdf0e10cSrcweir Link GetDataReceivedLink () {Link aLink = LINK( this, CommunicationLinkViaSocket, DataReceived ); return aLink;} 92cdf0e10cSrcweir DECL_LINK( PutDataReceivedHdl, CommunicationLinkViaSocket* ); 93cdf0e10cSrcweir 94cdf0e10cSrcweir protected: 95cdf0e10cSrcweir virtual void SAL_CALL run(); 96cdf0e10cSrcweir 97cdf0e10cSrcweir virtual sal_Bool ShutdownCommunication(); 98cdf0e10cSrcweir sal_uLong nConnectionClosedEventId; 99cdf0e10cSrcweir sal_uLong nDataReceivedEventId; 100cdf0e10cSrcweir vos::OMutex aMConnectionClosed; // Notwendig, da Event verarbeitet werden kann bevor Variable gesetzt ist 101cdf0e10cSrcweir vos::OMutex aMDataReceived; // Notwendig, da Event verarbeitet werden kann bevor Variable gesetzt ist 102cdf0e10cSrcweir virtual void WaitForShutdown(); 103cdf0e10cSrcweir 104cdf0e10cSrcweir DECL_LINK( ShutdownLink, void* ); 105cdf0e10cSrcweir Timer aShutdownTimer; 106cdf0e10cSrcweir sal_Bool bShutdownStarted; 107cdf0e10cSrcweir sal_Bool bDestroying; 108cdf0e10cSrcweir Link mlPutDataReceived; 109cdf0e10cSrcweir }; 110cdf0e10cSrcweir 111cdf0e10cSrcweir class CommunicationManagerServerViaSocket : public CommunicationManagerServer 112cdf0e10cSrcweir { 113cdf0e10cSrcweir friend class CommunicationManagerServerAcceptThread; 114cdf0e10cSrcweir public: 115cdf0e10cSrcweir using CommunicationManager::StartCommunication; 116cdf0e10cSrcweir 117cdf0e10cSrcweir CommunicationManagerServerViaSocket( sal_uLong nPort, sal_uInt16 nMaxCon, sal_Bool bUseMultiChannel = sal_False ); 118cdf0e10cSrcweir virtual ~CommunicationManagerServerViaSocket(); 119cdf0e10cSrcweir 120cdf0e10cSrcweir virtual sal_Bool StartCommunication(); 121cdf0e10cSrcweir virtual sal_Bool StopCommunication(); 122cdf0e10cSrcweir 123cdf0e10cSrcweir protected: 124cdf0e10cSrcweir sal_uLong nPortToListen; 125cdf0e10cSrcweir sal_uInt16 nMaxConnections; 126cdf0e10cSrcweir 127cdf0e10cSrcweir private: 128cdf0e10cSrcweir CommunicationManagerServerAcceptThread *pAcceptThread; 129cdf0e10cSrcweir void AddConnection( CommunicationLink *pNewConnection ); 130cdf0e10cSrcweir }; 131cdf0e10cSrcweir 132cdf0e10cSrcweir class CommunicationManagerServerAcceptThread: public vos::OThread 133cdf0e10cSrcweir { 134cdf0e10cSrcweir public: 135cdf0e10cSrcweir CommunicationManagerServerAcceptThread( CommunicationManagerServerViaSocket* pServer, sal_uLong nPort, sal_uInt16 nMaxCon = CM_UNLIMITED_CONNECTIONS ); 136cdf0e10cSrcweir virtual ~CommunicationManagerServerAcceptThread(); GetNewConnection()137cdf0e10cSrcweir CommunicationLinkRef GetNewConnection(){ CommunicationLinkRef xTemp = xmNewConnection; xmNewConnection.Clear(); return xTemp; } 138cdf0e10cSrcweir 139cdf0e10cSrcweir protected: 140cdf0e10cSrcweir virtual void SAL_CALL run(); 141cdf0e10cSrcweir 142cdf0e10cSrcweir private: 143cdf0e10cSrcweir CommunicationManagerServerViaSocket* pMyServer; 144cdf0e10cSrcweir vos::OAcceptorSocket *pAcceptorSocket; 145cdf0e10cSrcweir sal_uLong nPortToListen; 146cdf0e10cSrcweir sal_uInt16 nMaxConnections; 147cdf0e10cSrcweir sal_uLong nAddConnectionEventId; 148cdf0e10cSrcweir vos::OMutex aMAddConnection; // Notwendig, da Event verarbeitet werden kann bevor Variable gesetzt ist CallInfoMsg(InfoString aMsg)149cdf0e10cSrcweir void CallInfoMsg( InfoString aMsg ){ pMyServer->CallInfoMsg( aMsg ); } GetInfoType()150cdf0e10cSrcweir CM_InfoType GetInfoType(){ return pMyServer->GetInfoType(); } 151cdf0e10cSrcweir 152cdf0e10cSrcweir // Diese beiden werden zum Transport der Connection vom Thread zum Mainthread verwendet. 153cdf0e10cSrcweir CommunicationLinkRef xmNewConnection; 154cdf0e10cSrcweir DECL_LINK( AddConnection, void* ); 155cdf0e10cSrcweir }; 156cdf0e10cSrcweir 157cdf0e10cSrcweir class CommunicationManagerClientViaSocket : public CommunicationManagerClient, CommonSocketFunctions 158cdf0e10cSrcweir { 159cdf0e10cSrcweir public: 160cdf0e10cSrcweir using CommunicationManager::StartCommunication; 161cdf0e10cSrcweir 162cdf0e10cSrcweir CommunicationManagerClientViaSocket( ByteString aHost, sal_uLong nPort, sal_Bool bUseMultiChannel = sal_False ); 163cdf0e10cSrcweir CommunicationManagerClientViaSocket( sal_Bool bUseMultiChannel = sal_False ); 164cdf0e10cSrcweir virtual ~CommunicationManagerClientViaSocket(); 165cdf0e10cSrcweir StartCommunication()166cdf0e10cSrcweir virtual sal_Bool StartCommunication(){ return StartCommunication( aHostToTalk, nPortToTalk );} StartCommunication(ByteString aHost,sal_uLong nPort)167cdf0e10cSrcweir virtual sal_Bool StartCommunication( ByteString aHost, sal_uLong nPort ){ return DoStartCommunication( this, (ICommunicationManagerClient*) this, aHost, nPort );} 168cdf0e10cSrcweir 169cdf0e10cSrcweir private: 170cdf0e10cSrcweir ByteString aHostToTalk; 171cdf0e10cSrcweir sal_uLong nPortToTalk; 172cdf0e10cSrcweir protected: CreateCommunicationLink(CommunicationManager * pCM,vos::OConnectorSocket * pCS)173cdf0e10cSrcweir virtual CommunicationLink *CreateCommunicationLink( CommunicationManager *pCM, vos::OConnectorSocket *pCS ){ return new CommunicationLinkViaSocket( pCM, pCS ); } 174cdf0e10cSrcweir }; 175cdf0e10cSrcweir 176cdf0e10cSrcweir #endif 177