Files
libreoffice/desktop/source/offacc/acceptor.cxx

302 lines
9.6 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: Patch contributed by: Jurgen Schmidt remove onlineregistration with dependencies http://svn.apache.org/viewvc?view=revision&revision=1240245 imported patch package_eventlistener.patch http://svn.apache.org/viewvc?view=revision&revision=1172103 Patch contributed by Pedro Giffuni Accept Google Chrome OS fonts as equivalent to MS fonts. http://svn.apache.org/viewvc?view=revision&revision=1233155 http://svn.apache.org/viewvc?view=revision&revision=1233408 Patch contributed by Andre Fischer Do not add targets for junit tests when junit is disabled. http://svn.apache.org/viewvc?view=revision&revision=1241508 Patches contributed by Mathias Bauer (and others) gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 cws mba34issues01: #i114600#: remove forbidden characters from list of unencoded characters http://svn.apache.org/viewvc?view=revision&revision=1172370 Patches contributed by Oliver Rainer-Wittman some clean up in JPEGReader due to memory constraints http://svn.apache.org/viewvc?view=revision&revision=1299729 119114 - method <UpdateDialog::addSpecificError(..)> - create entry with correct type http://svn.apache.org/viewvc?view=revision&revision=1305265 Patches contributed by Ariel Constenla-Haile i118707 - make toolbar control's popup window grab focus http://svn.apache.org/viewvc?view=revision&revision=1225846 Patches contributed by Herbert Duerr #i118662# remove usage of BerkeleyDB in desktop module http://svn.apache.org/viewvc?view=revision&revision=1213171 minor cleanups in dp_persmap.* http://svn.apache.org/viewvc?view=revision&revision=1215064 flush early to prevent problem with extension manager not cleaning up its objects http://svn.apache.org/viewvc?view=revision&revision=1228147 i118726 do not flush *pmap file while reading it http://svn.apache.org/viewvc?view=revision&revision=1230614 #i119048# migrate BDB extension entries using a simple heuristic http://svn.apache.org/viewvc?view=revision&revision=1300972 #i119048# handle edge cases when importing BDB hash files http://svn.apache.org/viewvc?view=revision&revision=1301428 #i119113# fix of-by-one when importing BDB files http://svn.apache.org/viewvc?view=revision&revision=1305420 restore our encryption settings, icon themes, and dictionaries. removed wrapper hacks, kill obsolete bundled extension blob / pre-registration handling, remove duplicated quickstart code. remove OS/2 conditionals.
2012-11-15 17:28:16 +00:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
#include <sal/config.h>
#include "acceptor.hxx"
#include <com/sun/star/bridge/BridgeFactory.hpp>
#include <com/sun/star/connection/Acceptor.hpp>
#include <com/sun/star/uno/XNamingService.hpp>
#include <comphelper/processfactory.hxx>
#include <cppuhelper/factory.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <sal/log.hxx>
using namespace css::bridge;
using namespace css::connection;
using namespace css::container;
using namespace css::lang;
using namespace css::uno;
namespace desktop
{
extern "C" void offacc_workerfunc (void * acc)
{
osl_setThreadName("URP Acceptor");
static_cast<Acceptor*>(acc)->run();
}
Acceptor::Acceptor( const Reference< XComponentContext >& rxContext )
: m_thread(NULL)
, m_rContext(rxContext)
, m_bInit(false)
, m_bDying(false)
{
m_rAcceptor = css::connection::Acceptor::create(m_rContext);
m_rBridgeFactory = BridgeFactory::create(m_rContext);
}
Acceptor::~Acceptor()
{
m_rAcceptor->stopAccepting();
oslThread t;
{
osl::MutexGuard g(m_aMutex);
t = m_thread;
}
//prevent locking if the thread is still waiting
m_bDying = true;
m_cEnable.set();
osl_joinWithThread(t);
{
// Make the final state of m_bridges visible to this thread (since
// m_thread is joined, the code that follows is the only one left
// accessing m_bridges):
osl::MutexGuard g(m_aMutex);
}
for (;;) {
css::uno::Reference< css::bridge::XBridge > b(m_bridges.remove());
if (!b.is()) {
break;
}
css::uno::Reference< css::lang::XComponent >(
b, css::uno::UNO_QUERY_THROW)->dispose();
}
}
void Acceptor::run()
{
SAL_INFO( "desktop.offacc", "Acceptor::run" );
for (;;)
{
try
{
// wait until we get enabled
SAL_INFO( "desktop.offacc",
"Acceptor::run waiting for office to come up");
m_cEnable.wait();
if (m_bDying) //see destructor
break;
SAL_INFO( "desktop.offacc",
"Acceptor::run now enabled and continuing");
// accept connection
Reference< XConnection > rConnection = m_rAcceptor->accept( m_aConnectString );
// if we return without a valid connection we mus assume that the acceptor
// is destructed so we break out of the run method terminating the thread
if (! rConnection.is()) break;
OUString aDescription = rConnection->getDescription();
SAL_INFO( "desktop.offacc", "Acceptor::run connection " << aDescription );
// create instanceprovider for this connection
Reference< XInstanceProvider > rInstanceProvider(
new AccInstanceProvider(m_rContext, rConnection));
// create the bridge. The remote end will have a reference to this bridge
// thus preventing the bridge from being disposed. When the remote end releases
// the bridge, it will be destructed.
Reference< XBridge > rBridge = m_rBridgeFactory->createBridge(
"", m_aProtocol, rConnection, rInstanceProvider);
osl::MutexGuard g(m_aMutex);
m_bridges.add(rBridge);
} catch (const Exception& e) {
SAL_WARN("desktop.offacc", "caught Exception \"" << e.Message << "\"");
// connection failed...
// something went wrong during connection setup.
// just wait for a new connection to accept
}
}
}
// XInitialize
void Acceptor::initialize( const Sequence<Any>& aArguments )
throw( Exception, std::exception )
{
// prevent multiple initialization
osl::ClearableMutexGuard aGuard( m_aMutex );
SAL_INFO( "desktop.offacc", "Acceptor::initialize()" );
bool bOk = false;
// arg count
int nArgs = aArguments.getLength();
// not yet initialized and accept-string
if (!m_bInit && nArgs > 0 && (aArguments[0] >>= m_aAcceptString))
{
SAL_INFO( "desktop.offacc", "Acceptor::initialize string=" << m_aAcceptString );
// get connect string and protocol from accept string
// "<connectString>;<protocol>"
sal_Int32 nIndex1 = m_aAcceptString.indexOf( ';' );
if (nIndex1 < 0)
throw IllegalArgumentException(
"Invalid accept-string format", m_rContext, 1);
m_aConnectString = m_aAcceptString.copy( 0 , nIndex1 ).trim();
nIndex1++;
sal_Int32 nIndex2 = m_aAcceptString.indexOf( ';' , nIndex1 );
if (nIndex2 < 0) nIndex2 = m_aAcceptString.getLength();
m_aProtocol = m_aAcceptString.copy( nIndex1, nIndex2 - nIndex1 );
// start accepting in new thread...
m_thread = osl_createThread(offacc_workerfunc, this);
m_bInit = true;
bOk = true;
}
// do we want to enable accepting?
bool bEnable = false;
CWS-TOOLING: integrate CWS fwk95 2009-01-15 13:24:14 +0100 cd r266366 : #i96390# Change method name to use UNO AWT style for mnemonics 2009-01-15 13:23:30 +0100 cd r266365 : #i96390# Change method name to use UNO AWT style for mnemonics 2009-01-12 17:25:13 +0100 cd r266174 : #i97983# Check pointer returned by dynamic_cast 2009-01-12 15:31:40 +0100 cd r266162 : #i97983# Create toolkit popup menus via service manager instead of implementation class 2008-12-11 15:04:34 +0100 cd r265305 : #i95863# Remove user defined properties 2008-12-11 14:56:45 +0100 cd r265302 : #i95606# Update documentation for textfields 2008-12-11 10:06:20 +0100 cd r265250 : #i96390# Fix warning on Solaris compiler 2008-12-09 17:27:32 +0100 cd r265119 : CWS-TOOLING: rebase CWS fwk95 to trunk@264807 (milestone: DEV300:m37) 2008-12-01 13:29:43 +0100 cd r264597 : #i96390# New interfaces and structures for complete UNO AWT menu API 2008-12-01 13:25:22 +0100 cd r264596 : #i96390# Added implementation of the new UNO AWT interfaces and structures for menus 2008-11-28 13:55:19 +0100 cd r264553 : #i96640# Fixed wrong property type for MenuBarCloser 2008-11-28 13:53:56 +0100 cd r264552 : #i96621# Fixed ambiguous usage of && and || 2008-11-18 16:05:45 +0100 cd r263781 : #i95316# Initialize SvtTabAppearanceCfg to enable system settings changed notiifcation code 2008-11-18 16:05:43 +0100 cd r263780 : #i96155# Fix wrong statement to check for enabled argument 2008-10-20 16:54:37 +0200 cd r262328 : #i10000# migrate CWS fwk95 to SVN.
2009-01-21 15:28:14 +00:00
if (((nArgs == 1 && (aArguments[0] >>= bEnable)) ||
(nArgs == 2 && (aArguments[1] >>= bEnable))) &&
bEnable )
{
m_cEnable.set();
bOk = true;
}
if (!bOk)
{
throw IllegalArgumentException( "invalid initialization", m_rContext, 1);
}
}
// XServiceInfo
OUString Acceptor::impl_getImplementationName()
{
return OUString("com.sun.star.office.comp.Acceptor");
}
OUString Acceptor::getImplementationName()
throw (RuntimeException, std::exception)
{
return Acceptor::impl_getImplementationName();
}
Sequence<OUString> Acceptor::impl_getSupportedServiceNames()
{
Sequence<OUString> aSequence(1);
aSequence[0] = "com.sun.star.office.Acceptor";
return aSequence;
}
Sequence<OUString> Acceptor::getSupportedServiceNames()
throw (RuntimeException, std::exception)
{
return Acceptor::impl_getSupportedServiceNames();
}
sal_Bool Acceptor::supportsService(OUString const & ServiceName)
throw (css::uno::RuntimeException, std::exception)
{
return cppu::supportsService(this, ServiceName);
}
// Factory
Reference< XInterface > Acceptor::impl_getInstance( const Reference< XMultiServiceFactory >& aFactory )
{
try {
return static_cast<cppu::OWeakObject *>(
new Acceptor(comphelper::getComponentContext(aFactory)));
2011-12-06 00:19:44 +09:00
} catch ( const Exception& ) {
return css::uno::Reference<css::uno::XInterface>();
}
}
// InstanceProvider
AccInstanceProvider::AccInstanceProvider(const Reference<XComponentContext>& rxContext, const Reference<XConnection>& rConnection)
{
m_rContext = rxContext;
m_rConnection = rConnection;
}
AccInstanceProvider::~AccInstanceProvider()
{
}
Reference<XInterface> AccInstanceProvider::getInstance (const OUString& aName )
throw ( NoSuchElementException, std::exception )
{
Reference<XInterface> rInstance;
if ( aName == "StarOffice.ServiceManager" )
{
rInstance = Reference< XInterface >( m_rContext->getServiceManager() );
}
else if ( aName == "StarOffice.ComponentContext" )
{
rInstance = m_rContext;
}
else if ( aName == "StarOffice.NamingService" )
{
Reference< XNamingService > rNamingService(
m_rContext->getServiceManager()->createInstanceWithContext("com.sun.star.uno.NamingService", m_rContext),
UNO_QUERY );
if ( rNamingService.is() )
{
rNamingService->registerObject(
OUString("StarOffice.ServiceManager" ), m_rContext->getServiceManager() );
rNamingService->registerObject(
OUString("StarOffice.ComponentContext" ), m_rContext );
rInstance = rNamingService;
}
}
return rInstance;
}
}
// component management stuff...
extern "C"
{
using namespace desktop;
SAL_DLLPUBLIC_EXPORT void * SAL_CALL offacc_component_getFactory(char const *pImplementationName, void *pServiceManager, void *)
{
void* pReturn = NULL ;
if ( pImplementationName && pServiceManager )
{
// Define variables which are used in following macros.
Reference< XSingleServiceFactory > xFactory;
Reference< XMultiServiceFactory > xServiceManager(
static_cast< XMultiServiceFactory* >(pServiceManager));
if (desktop::Acceptor::impl_getImplementationName().equalsAscii( pImplementationName ) )
{
xFactory = Reference< XSingleServiceFactory >( cppu::createSingleFactory(
xServiceManager, desktop::Acceptor::impl_getImplementationName(),
desktop::Acceptor::impl_getInstance, desktop::Acceptor::impl_getSupportedServiceNames()) );
}
// Factory is valid - service was found.
if ( xFactory.is() )
{
xFactory->acquire();
pReturn = xFactory.get();
}
}
// Return with result of this operation.
return pReturn ;
}
} // extern "C"
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */