Hi Artur,
> Hi!
>
> I want to update my grammar checker (Esperantilo) from 3.0 interface to 
> new 3.1 XProofreader.
> It seems that there is some changes about handling XProofreader 
> instances,  isn't it?
>
> By the old implementation I have used
> ::cppu::createSingleComponentFactory
> to create XGrammarChecker component and it works fine.
>
> No if I use this method, OO tries to create many instances of 
> XProofreader and it will be overloaded and unusable.
> I have looked into Java LanguageTool implementation. It uses own 
> singleton factory.
>
> What is the right way to do it in C++. Is 
> ::cppu::createSingleComponentFactory not the right method to ensure
> that there is only one instance of Proofreader?
>
> In the OO documentation
> http://wiki.services.openoffice.org/wiki/Uno/Cpp/Tutorials/Introduction_to_Cpp_Uno
> is said not to use own singletons.
>
> Is there any example of Grammar Checker in C++?
>   

I use the following code:



static ::rtl::OUString MyProofreader_getImplementationName() throw()
{
    return A2OU( GRAMMARCHECKER_IMPLNAME );
}


static uno::Sequence< OUString >
MyProofreader_getSupportedServiceNames(  ) throw()
{
    uno::Sequence< OUString > aSNS( 1 );
    aSNS.getArray()[0] = A2OU( GRAMMARCHECKER_SERVICENAME );
    return aSNS;
}


static uno::Reference< uno::XInterface > SAL_CALL
MyProofreader_createInstance(
    const uno::Reference< lang::XMultiServiceFactory > & rxSMgr )
throw(uno::Exception)
{
    MyProofreader *pObj = new MyProofreader( rxSMgr );
    uno::Reference< uno::XInterface > xRes( dynamic_cast<
linguistic2::XProofreader * >(pObj) );
    pObj->Init();
    return xRes;
}
   

void * SAL_CALL MyProofreader_getFactory(
    const sal_Char *pImplName,
    lang::XMultiServiceFactory *pServiceManager,
    void * /*pRegistryKey*/ )
{
    void * pRet = 0;
    if ( !MyProofreader_getImplementationName().compareToAscii(
pImplName ) )
    {
        uno::Reference< lang::XSingleServiceFactory > xFactory =
            cppu::createOneInstanceFactory(
                pServiceManager,
                MyProofreader_getImplementationName(),
                MyProofreader_createInstance,
                MyProofreader_getSupportedServiceNames());
        // acquire, because we return an interface pointer instead of a
reference
        xFactory->acquire();
        pRet = xFactory.get();
    }
    return pRet;
}


sal_Bool SAL_CALL MyProofreader_writeInfo(
    void * /*pServiceManager*/,
    registry::XRegistryKey * pRegistryKey )
{
    try
    {
        OUString aImpl( '/' );
        aImpl += MyProofreader_getImplementationName().getStr();
        aImpl += A2OU( "/UNO/SERVICES" );
        uno::Reference< registry::XRegistryKey > xNewKey =
pRegistryKey->createKey( aImpl );
        uno::Sequence< OUString > aServices =
MyProofreader_getSupportedServiceNames();
        for( sal_Int32 i = 0; i < aServices.getLength(); i++ )
            xNewKey->createKey( aServices.getConstArray()[i] );

        return sal_True;
    }
    catch (uno::Exception &)
    {
        return sal_False;
    }
}


Maybe createOneInstanceFactory is all that you need.
Unfortunately there was no really wotking create...Component function to
do that. Because of that we used the older and actually deprecated
createOneInstanceFactory, at least that one works just fine.


Thomas



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@lingucomponent.openoffice.org
For additional commands, e-mail: dev-h...@lingucomponent.openoffice.org

Reply via email to