diff options
Diffstat (limited to 'odk/examples/cpp/counter')
-rw-r--r-- | odk/examples/cpp/counter/Makefile | 42 | ||||
-rw-r--r-- | odk/examples/cpp/counter/counter.cxx | 54 | ||||
-rw-r--r-- | odk/examples/cpp/counter/countermain.cxx | 68 |
3 files changed, 80 insertions, 84 deletions
diff --git a/odk/examples/cpp/counter/Makefile b/odk/examples/cpp/counter/Makefile index 5e7f620a..161145f7 100644 --- a/odk/examples/cpp/counter/Makefile +++ b/odk/examples/cpp/counter/Makefile @@ -43,15 +43,18 @@ include $(SETTINGS)/dk.mk # Define non-platform/compiler specific settings COMP_NAME=counter -COMP_IMPL_NAME=$(COMP_NAME).uno.$(SHAREDLIB_EXT) +COMP_IMPL_NAME=$(COMP_NAME).uno.$(SHAREDLIB_EXT) COMP_IMPL=$(SHAREDLIB_OUT)/$(COMP_IMPL_NAME) COMP_RDB_NAME = $(COMP_NAME).uno.rdb COMP_RDB = $(OUT_BIN)/$(COMP_RDB_NAME) -COMP_MAPFILE = $(OUT_COMP_GEN)/$(COMP_NAME).uno.map OUT_COMP_INC = $(OUT_INC)/$(COMP_NAME) OUT_COMP_GEN = $(OUT_MISC)/$(COMP_NAME) OUT_COMP_OBJ = $(OUT_OBJ)/$(COMP_NAME) OUT_COMP_SLO = $(OUT_SLO)/$(COMP_NAME) +COMP_SERVICES=$(SHAREDLIB_OUT)/counterservices.rdb + +ENV_EXAMPLE_TYPES=-env:URE_MORE_TYPES=$(URLPREFIX)$(COMP_RDB) +ENV_COMP_SERVICES=-env:URE_MORE_SERVICES=$(URLPREFIX)$(COMP_SERVICES) COMP_TYPEFLAG = $(OUT_MISC)/cpp_$(COMP_NAME)_types.flag @@ -84,12 +87,12 @@ $(OUT_BIN)/%.rdb : $(GENURDFILES) -$(MKDIR) $(subst /,$(PS),$(@D)) -$(DEL) $(subst \\,\,$(subst /,$(PS),$@)) $(REGMERGE) $@ /UCR $(GENURDFILES) - $(REGMERGE) $@ / $(URE_TYPES) +# $(REGMERGE) $@ / $(URE_TYPES) $(COMP_TYPEFLAG) : $(COMP_RDB) $(SDKTYPEFLAG) -$(MKDIR) $(subst /,$(PS),$(@D)) -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_TYPEFLAG))) - $(CPPUMAKER) -Gc -BUCR -O$(OUT_COMP_INC) $(TYPESLIST) $(COMP_RDB) + $(CPPUMAKER) -Gc -BUCR -O$(OUT_COMP_INC) $(TYPESLIST) $(COMP_RDB) -X $(URE_TYPES) echo flagged > $@ $(OUT_COMP_OBJ)/%.$(OBJ_EXT) : %.cxx $(COMP_TYPEFLAG) @@ -102,13 +105,6 @@ $(OUT_COMP_SLO)/%.$(OBJ_EXT) : %.cxx $(COMP_TYPEFLAG) -$(MKDIR) $(subst /,$(PS),$(@D)) $(CC) $(CC_FLAGS) $(CC_INCLUDES) -I$(OUT_COMP_INC) $(CC_DEFINES) $(CC_OUTPUT_SWITCH)$(subst /,$(PS),$@) $< -$(COMP_MAPFILE) : $(SLOFILES) - -$(MKDIR) $(subst /,$(PS),$(@D)) - cat $(PRJ)/settings/component.uno.map > $(COMP_MAPFILE) -ifeq "$(OS)" "MACOSX" - nm -gx $(SLOFILES) | $(ADDSYMBOLS) >> $(COMP_MAPFILE) -endif - ifeq "$(OS)" "WIN" $(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES) -$(MKDIR) $(subst /,$(PS),$(@D)) @@ -118,7 +114,7 @@ $(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES) $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STLPORTLIB) msvcrt.lib kernel32.lib $(LINK_MANIFEST) else -$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES) $(COMP_MAPFILE) +$(SHAREDLIB_OUT)/%.$(SHAREDLIB_EXT) : $(SLOFILES) -$(MKDIR) $(subst /,$(PS),$(@D)) $(LINK) $(COMP_LINK_FLAGS) $(LINK_LIBS) -o $@ $(SLOFILES) \ $(CPPUHELPERLIB) $(CPPULIB) $(SALLIB) $(STLPORTLIB) $(STC++LIB) $(CPPUHELPERDYLIB) $(CPPUDYLIB) $(SALDYLIB) @@ -138,16 +134,33 @@ else $(CPPUHELPERLIB) $(CPPULIB) $(SALHELPERLIB) $(SALLIB) $(STLPORTLIB) $(STDC++LIB) endif +$(COMP_SERVICES) : + -$(MKDIR) $(subst /,$(PS),$(@D)) + @echo $(OSEP)?xml version="$(QM)1.0$(QM)" encoding="$(QM)UTF-8$(QM)"?$(CSEP) > $@ + @echo $(OSEP)components xmlns="$(QM)http://openoffice.org/2010/uno-components$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)component loader="$(QM)com.sun.star.loader.SharedLibrary$(QM)" uri="$(QM)$(COMP_IMPL_NAME)$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)implementation name="$(QM)com.sun.star.comp.example.cpp.Counter$(QM)"$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)service name="$(QM)foo.Counter$(QM)"/$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)/implementation$(CSEP) >> $@ + @echo $(SQM) $(SQM)$(OSEP)/component$(CSEP) >> $@ + @echo $(OSEP)/components$(CSEP) >> $@ + -CppCounterExample : $(OUT_BIN)/countermain$(EXE_EXT) $(COMP_IMPL) +CppCounterExample : $(OUT_BIN)/countermain$(EXE_EXT) $(COMP_IMPL) $(COMP_SERVICES) @echo -------------------------------------------------------------------------------- @echo Please use the following command to execute the example! @echo - @echo $(MAKE) countermain.run + @echo - + @echo NOTE: The example makes use of the URE and use the defaultBootstrap_InitialComponentContext method. + @echo $(SQM) $(SQM)The additional example IDL types are provided via the UNO environment variable -env:URE_MORE_TYPES=... + @echo $(SQM) $(SQM)and the example component is made available via -env:URE_MORE_SERVICES=... + @echo $(SQM) $(SQM)Please check the generated $(QM)$(COMP_SERVICES)$(QM) to see how you can specify your own components in such an environment + @echo $(SQM) $(SQM)and how to use the passive UNO registration. @echo -------------------------------------------------------------------------------- %.run: $(OUT_BIN)/countermain$(EXE_EXT) $(COMP_IMPL) - cd $(subst /,$(PS),$(OUT_BIN)) && $(basename $@) + cd $(subst /,$(PS),$(OUT_BIN)) && $(basename $@) $(ENV_EXAMPLE_TYPES) $(ENV_COMP_SERVICES) .PHONY: clean clean : @@ -159,3 +172,4 @@ clean : -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_RDB))) -$(DEL) $(subst \\,\,$(subst /,$(PS),$(SHAREDLIB_OUT)/$(COMP_NAME).*)) -$(DEL) $(subst \\,\,$(subst /,$(PS),$(OUT_BIN)/countermain*)) + -$(DEL) $(subst \\,\,$(subst /,$(PS),$(COMP_SERVICES))) diff --git a/odk/examples/cpp/counter/counter.cxx b/odk/examples/cpp/counter/counter.cxx index db903cfa..f13ee41f 100644 --- a/odk/examples/cpp/counter/counter.cxx +++ b/odk/examples/cpp/counter/counter.cxx @@ -167,7 +167,7 @@ Reference< XInterface > SAL_CALL MyCounterImpl_create( /** * Gives the environment this component belongs to. */ -extern "C" void SAL_CALL component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv) +extern "C" SAL_DLLPUBLIC_EXPORT void SAL_CALL component_getImplementationEnvironment(const sal_Char ** ppEnvTypeName, uno_Environment ** ppEnv) { *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME; } @@ -179,33 +179,33 @@ extern "C" void SAL_CALL component_getImplementationEnvironment(const sal_Char * * @param pServiceManager the service manager * @param pRegistryKey the registry key */ -extern "C" sal_Bool SAL_CALL component_writeInfo(void * pServiceManager, void * pRegistryKey) -{ - sal_Bool result = sal_False; - - if (pRegistryKey) - { - try - { - Reference< XRegistryKey > xNewKey( - reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( - OUString( RTL_CONSTASCII_USTRINGPARAM("/" IMPLNAME "/UNO/SERVICES") ) ) ); +// extern "C" SAL_DLLPUBLIC_EXPORT sal_Bool SAL_CALL component_writeInfo(void * pServiceManager, void * pRegistryKey) +// { +// sal_Bool result = sal_False; + +// if (pRegistryKey) +// { +// try +// { +// Reference< XRegistryKey > xNewKey( +// reinterpret_cast< XRegistryKey * >( pRegistryKey )->createKey( +// OUString( RTL_CONSTASCII_USTRINGPARAM("/" IMPLNAME "/UNO/SERVICES") ) ) ); - const Sequence< OUString > & rSNL = - MyCounterImpl::getSupportedServiceNames_Static(); - const OUString * pArray = rSNL.getConstArray(); - for ( sal_Int32 nPos = rSNL.getLength(); nPos--; ) - xNewKey->createKey( pArray[nPos] ); +// const Sequence< OUString > & rSNL = +// MyCounterImpl::getSupportedServiceNames_Static(); +// const OUString * pArray = rSNL.getConstArray(); +// for ( sal_Int32 nPos = rSNL.getLength(); nPos--; ) +// xNewKey->createKey( pArray[nPos] ); - return sal_True; - } - catch (InvalidRegistryException &) - { - // we should not ignore exceptions - } - } - return result; -} +// return sal_True; +// } +// catch (InvalidRegistryException &) +// { +// // we should not ignore exceptions +// } +// } +// return result; +// } /** * This function is called to get service factories for an implementation. @@ -215,7 +215,7 @@ extern "C" sal_Bool SAL_CALL component_writeInfo(void * pServiceManager, void * * @param pRegistryKey the registry key for this component, need for persistent data * @return a component factory */ -extern "C" void * SAL_CALL component_getFactory(const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey) +extern "C" SAL_DLLPUBLIC_EXPORT void * SAL_CALL component_getFactory(const sal_Char * pImplName, void * pServiceManager, void * pRegistryKey) { void * pRet = 0; diff --git a/odk/examples/cpp/counter/countermain.cxx b/odk/examples/cpp/counter/countermain.cxx index 08a68b19..fce1715f 100644 --- a/odk/examples/cpp/counter/countermain.cxx +++ b/odk/examples/cpp/counter/countermain.cxx @@ -68,55 +68,37 @@ using namespace ::rtl; //======================================================================= SAL_IMPLEMENT_MAIN() { - Reference< XSimpleRegistry > xReg = createSimpleRegistry(); - OSL_ENSURE( xReg.is(), "### cannot get service instance of \"com.sun.star.regiystry.SimpleRegistry\"!" ); - - xReg->open(OUString::createFromAscii("counter.uno.rdb"), sal_False, sal_False); - OSL_ENSURE( xReg->isValid(), "### cannot open test registry \"counter.uno.rdb\"!" ); - - Reference< XComponentContext > xContext = bootstrap_InitialComponentContext(xReg); - OSL_ENSURE( xContext.is(), "### cannot creage intial component context!" ); - - Reference< XMultiComponentFactory > xMgr = xContext->getServiceManager(); - OSL_ENSURE( xMgr.is(), "### cannot get initial service manager!" ); - - // register my counter component - Reference< XImplementationRegistration > xImplReg( - xMgr->createInstanceWithContext(OUString::createFromAscii("com.sun.star.registry.ImplementationRegistration"), xContext), UNO_QUERY); - OSL_ENSURE( xImplReg.is(), "### cannot get service instance of \"com.sun.star.registry.ImplementationRegistration\"!" ); - - if (xImplReg.is()) - { - xImplReg->registerImplementation( - OUString::createFromAscii("com.sun.star.loader.SharedLibrary"), // loader for component -#ifdef UNX -#ifdef MACOSX - OUString::createFromAscii("counter.uno.dylib"), // component location -#else - OUString::createFromAscii("counter.uno.so"), // component location -#endif -#else - OUString::createFromAscii("counter.uno.dll"), // component location -#endif - Reference< XSimpleRegistry >() // registry omitted, - // defaulting to service manager registry used - ); - - // get a counter instance - Reference< XInterface > xx ; - xx = xMgr->createInstanceWithContext(OUString::createFromAscii("foo.Counter"), xContext); + try { + + Reference< XComponentContext > xContext(::cppu::defaultBootstrap_InitialComponentContext()); + OSL_ENSURE( xContext.is(), "### bootstrap failed!\n" ); + + Reference< XMultiComponentFactory > xMgr = xContext->getServiceManager(); + OSL_ENSURE( xMgr.is(), "### cannot get initial service manager!" ); + + Reference< XInterface > xx = xMgr->createInstanceWithContext( + OUString::createFromAscii("foo.Counter"), xContext); + + OSL_ENSURE( xx.is(), "### cannot get service instance of \"foo.Counter\"!" ); + Reference< XCountable > xCount( xx, UNO_QUERY ); - OSL_ENSURE( xCount.is(), "### cannot get service instance of \"foo.Counter\"!" ); + OSL_ENSURE( xCount.is(), "### cannot query XCountable interface of service instance \"foo.Counter\"!" ); if (xCount.is()) { - xCount->setCount( 42 ); - fprintf( stdout , "%d," , xCount->getCount() ); - fprintf( stdout , "%d," , xCount->increment() ); - fprintf( stdout , "%d\n" , xCount->decrement() ); + xCount->setCount( 42 ); + fprintf( stdout , "%d," , (int)xCount->getCount() ); + fprintf( stdout , "%d," , (int)xCount->increment() ); + fprintf( stdout , "%d\n" , (int)xCount->decrement() ); } + + Reference< XComponent >::query( xContext )->dispose(); + + } catch( Exception& e) { + printf("Error: caught exception:\n %s\n", + OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US).getStr()); + exit(1); } - Reference< XComponent >::query( xContext )->dispose(); return 0; } |