Counter Example

From Apache OpenOffice Wiki
Revision as of 09:58, 25 May 2006 by SergeMoutou (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

This example given with the SDK is previously partially takled : see chapter 11.5. It contains two files : counter.cxx and countermain.cxx. These files shows differencies with Listing 3 and Listing 4 previously tackled because they have to run with OpenOffice.org now. This little example uses a registered external module (counter.uno.so build from counter.cxx) and a main program (countermain.cxx) which uses it. The generated counter, like ProfUnoLifeTime, is able to run even if OpenOffice isn't running. MainCounter in the Figure below is the binary program file to run to test the example. There is no direct arrow between MainCounter and Counter.uno.so, indicating that they are independent of each other : if MainCounter want something from Counter.uno.so, it has to ask to cppuhelper (in other words to Openoffice). This example has been done previously without the cppuhelper, but the intention is to demonstrate the use of cppuhelper in this specific situation.

MakefileCounterEx.png

The make dependency for this example (see Figure above) is more complicated than previously, because of the two cpp source files : counter.cxx and countermain.cxx. Please note we have to create a third file in this example : XCounter.idl. The listing of this IDL file is now comprehensive by a reader who have studied chapter 10 :

//Listing 6 The IDL Counter File
// IDL
#include <com/sun/star/uno/XInterface.idl>

module foo
{
	/**
	 * Interface to count things. 
	 */
	interface XCountable : com::sun::star::uno::XInterface
	{
		long getCount();
		void setCount( [in] long nCount );
		long increment();
		long decrement();
	};

	service Counter
	{
		// exported interface:
		interface XCountable;
	};
};

This IDL file describe the interface of counter.cxx which will become counter.uno.so (counter.uno.dll under Windows), a library file after compilation. But again you call one of the four method not directly but through cppuhelper.

Return to Constructing Component or to "Using C++ with OOo SDK" main page

Personal tools