2010-10-12 15:57:08 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2005-06-21 18:07:46 +00:00
|
|
|
/*************************************************************************
|
|
|
|
*
|
2008-04-11 09:09:51 +00:00
|
|
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
2005-06-21 18:07:46 +00:00
|
|
|
*
|
2010-02-12 15:01:35 +01:00
|
|
|
* Copyright 2000, 2010 Oracle and/or its affiliates.
|
2005-06-21 18:07:46 +00:00
|
|
|
*
|
2008-04-11 09:09:51 +00:00
|
|
|
* OpenOffice.org - a multi-platform office productivity suite
|
2005-06-21 18:07:46 +00:00
|
|
|
*
|
2008-04-11 09:09:51 +00:00
|
|
|
* This file is part of OpenOffice.org.
|
2005-06-21 18:07:46 +00:00
|
|
|
*
|
2008-04-11 09:09:51 +00:00
|
|
|
* OpenOffice.org is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU Lesser General Public License version 3
|
|
|
|
* only, as published by the Free Software Foundation.
|
2005-06-21 18:07:46 +00:00
|
|
|
*
|
2008-04-11 09:09:51 +00:00
|
|
|
* OpenOffice.org is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU Lesser General Public License version 3 for more details
|
|
|
|
* (a copy is included in the LICENSE file that accompanied this code).
|
2005-06-21 18:07:46 +00:00
|
|
|
*
|
2008-04-11 09:09:51 +00:00
|
|
|
* You should have received a copy of the GNU Lesser General Public License
|
|
|
|
* version 3 along with OpenOffice.org. If not, see
|
|
|
|
* <http://www.openoffice.org/license.html>
|
|
|
|
* for a copy of the LGPLv3 License.
|
2005-06-21 18:07:46 +00:00
|
|
|
*
|
|
|
|
************************************************************************/
|
|
|
|
|
2006-09-16 23:38:29 +00:00
|
|
|
// MARKER(update_precomp.py): autogen include statement, do not remove
|
|
|
|
#include "precompiled_automation.hxx"
|
|
|
|
|
2005-06-21 18:07:46 +00:00
|
|
|
#include "comm_bas.hxx"
|
|
|
|
#include <tools/errcode.hxx>
|
|
|
|
#include <basic/sbxobj.hxx>
|
|
|
|
#include <basic/sbx.hxx>
|
|
|
|
#include <basic/sbxvar.hxx>
|
|
|
|
#include <vcl/svapp.hxx>
|
2007-06-27 20:01:57 +00:00
|
|
|
#include <automation/communi.hxx>
|
2005-06-21 18:07:46 +00:00
|
|
|
#include <basic/ttstrhlp.hxx>
|
|
|
|
|
2011-08-22 11:39:37 +02:00
|
|
|
// The CommunicationManager consists of the following elements:
|
2005-06-21 18:07:46 +00:00
|
|
|
// 1) Properties:
|
2011-08-22 11:39:37 +02:00
|
|
|
// none
|
|
|
|
// 2) Methods:
|
2005-06-21 18:07:46 +00:00
|
|
|
// CommunicationLink StartCommunication( Host, Port )
|
2011-08-22 11:39:37 +02:00
|
|
|
// StopAllCommunication
|
|
|
|
// sal_Bool IsCommunicationRunning
|
|
|
|
// String GetMyName
|
|
|
|
// sal_Bool IsLinkValid( CommunicationLink )
|
|
|
|
// SetCommunicationEventHandler( String )
|
2005-06-21 18:07:46 +00:00
|
|
|
|
2011-08-22 11:39:37 +02:00
|
|
|
// The CommunicationLink consists of the following elements:
|
2005-06-21 18:07:46 +00:00
|
|
|
// 1) Properties:
|
2011-08-22 11:39:37 +02:00
|
|
|
// none
|
|
|
|
// 2) Methods:
|
|
|
|
// StopCommunication
|
|
|
|
// String GetMyName
|
|
|
|
// String GetHostName
|
|
|
|
// Send( String )
|
|
|
|
// String GetString
|
2005-06-21 18:07:46 +00:00
|
|
|
|
|
|
|
|
2011-08-22 11:39:37 +02:00
|
|
|
// This implementation is an example for a table-controlled
|
|
|
|
// version that can contain a lot of elements. The elements are
|
|
|
|
// taken from the table to the object when needed.
|
2005-06-21 18:07:46 +00:00
|
|
|
|
2011-08-22 11:39:37 +02:00
|
|
|
// The nArgs-field of a table entry is encrypted as follows:
|
2005-06-21 18:07:46 +00:00
|
|
|
|
2011-08-22 11:39:37 +02:00
|
|
|
#define _ARGSMASK 0x00FF // up to 255 arguments
|
|
|
|
#define _RWMASK 0x0F00 // mask for R/W-Bits
|
|
|
|
#define _TYPEMASK 0xF000 // mask for the entry type
|
2005-06-21 18:07:46 +00:00
|
|
|
|
2011-08-22 11:39:37 +02:00
|
|
|
#define _READ 0x0100 // can be read
|
|
|
|
#define _BWRITE 0x0200 // can be used as Lvalue
|
|
|
|
#define _LVALUE _BWRITE // can be used as Lvalue
|
|
|
|
#define _READWRITE 0x0300 // both
|
|
|
|
#define _OPT 0x0400 // TRUE: optional parameter
|
|
|
|
#define _METHOD 0x1000 // mask bit for a method
|
|
|
|
#define _PROPERTY 0x2000 // mask bit for a property
|
|
|
|
#define _COLL 0x4000 // mask bit for a collection
|
|
|
|
// combination of bits above:
|
|
|
|
#define _FUNCTION 0x1100 // mask for a function
|
|
|
|
#define _LFUNCTION 0x1300 // mask for a function, that works as Lvalue too
|
|
|
|
#define _ROPROP 0x2100 // mask Read Only-Property
|
|
|
|
#define _WOPROP 0x2200 // mask Write Only-Property
|
|
|
|
#define _RWPROP 0x2300 // mask Read/Write-Property
|
|
|
|
#define _COLLPROP 0x4100 // mask Read-Collection-Element
|
2005-06-21 18:07:46 +00:00
|
|
|
|
2011-08-22 11:39:37 +02:00
|
|
|
#define COLLNAME "Elements" // the collection's name, here wired hard
|
2005-06-21 18:07:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CommunicationWrapper::Methods CommunicationWrapper::aManagerMethods[] = {
|
2011-08-22 11:39:37 +02:00
|
|
|
|
2006-10-12 13:05:59 +00:00
|
|
|
{ "StartCommunication", SbxEMPTY, &CommunicationWrapper::MStartCommunication, 2 | _FUNCTION },
|
2011-08-22 11:39:37 +02:00
|
|
|
|
2006-10-12 13:05:59 +00:00
|
|
|
{ "Host", SbxSTRING, NULL, 0 },
|
|
|
|
{ "Port", SbxLONG, NULL, 0 },
|
2011-08-22 11:39:37 +02:00
|
|
|
|
2006-10-12 13:05:59 +00:00
|
|
|
{ "StopAllCommunication", SbxEMPTY, &CommunicationWrapper::MStopAllCommunication, 0 | _FUNCTION },
|
2011-08-22 11:39:37 +02:00
|
|
|
|
2006-10-12 13:05:59 +00:00
|
|
|
{ "IsCommunicationRunning", SbxBOOL, &CommunicationWrapper::MIsCommunicationRunning, 0 | _FUNCTION },
|
2011-08-22 11:39:37 +02:00
|
|
|
// as FQDN
|
2006-10-12 13:05:59 +00:00
|
|
|
{ "GetMyName", SbxSTRING, &CommunicationWrapper::MGetMyName, 0 | _FUNCTION },
|
2011-08-22 11:39:37 +02:00
|
|
|
|
2006-10-12 13:05:59 +00:00
|
|
|
{ "IsLinkValid", SbxBOOL, &CommunicationWrapper::MIsLinkValid, 1 | _FUNCTION },
|
2011-08-22 11:39:37 +02:00
|
|
|
|
2006-10-12 13:05:59 +00:00
|
|
|
{ "Link", SbxOBJECT, NULL, 0 },
|
2011-08-22 11:39:37 +02:00
|
|
|
|
2006-10-12 13:05:59 +00:00
|
|
|
{ "SetCommunicationEventHandler", SbxEMPTY, &CommunicationWrapper::MSetCommunicationEventHandler, 1 | _FUNCTION },
|
2011-08-22 11:39:37 +02:00
|
|
|
|
2006-10-12 13:05:59 +00:00
|
|
|
{ "FuncName", SbxSTRING, NULL, 0 },
|
2005-06-21 18:07:46 +00:00
|
|
|
|
2011-08-22 11:39:37 +02:00
|
|
|
{ NULL, SbxNULL, NULL, -1 }}; // end of the table
|
2005-06-21 18:07:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
CommunicationWrapper::Methods CommunicationWrapper::aLinkMethods[] = {
|
2011-08-22 11:39:37 +02:00
|
|
|
|
2006-10-12 13:05:59 +00:00
|
|
|
{ "StopCommunication", SbxEMPTY, &CommunicationWrapper::LStopCommunication, 0 | _FUNCTION },
|
2011-08-22 11:39:37 +02:00
|
|
|
|
2006-10-12 13:05:59 +00:00
|
|
|
{ "GetMyName", SbxSTRING, &CommunicationWrapper::LGetMyName, 0 | _FUNCTION },
|
2011-08-22 11:39:37 +02:00
|
|
|
|
2006-10-12 13:05:59 +00:00
|
|
|
{ "GetHostName", SbxSTRING, &CommunicationWrapper::LGetHostName, 0 | _FUNCTION },
|
2011-08-22 11:39:37 +02:00
|
|
|
|
2006-10-12 13:05:59 +00:00
|
|
|
{ "Send", SbxEMPTY, &CommunicationWrapper::LSend, 1 | _FUNCTION },
|
2011-08-22 11:39:37 +02:00
|
|
|
|
2006-10-12 13:05:59 +00:00
|
|
|
{ "SendString", SbxSTRING, NULL, 0 },
|
2011-08-22 11:39:37 +02:00
|
|
|
|
2006-10-12 13:05:59 +00:00
|
|
|
{ "GetString", SbxSTRING, &CommunicationWrapper::LGetString, 0 | _FUNCTION },
|
2005-06-21 18:07:46 +00:00
|
|
|
|
2011-08-22 11:39:37 +02:00
|
|
|
{ NULL, SbxNULL, NULL, -1 }}; // end of the table
|
2005-06-21 18:07:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-22 11:39:37 +02:00
|
|
|
// constructor for the manager
|
2005-06-21 18:07:46 +00:00
|
|
|
CommunicationWrapper::CommunicationWrapper( const String& rClass ) : SbxObject( rClass )
|
2006-06-19 23:26:18 +00:00
|
|
|
, m_pLink( NULL )
|
2011-01-12 11:34:50 +01:00
|
|
|
, m_bIsManager( sal_True )
|
|
|
|
, m_bCatchOpen( sal_False )
|
2006-06-19 23:26:18 +00:00
|
|
|
, m_pNewLink( NULL )
|
2005-06-21 18:07:46 +00:00
|
|
|
{
|
2006-06-19 23:26:18 +00:00
|
|
|
m_pMethods = &aManagerMethods[0];
|
|
|
|
m_pManager = new CommunicationManagerClientViaSocket;
|
|
|
|
m_pManager->SetConnectionOpenedHdl( LINK( this, CommunicationWrapper, Open ) );
|
|
|
|
m_pManager->SetConnectionClosedHdl( LINK( this, CommunicationWrapper, Close ) );
|
|
|
|
m_pManager->SetDataReceivedHdl( LINK( this, CommunicationWrapper, Data ) );
|
2005-06-21 18:07:46 +00:00
|
|
|
}
|
|
|
|
|
2011-08-22 11:39:37 +02:00
|
|
|
// constructor for the link
|
2005-06-21 18:07:46 +00:00
|
|
|
CommunicationWrapper::CommunicationWrapper( CommunicationLink *pThisLink ) : SbxObject( CUniString("Link") )
|
2006-06-19 23:26:18 +00:00
|
|
|
, m_pLink( pThisLink )
|
2011-01-12 11:34:50 +01:00
|
|
|
, m_bIsManager( sal_False )
|
|
|
|
, m_bCatchOpen( sal_False )
|
2006-06-19 23:26:18 +00:00
|
|
|
, m_pNewLink( NULL )
|
2005-06-21 18:07:46 +00:00
|
|
|
{
|
2006-06-19 23:26:18 +00:00
|
|
|
m_pMethods = &aLinkMethods[0];
|
|
|
|
m_pManager = (CommunicationManagerClientViaSocket*)pThisLink->GetCommunicationManager();
|
2005-06-21 18:07:46 +00:00
|
|
|
}
|
|
|
|
|
2011-08-22 11:39:37 +02:00
|
|
|
// deconstructor
|
2005-06-21 18:07:46 +00:00
|
|
|
CommunicationWrapper::~CommunicationWrapper()
|
|
|
|
{
|
2006-06-19 23:26:18 +00:00
|
|
|
if ( m_bIsManager )
|
|
|
|
delete m_pManager;
|
2005-06-21 18:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-08-22 11:39:37 +02:00
|
|
|
// Search for an element:
|
|
|
|
// Here it goes through the method table until an appropriate one
|
|
|
|
// has been found.
|
|
|
|
// If the method/property has not been found, get back only NULL
|
|
|
|
// without error code because that way a whole chain of objects
|
|
|
|
// can be asked for the method/property.
|
2005-06-21 18:07:46 +00:00
|
|
|
|
|
|
|
SbxVariable* CommunicationWrapper::Find( const String& rName, SbxClassType t )
|
|
|
|
{
|
2011-08-22 11:39:37 +02:00
|
|
|
// Does the element exist already?
|
2005-06-21 18:07:46 +00:00
|
|
|
SbxVariable* pRes = SbxObject::Find( rName, t );
|
|
|
|
if( !pRes && t != SbxCLASS_OBJECT )
|
|
|
|
{
|
2011-08-22 11:39:37 +02:00
|
|
|
// look for it if not
|
2006-06-19 23:26:18 +00:00
|
|
|
Methods* p = m_pMethods;
|
2005-06-21 18:07:46 +00:00
|
|
|
short nIndex = 0;
|
2011-01-12 11:34:50 +01:00
|
|
|
sal_Bool bFound = sal_False;
|
2005-06-21 18:07:46 +00:00
|
|
|
while( p->nArgs != -1 )
|
|
|
|
{
|
|
|
|
if( rName.CompareIgnoreCaseToAscii( p->pName ) == COMPARE_EQUAL )
|
|
|
|
{
|
2011-01-12 11:34:50 +01:00
|
|
|
bFound = sal_True; break;
|
2005-06-21 18:07:46 +00:00
|
|
|
}
|
|
|
|
nIndex += ( p->nArgs & _ARGSMASK ) + 1;
|
2006-06-19 23:26:18 +00:00
|
|
|
p = m_pMethods + nIndex;
|
2005-06-21 18:07:46 +00:00
|
|
|
}
|
|
|
|
if( bFound )
|
|
|
|
{
|
2011-08-22 11:39:37 +02:00
|
|
|
// isolate args-fields:
|
2005-06-21 18:07:46 +00:00
|
|
|
short nAccess = ( p->nArgs & _RWMASK ) >> 8;
|
|
|
|
short nType = ( p->nArgs & _TYPEMASK );
|
|
|
|
String aName( p->pName, RTL_TEXTENCODING_ASCII_US );
|
|
|
|
SbxClassType eCT = SbxCLASS_OBJECT;
|
|
|
|
if( nType & _PROPERTY )
|
|
|
|
eCT = SbxCLASS_PROPERTY;
|
|
|
|
else if( nType & _METHOD )
|
|
|
|
eCT = SbxCLASS_METHOD;
|
|
|
|
pRes = Make( aName, eCT, p->eType );
|
2011-08-22 11:39:37 +02:00
|
|
|
// We set the array-index + 1, because there are still
|
|
|
|
// other standard properties existing, which have to be activated.
|
2005-06-21 18:07:46 +00:00
|
|
|
pRes->SetUserData( nIndex + 1 );
|
|
|
|
pRes->SetFlags( nAccess );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return pRes;
|
|
|
|
}
|
|
|
|
|
2011-08-22 11:39:37 +02:00
|
|
|
// activation of an element or asking for an infoblock
|
2005-06-21 18:07:46 +00:00
|
|
|
|
|
|
|
void CommunicationWrapper::SFX_NOTIFY( SfxBroadcaster& rBC, const TypeId& rBCT,
|
|
|
|
const SfxHint& rHint, const TypeId& rHT )
|
|
|
|
{
|
|
|
|
const SbxHint* pHint = PTR_CAST(SbxHint,&rHint);
|
|
|
|
if( pHint )
|
|
|
|
{
|
|
|
|
SbxVariable* pVar = pHint->GetVar();
|
|
|
|
SbxArray* pPar = pVar->GetParameters();
|
2011-01-12 11:34:50 +01:00
|
|
|
sal_uInt16 nIndex = (sal_uInt16) pVar->GetUserData();
|
2011-08-22 11:39:37 +02:00
|
|
|
// no index: hand on!
|
2005-06-21 18:07:46 +00:00
|
|
|
if( nIndex )
|
|
|
|
{
|
2011-01-12 11:34:50 +01:00
|
|
|
sal_uLong t = pHint->GetId();
|
2005-06-21 18:07:46 +00:00
|
|
|
if( t == SBX_HINT_INFOWANTED )
|
|
|
|
pVar->SetInfo( GetInfo( (short) pVar->GetUserData() ) );
|
|
|
|
else
|
|
|
|
{
|
2011-01-12 11:34:50 +01:00
|
|
|
sal_Bool bWrite = sal_False;
|
2005-06-21 18:07:46 +00:00
|
|
|
if( t == SBX_HINT_DATACHANGED )
|
2011-01-12 11:34:50 +01:00
|
|
|
bWrite = sal_True;
|
2005-06-21 18:07:46 +00:00
|
|
|
if( t == SBX_HINT_DATAWANTED || bWrite )
|
|
|
|
{
|
2011-08-22 11:39:37 +02:00
|
|
|
// parameter test for methods:
|
2011-01-12 11:34:50 +01:00
|
|
|
sal_uInt16 nPar = m_pMethods[ --nIndex ].nArgs & 0x00FF;
|
2011-08-22 11:39:37 +02:00
|
|
|
// element 0 is the return value
|
2005-06-21 18:07:46 +00:00
|
|
|
if( ( !pPar && nPar )
|
|
|
|
|| ( pPar && pPar->Count() != nPar+1 ) )
|
|
|
|
SetError( SbxERR_WRONG_ARGS );
|
2011-08-22 11:39:37 +02:00
|
|
|
|
2005-06-21 18:07:46 +00:00
|
|
|
else
|
|
|
|
{
|
2006-06-19 23:26:18 +00:00
|
|
|
(this->*(m_pMethods[ nIndex ].pFunc))( pVar, pPar, bWrite );
|
2005-06-21 18:07:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
SbxObject::SFX_NOTIFY( rBC, rBCT, rHint, rHT );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-22 11:39:37 +02:00
|
|
|
// construction of the info-structure for single elements
|
2005-06-21 18:07:46 +00:00
|
|
|
|
|
|
|
SbxInfo* CommunicationWrapper::GetInfo( short nIdx )
|
|
|
|
{
|
2006-06-19 23:26:18 +00:00
|
|
|
Methods* p = &m_pMethods[ nIdx ];
|
2011-08-22 11:39:37 +02:00
|
|
|
// if there's a help-file some time:
|
|
|
|
// SbxInfo* pInfo = new SbxInfo( helpfilename, p->nHelpId );
|
2006-06-19 23:26:18 +00:00
|
|
|
SbxInfo* pRetInfo = new SbxInfo;
|
2005-06-21 18:07:46 +00:00
|
|
|
short nPar = p->nArgs & _ARGSMASK;
|
|
|
|
for( short i = 0; i < nPar; i++ )
|
|
|
|
{
|
|
|
|
p++;
|
|
|
|
String aName( p->pName, RTL_TEXTENCODING_ASCII_US );
|
2011-01-12 11:34:50 +01:00
|
|
|
sal_uInt16 nIFlags = ( p->nArgs >> 8 ) & 0x03;
|
2005-06-21 18:07:46 +00:00
|
|
|
if( p->nArgs & _OPT )
|
2006-06-19 23:26:18 +00:00
|
|
|
nIFlags |= SBX_OPTIONAL;
|
|
|
|
pRetInfo->AddParam( aName, p->eType, nIFlags );
|
2005-06-21 18:07:46 +00:00
|
|
|
}
|
2006-06-19 23:26:18 +00:00
|
|
|
return pRetInfo;
|
2005-06-21 18:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-08-22 11:39:37 +02:00
|
|
|
// help methods for the manager
|
2005-06-21 18:07:46 +00:00
|
|
|
|
|
|
|
IMPL_LINK( CommunicationWrapper, Open, CommunicationLink*, pLink )
|
|
|
|
{
|
2006-06-19 23:26:18 +00:00
|
|
|
if ( m_bCatchOpen )
|
|
|
|
m_pNewLink = pLink;
|
2005-06-21 18:07:46 +00:00
|
|
|
else
|
|
|
|
Events( CUniString("Open"), pLink );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_LINK( CommunicationWrapper, Close, CommunicationLink*, pLink )
|
|
|
|
{
|
|
|
|
Events( CUniString("Close"), pLink );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
IMPL_LINK( CommunicationWrapper, Data, CommunicationLink*, pLink )
|
|
|
|
{
|
|
|
|
Events( CUniString("Data"), pLink );
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void CommunicationWrapper::Events( String aType, CommunicationLink* pLink )
|
|
|
|
{
|
2006-06-19 23:26:18 +00:00
|
|
|
if ( m_aEventHandlerName.Len() )
|
2005-06-21 18:07:46 +00:00
|
|
|
{
|
|
|
|
SbxArrayRef pPar = new SbxArray( SbxVARIANT );
|
|
|
|
pPar->Put( new SbxVariable( SbxSTRING ), 1 );
|
|
|
|
pPar->Get( 1 )->PutString( aType );
|
|
|
|
|
|
|
|
pPar->Put( new SbxVariable( SbxOBJECT ), 2 );
|
|
|
|
pPar->Get( 2 )->PutObject( new CommunicationWrapper( pLink ) );
|
|
|
|
|
2006-06-19 23:26:18 +00:00
|
|
|
Call( m_aEventHandlerName, pPar );
|
2005-06-21 18:07:46 +00:00
|
|
|
}
|
|
|
|
else
|
2011-08-22 11:39:37 +02:00
|
|
|
delete pLink->GetServiceData(); // give away the stream to prevent blocking
|
2005-06-21 18:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2011-08-22 11:39:37 +02:00
|
|
|
// Properties and methods put down the return value for Get (bPut = sal_False) at
|
|
|
|
// element 0 of the Argv; for Put (bPut = sal_True) the value from element 0 is saved.
|
2005-06-21 18:07:46 +00:00
|
|
|
|
2011-08-22 11:39:37 +02:00
|
|
|
// the methods:
|
2005-06-21 18:07:46 +00:00
|
|
|
|
2011-08-22 11:39:37 +02:00
|
|
|
// manager
|
2011-01-12 11:34:50 +01:00
|
|
|
void CommunicationWrapper::MStartCommunication( SbxVariable* pVar, SbxArray* pPar, sal_Bool /*bWrite*/ )
|
2005-06-21 18:07:46 +00:00
|
|
|
{ // CommunicationLink StartCommunication( Host, Port )
|
2011-01-12 11:34:50 +01:00
|
|
|
m_bCatchOpen = sal_True;
|
2006-06-19 23:26:18 +00:00
|
|
|
if ( m_pManager->StartCommunication( ByteString( pPar->Get( 1 )->GetString(), RTL_TEXTENCODING_UTF8 ), pPar->Get( 2 )->GetULong() ) )
|
2005-06-21 18:07:46 +00:00
|
|
|
{
|
2006-06-19 23:26:18 +00:00
|
|
|
while ( !m_pNewLink )
|
2005-06-21 18:07:46 +00:00
|
|
|
GetpApp()->Reschedule();
|
2011-01-12 11:34:50 +01:00
|
|
|
m_bCatchOpen = sal_False;
|
2006-06-19 23:26:18 +00:00
|
|
|
CommunicationWrapper *pNewLinkWrapper = new CommunicationWrapper( m_pNewLink );
|
|
|
|
m_pNewLink = NULL;
|
2005-06-21 18:07:46 +00:00
|
|
|
pVar->PutObject( pNewLinkWrapper );
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-01-12 11:34:50 +01:00
|
|
|
void CommunicationWrapper::MStopAllCommunication( SbxVariable* /*pVar*/, SbxArray* /*pPar*/, sal_Bool /*bWrite*/ )
|
2011-08-22 11:39:37 +02:00
|
|
|
{ // StopAllCommunication
|
2006-06-19 23:26:18 +00:00
|
|
|
m_pManager->StopCommunication();
|
2005-06-21 18:07:46 +00:00
|
|
|
}
|
|
|
|
|
2011-01-12 11:34:50 +01:00
|
|
|
void CommunicationWrapper::MIsCommunicationRunning( SbxVariable* pVar, SbxArray* /*pPar*/, sal_Bool /*bWrite*/ )
|
2011-08-22 11:39:37 +02:00
|
|
|
{ // sal_Bool IsCommunicationRunning
|
2006-06-19 23:26:18 +00:00
|
|
|
pVar->PutBool( m_pManager->IsCommunicationRunning() );
|
2005-06-21 18:07:46 +00:00
|
|
|
}
|
|
|
|
|
2011-01-12 11:34:50 +01:00
|
|
|
void CommunicationWrapper::MGetMyName( SbxVariable* pVar, SbxArray* /*pPar*/, sal_Bool /*bWrite*/ )
|
2011-08-22 11:39:37 +02:00
|
|
|
{ // String GetMyName
|
2006-06-19 23:26:18 +00:00
|
|
|
pVar->PutString( UniString( m_pManager->GetMyName( CM_FQDN ), RTL_TEXTENCODING_UTF8 ) );
|
2005-06-21 18:07:46 +00:00
|
|
|
}
|
|
|
|
|
2011-01-12 11:34:50 +01:00
|
|
|
void CommunicationWrapper::MIsLinkValid( SbxVariable* pVar, SbxArray* pPar, sal_Bool /*bWrite*/ )
|
2011-08-22 11:39:37 +02:00
|
|
|
{ // sal_Bool IsLinkValid( CommunicationLink )
|
2005-06-21 18:07:46 +00:00
|
|
|
CommunicationWrapper *pWrapper = (CommunicationWrapper*)(pPar->Get( 1 )->GetObject());
|
2006-06-19 23:26:18 +00:00
|
|
|
pVar->PutBool( m_pManager->IsLinkValid( pWrapper->GetCommunicationLink() ) );
|
2005-06-21 18:07:46 +00:00
|
|
|
}
|
|
|
|
|
2011-01-12 11:34:50 +01:00
|
|
|
void CommunicationWrapper::MSetCommunicationEventHandler( SbxVariable* /*pVar*/, SbxArray* pPar, sal_Bool /*bWrite*/ )
|
2011-08-22 11:39:37 +02:00
|
|
|
{ // SetCommunicationEventHandler( String )
|
2006-06-19 23:26:18 +00:00
|
|
|
m_aEventHandlerName = pPar->Get( 1 )->GetString();
|
2005-06-21 18:07:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Link
|
2011-01-12 11:34:50 +01:00
|
|
|
void CommunicationWrapper::LStopCommunication( SbxVariable* /*pVar*/, SbxArray* /*pPar*/, sal_Bool /*bWrite*/ )
|
2011-08-22 11:39:37 +02:00
|
|
|
{ // StopCommunication
|
2006-06-19 23:26:18 +00:00
|
|
|
m_pLink->StopCommunication();
|
2005-06-21 18:07:46 +00:00
|
|
|
}
|
|
|
|
|
2011-01-12 11:34:50 +01:00
|
|
|
void CommunicationWrapper::LGetMyName( SbxVariable* pVar, SbxArray* /*pPar*/, sal_Bool /*bWrite*/ )
|
2011-08-22 11:39:37 +02:00
|
|
|
{ // String GetMyName
|
2006-06-19 23:26:18 +00:00
|
|
|
pVar->PutString( UniString( m_pLink->GetMyName( CM_FQDN ), RTL_TEXTENCODING_UTF8 ) );
|
2005-06-21 18:07:46 +00:00
|
|
|
}
|
|
|
|
|
2011-01-12 11:34:50 +01:00
|
|
|
void CommunicationWrapper::LGetHostName( SbxVariable* pVar, SbxArray* /*pPar*/, sal_Bool /*bWrite*/ )
|
2011-08-22 11:39:37 +02:00
|
|
|
{ // String GetHostName
|
2006-06-19 23:26:18 +00:00
|
|
|
pVar->PutString( UniString( m_pLink->GetCommunicationPartner( CM_FQDN ), RTL_TEXTENCODING_UTF8 ) );
|
2005-06-21 18:07:46 +00:00
|
|
|
}
|
|
|
|
|
2011-01-12 11:34:50 +01:00
|
|
|
void CommunicationWrapper::LSend( SbxVariable* /*pVar*/, SbxArray* pPar, sal_Bool /*bWrite*/ )
|
2011-08-22 11:39:37 +02:00
|
|
|
{ // Send(String )
|
2006-06-19 23:26:18 +00:00
|
|
|
SvStream *pSendStream = m_pLink->GetBestCommunicationStream();
|
2005-06-21 18:07:46 +00:00
|
|
|
String aSendString = pPar->Get( 1 )->GetString();
|
|
|
|
pSendStream->WriteByteString( aSendString, RTL_TEXTENCODING_UTF8 );
|
2006-06-19 23:26:18 +00:00
|
|
|
m_pLink->TransferDataStream( pSendStream );
|
2005-06-21 18:07:46 +00:00
|
|
|
delete pSendStream;
|
|
|
|
}
|
|
|
|
|
2011-01-12 11:34:50 +01:00
|
|
|
void CommunicationWrapper::LGetString( SbxVariable* pVar, SbxArray* /*pPar*/, sal_Bool /*bWrite*/ )
|
2011-08-22 11:39:37 +02:00
|
|
|
{ // String GetString
|
2006-06-19 23:26:18 +00:00
|
|
|
SvStream *pReceiveStream = m_pLink->GetServiceData();
|
2005-06-21 18:07:46 +00:00
|
|
|
if ( pReceiveStream )
|
|
|
|
{
|
2011-01-12 11:34:50 +01:00
|
|
|
sal_uLong nLength = pReceiveStream->Seek( STREAM_SEEK_TO_END );
|
2005-06-21 18:07:46 +00:00
|
|
|
pReceiveStream->Seek( STREAM_SEEK_TO_BEGIN );
|
|
|
|
char *pBuffer = new char[nLength];
|
|
|
|
pReceiveStream->Read( pBuffer, nLength );
|
2006-10-12 13:05:59 +00:00
|
|
|
String aReceive(
|
|
|
|
pBuffer, sal::static_int_cast< xub_StrLen >( nLength ),
|
|
|
|
RTL_TEXTENCODING_UTF8 );
|
2005-06-21 18:07:46 +00:00
|
|
|
delete [] pBuffer;
|
|
|
|
pVar->PutString( aReceive );
|
|
|
|
delete pReceiveStream;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
pVar->PutString( UniString() );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SbxObject* CommunicationFactory::CreateObject( const String& rClass )
|
|
|
|
{
|
|
|
|
if( rClass.CompareIgnoreCaseToAscii( "CommunicationManager" ) == COMPARE_EQUAL )
|
|
|
|
return new CommunicationWrapper( rClass );
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-10-12 15:57:08 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|