1*34dd1e25SAndrew Rist /**************************************************************
2*34dd1e25SAndrew Rist  *
3*34dd1e25SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*34dd1e25SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*34dd1e25SAndrew Rist  * distributed with this work for additional information
6*34dd1e25SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*34dd1e25SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*34dd1e25SAndrew Rist  * "License"); you may not use this file except in compliance
9*34dd1e25SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*34dd1e25SAndrew Rist  *
11*34dd1e25SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*34dd1e25SAndrew Rist  *
13*34dd1e25SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*34dd1e25SAndrew Rist  * software distributed under the License is distributed on an
15*34dd1e25SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*34dd1e25SAndrew Rist  * KIND, either express or implied.  See the License for the
17*34dd1e25SAndrew Rist  * specific language governing permissions and limitations
18*34dd1e25SAndrew Rist  * under the License.
19*34dd1e25SAndrew Rist  *
20*34dd1e25SAndrew Rist  *************************************************************/
21*34dd1e25SAndrew Rist 
22*34dd1e25SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir /*************************************************************************
25cdf0e10cSrcweir  *************************************************************************
26cdf0e10cSrcweir  *
27cdf0e10cSrcweir  * simple client application registering and using the counter component.
28cdf0e10cSrcweir  *
29cdf0e10cSrcweir  *************************************************************************
30cdf0e10cSrcweir  *************************************************************************/
31cdf0e10cSrcweir 
32cdf0e10cSrcweir #include <stdio.h>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #include <sal/main.h>
35cdf0e10cSrcweir #include <rtl/ustring.hxx>
36cdf0e10cSrcweir 
37cdf0e10cSrcweir #include <osl/diagnose.h>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx>
40cdf0e10cSrcweir 
41cdf0e10cSrcweir // generated c++ interfaces
42cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
43cdf0e10cSrcweir #include <com/sun/star/lang/XMultiComponentFactory.hpp>
44cdf0e10cSrcweir #include <com/sun/star/registry/XImplementationRegistration.hpp>
45cdf0e10cSrcweir #include <foo/XCountable.hpp>
46cdf0e10cSrcweir 
47cdf0e10cSrcweir 
48cdf0e10cSrcweir using namespace foo;
49cdf0e10cSrcweir using namespace cppu;
50cdf0e10cSrcweir using namespace com::sun::star::uno;
51cdf0e10cSrcweir using namespace com::sun::star::lang;
52cdf0e10cSrcweir using namespace com::sun::star::registry;
53cdf0e10cSrcweir 
54cdf0e10cSrcweir using namespace ::rtl;
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 
57cdf0e10cSrcweir //=======================================================================
SAL_IMPLEMENT_MAIN()58cdf0e10cSrcweir SAL_IMPLEMENT_MAIN()
59cdf0e10cSrcweir {
60cdf0e10cSrcweir     try {
61cdf0e10cSrcweir 
62cdf0e10cSrcweir 		Reference< XComponentContext > xContext(::cppu::defaultBootstrap_InitialComponentContext());
63cdf0e10cSrcweir 		OSL_ENSURE( xContext.is(), "### bootstrap failed!\n" );
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 		Reference< XMultiComponentFactory > xMgr = xContext->getServiceManager();
66cdf0e10cSrcweir 		OSL_ENSURE( xMgr.is(), "### cannot get initial service manager!" );
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 		Reference< XInterface > xx = xMgr->createInstanceWithContext(
69cdf0e10cSrcweir 			OUString::createFromAscii("foo.Counter"), xContext);
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 		OSL_ENSURE( xx.is(), "### cannot get service instance of \"foo.Counter\"!" );
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 		Reference< XCountable > xCount( xx, UNO_QUERY );
74cdf0e10cSrcweir 		OSL_ENSURE( xCount.is(), "### cannot query XCountable interface of service instance \"foo.Counter\"!" );
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 		if (xCount.is())
77cdf0e10cSrcweir 		{
78cdf0e10cSrcweir 			 xCount->setCount( 42 );
79cdf0e10cSrcweir 			 fprintf( stdout , "%d," , (int)xCount->getCount() );
80cdf0e10cSrcweir 			 fprintf( stdout , "%d," , (int)xCount->increment() );
81cdf0e10cSrcweir 			 fprintf( stdout , "%d\n" , (int)xCount->decrement() );
82cdf0e10cSrcweir 		}
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 		Reference< XComponent >::query( xContext )->dispose();
85cdf0e10cSrcweir 
86cdf0e10cSrcweir 	} catch( Exception& e) {
87cdf0e10cSrcweir 	    printf("Error: caught exception:\n       %s\n",
88cdf0e10cSrcweir                OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US).getStr());
89cdf0e10cSrcweir 		exit(1);
90cdf0e10cSrcweir 	}
91cdf0e10cSrcweir 
92cdf0e10cSrcweir 	return 0;
93cdf0e10cSrcweir }
94