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