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