1 /************************************************************************* 2 * 3 * The Contents of this file are made available subject to the terms of 4 * the BSD license. 5 * 6 * Copyright 2000, 2010 Oracle and/or its affiliates. 7 * All rights reserved. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its 18 * contributors may be used to endorse or promote products derived 19 * from this software without specific prior written permission. 20 * 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS 28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 29 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR 30 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE 31 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * 33 *************************************************************************/ 34 35 #include <stdio.h> 36 #include <sal/main.h> 37 #include <cppuhelper/bootstrap.hxx> 38 #include <com/sun/star/bridge/XUnoUrlResolver.hpp> 39 #include <com/sun/star/frame/XComponentLoader.hpp> 40 #include <my_module/MyService1.hpp> 41 #include <my_module/MyService2.hpp> 42 43 using namespace rtl; 44 using namespace com::sun::star::uno; 45 //namespace cssuno = ::com::sun::star::uno; 46 using namespace com::sun::star::lang; 47 using namespace com::sun::star::frame; 48 49 SAL_IMPLEMENT_MAIN() 50 { 51 try 52 { 53 // get the remote office component context 54 Reference< XComponentContext > xContext( ::cppu::bootstrap() ); 55 fprintf(stdout, "\nconnected to a running office...\n"); 56 57 // create a new instance of MyService1 58 Reference<my_module::XSomething> xSomething = 59 my_module::MyService1::create(xContext); 60 61 // call methodOne and print the return value on stdout 62 OUString s = xSomething->methodOne(OUString(RTL_CONSTASCII_USTRINGPARAM("Hello World!"))); 63 fprintf(stdout,"\nCreate new instance of MyService1\nCall of XSomething.methOne at MyService1 = %s", OUStringToOString( s, RTL_TEXTENCODING_ASCII_US ).getStr()); 64 65 // create a new instance of MyService2 with the specified string argument 66 xSomething = my_module::MyService2::create(xContext, OUString(RTL_CONSTASCII_USTRINGPARAM("Hello My World!"))); 67 68 // call methodTwo and print the return value of methodTwo 69 s = xSomething->methodTwo(); 70 fprintf(stdout, "\n\nCreate new instance of MyService2 with argument\nCall of XSomething.methTwo at MyService2 = %s", OUStringToOString( s, RTL_TEXTENCODING_ASCII_US ).getStr()); 71 72 fprintf(stdout, "\n\nPlease press 'return' to finish the example!\n"); 73 getchar(); 74 } 75 catch ( ::cppu::BootstrapException & e ) 76 { 77 fprintf(stderr, "\ncaught BootstrapException: %s\n", 78 OUStringToOString( e.getMessage(), RTL_TEXTENCODING_ASCII_US ).getStr()); 79 return 1; 80 } 81 catch ( Exception & e ) 82 { 83 fprintf(stderr, "\ncaught UNO exception: %s\n", 84 OUStringToOString( e.Message, RTL_TEXTENCODING_ASCII_US ).getStr()); 85 return 1; 86 } 87 88 return 0; 89 } 90