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