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 #include <stdio.h>
25cdf0e10cSrcweir #include <sal/main.h>
26cdf0e10cSrcweir #include <cppuhelper/bootstrap.hxx>
27cdf0e10cSrcweir #include <com/sun/star/bridge/XUnoUrlResolver.hpp>
28cdf0e10cSrcweir #include <com/sun/star/frame/XComponentLoader.hpp>
29cdf0e10cSrcweir #include <my_module/MyService1.hpp>
30cdf0e10cSrcweir #include <my_module/MyService2.hpp>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir using namespace rtl;
33cdf0e10cSrcweir using namespace com::sun::star::uno;
34cdf0e10cSrcweir //namespace cssuno = ::com::sun::star::uno;
35cdf0e10cSrcweir using namespace com::sun::star::lang;
36cdf0e10cSrcweir using namespace com::sun::star::frame;
37cdf0e10cSrcweir 
SAL_IMPLEMENT_MAIN()38cdf0e10cSrcweir SAL_IMPLEMENT_MAIN()
39cdf0e10cSrcweir {
40cdf0e10cSrcweir     try
41cdf0e10cSrcweir     {
42cdf0e10cSrcweir         // get the remote office component context
43cdf0e10cSrcweir         Reference< XComponentContext > xContext( ::cppu::bootstrap() );
44cdf0e10cSrcweir         fprintf(stdout, "\nconnected to a running office...\n");
45cdf0e10cSrcweir 
46cdf0e10cSrcweir         // create a new instance of MyService1
47cdf0e10cSrcweir         Reference<my_module::XSomething> xSomething =
48cdf0e10cSrcweir             my_module::MyService1::create(xContext);
49cdf0e10cSrcweir 
50cdf0e10cSrcweir         // call methodOne and print the return value on stdout
51cdf0e10cSrcweir         OUString s = xSomething->methodOne(OUString(RTL_CONSTASCII_USTRINGPARAM("Hello World!")));
52cdf0e10cSrcweir         fprintf(stdout,"\nCreate new instance of MyService1\nCall of XSomething.methOne at MyService1 = %s", OUStringToOString( s, RTL_TEXTENCODING_ASCII_US ).getStr());
53cdf0e10cSrcweir 
54cdf0e10cSrcweir         // create a new instance of MyService2 with the specified string argument
55cdf0e10cSrcweir         xSomething = my_module::MyService2::create(xContext, OUString(RTL_CONSTASCII_USTRINGPARAM("Hello My World!")));
56cdf0e10cSrcweir 
57cdf0e10cSrcweir         // call methodTwo and print the return value of methodTwo
58cdf0e10cSrcweir         s = xSomething->methodTwo();
59cdf0e10cSrcweir         fprintf(stdout, "\n\nCreate new instance of MyService2 with argument\nCall of XSomething.methTwo at MyService2 = %s", OUStringToOString( s, RTL_TEXTENCODING_ASCII_US ).getStr());
60cdf0e10cSrcweir 
61cdf0e10cSrcweir         fprintf(stdout, "\n\nPlease press 'return' to finish the example!\n");
62cdf0e10cSrcweir         getchar();
63cdf0e10cSrcweir     }
64cdf0e10cSrcweir     catch ( ::cppu::BootstrapException & e )
65cdf0e10cSrcweir     {
66cdf0e10cSrcweir         fprintf(stderr, "\ncaught BootstrapException: %s\n",
67cdf0e10cSrcweir                 OUStringToOString( e.getMessage(), RTL_TEXTENCODING_ASCII_US ).getStr());
68cdf0e10cSrcweir         return 1;
69cdf0e10cSrcweir     }
70cdf0e10cSrcweir     catch ( Exception & e )
71cdf0e10cSrcweir     {
72cdf0e10cSrcweir         fprintf(stderr, "\ncaught UNO exception: %s\n",
73cdf0e10cSrcweir                 OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).getStr());
74cdf0e10cSrcweir         return 1;
75cdf0e10cSrcweir     }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     return 0;
78cdf0e10cSrcweir }
79