merge the formfield patch from ooo-build
[ooovba.git] / odk / examples / cpp / counter / countermain.cxx
blob7231d926f4fe773bfa535f598b259054181ee649
1 /*************************************************************************
3 * $RCSfile: countermain.cxx,v $
5 * $Revision: 1.9 $
7 * last change: $Author: vg $ $Date: 2008-01-28 16:30:31 $
9 * The Contents of this file are made available subject to the terms of
10 * the BSD license.
12 * Copyright (c) 2003 by Sun Microsystems, Inc.
13 * All rights reserved.
15 * Redistribution and use in source and binary forms, with or without
16 * modification, are permitted provided that the following conditions
17 * are met:
18 * 1. Redistributions of source code must retain the above copyright
19 * notice, this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright
21 * notice, this list of conditions and the following disclaimer in the
22 * documentation and/or other materials provided with the distribution.
23 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
24 * contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
30 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
31 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
33 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
34 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
35 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
36 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
37 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 *************************************************************************/
41 /*************************************************************************
42 *************************************************************************
44 * simple client application registering and using the counter component.
46 *************************************************************************
47 *************************************************************************/
49 #include <stdio.h>
51 #include <rtl/ustring.hxx>
53 #include <osl/diagnose.h>
55 #include <cppuhelper/bootstrap.hxx>
57 // generated c++ interfaces
58 #include <com/sun/star/lang/XComponent.hpp>
59 #include <com/sun/star/lang/XMultiComponentFactory.hpp>
60 #include <com/sun/star/registry/XImplementationRegistration.hpp>
61 #include <foo/XCountable.hpp>
64 using namespace foo;
65 using namespace cppu;
66 using namespace com::sun::star::uno;
67 using namespace com::sun::star::lang;
68 using namespace com::sun::star::registry;
70 using namespace ::rtl;
73 //=======================================================================
74 int SAL_CALL main(int argc, char **argv)
76 Reference< XSimpleRegistry > xReg = createSimpleRegistry();
77 OSL_ENSURE( xReg.is(), "### cannot get service instance of \"com.sun.star.regiystry.SimpleRegistry\"!" );
79 xReg->open(OUString::createFromAscii("counter.uno.rdb"), sal_False, sal_False);
80 OSL_ENSURE( xReg->isValid(), "### cannot open test registry \"counter.uno.rdb\"!" );
82 Reference< XComponentContext > xContext = bootstrap_InitialComponentContext(xReg);
83 OSL_ENSURE( xContext.is(), "### cannot creage intial component context!" );
85 Reference< XMultiComponentFactory > xMgr = xContext->getServiceManager();
86 OSL_ENSURE( xMgr.is(), "### cannot get initial service manager!" );
88 // register my counter component
89 Reference< XImplementationRegistration > xImplReg(
90 xMgr->createInstanceWithContext(OUString::createFromAscii("com.sun.star.registry.ImplementationRegistration"), xContext), UNO_QUERY);
91 OSL_ENSURE( xImplReg.is(), "### cannot get service instance of \"com.sun.star.registry.ImplementationRegistration\"!" );
93 if (xImplReg.is())
95 xImplReg->registerImplementation(
96 OUString::createFromAscii("com.sun.star.loader.SharedLibrary"), // loader for component
97 #ifdef UNX
98 #ifdef MACOSX
99 OUString::createFromAscii("counter.uno.dylib"), // component location
100 #else
101 OUString::createFromAscii("counter.uno.so"), // component location
102 #endif
103 #else
104 OUString::createFromAscii("counter.uno.dll"), // component location
105 #endif
106 Reference< XSimpleRegistry >() // registry omitted,
107 // defaulting to service manager registry used
110 // get a counter instance
111 Reference< XInterface > xx ;
112 xx = xMgr->createInstanceWithContext(OUString::createFromAscii("foo.Counter"), xContext);
113 Reference< XCountable > xCount( xx, UNO_QUERY );
114 OSL_ENSURE( xCount.is(), "### cannot get service instance of \"foo.Counter\"!" );
116 if (xCount.is())
118 xCount->setCount( 42 );
119 fprintf( stdout , "%d," , xCount->getCount() );
120 fprintf( stdout , "%d," , xCount->increment() );
121 fprintf( stdout , "%d\n" , xCount->decrement() );
125 Reference< XComponent >::query( xContext )->dispose();
126 return 0;