tdf#154285 Check upper bound of arguments in SbRtl_Minute function
[LibreOffice.git] / odk / examples / DevelopersGuide / Components / CppComponent / service1_impl.cxx
blobbe2055e9ce998f19f294e3ee521926eb744b97d1
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
5 * the BSD license.
7 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * All rights reserved.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of Sun Microsystems, Inc. nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
29 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
30 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
31 * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
32 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *************************************************************************/
36 #include <osl/interlck.h>
37 #include <osl/mutex.hxx>
38 #include <cppuhelper/factory.hxx>
39 #include <cppuhelper/supportsservice.hxx>
41 #include <com/sun/star/lang/XServiceInfo.hpp>
42 #include <com/sun/star/lang/XTypeProvider.hpp>
43 #include <mymodule/XSomething.hpp>
46 using namespace ::rtl; // for OUString
47 using namespace ::com::sun::star; // for odk interfaces
48 using namespace ::com::sun::star::uno; // for basic types
50 namespace my_sc_impl
53 Sequence< OUString > SAL_CALL getSupportedServiceNames_MyService1Impl()
55 Sequence< OUString > names(1);
56 names[0] = "mymodule.MyService1";
57 return names;
60 OUString SAL_CALL getImplementationName_MyService1Impl()
62 return OUString("mymodule.my_sc_implementation.MyService1");
66 class MyService1Impl
67 : public ::mymodule::XSomething
68 , public lang::XServiceInfo
69 , public lang::XTypeProvider
71 oslInterlockedCount m_refcount;
72 OUString m_sData;
73 // it's good practice to store the context for further use when you use
74 // other UNO API's in your implementation
75 Reference< XComponentContext > m_xContext;
76 public:
77 inline MyService1Impl(Reference< XComponentContext > const & xContext) SAL_NOEXCEPT
78 : m_refcount( 0 ),
79 m_xContext(xContext)
82 virtual ~MyService1Impl() {}
84 // XInterface
85 virtual Any SAL_CALL queryInterface( Type const & type );
86 virtual void SAL_CALL acquire() SAL_NOEXCEPT;
87 virtual void SAL_CALL release() SAL_NOEXCEPT;
88 // XTypeProvider
89 virtual Sequence< Type > SAL_CALL getTypes();
90 virtual Sequence< sal_Int8 > SAL_CALL getImplementationId();
91 // XSomething
92 virtual OUString SAL_CALL methodOne( OUString const & str );
93 virtual OUString SAL_CALL methodTwo( );
94 // XServiceInfo
95 virtual OUString SAL_CALL getImplementationName();
96 virtual sal_Bool SAL_CALL supportsService( OUString const & serviceName );
97 virtual Sequence< OUString > SAL_CALL getSupportedServiceNames();
100 // XInterface implementation
101 Any MyService1Impl::queryInterface( Type const & type )
103 if (type.equals(::cppu::UnoType<XInterface>::get()))
105 // return XInterface interface
106 // (resolve ambiguity by casting to lang::XTypeProvider)
107 Reference< XInterface > x(
108 static_cast< lang::XTypeProvider * >( this ) );
109 return makeAny( x );
111 if (type.equals(::cppu::UnoType<lang::XTypeProvider>::get()))
113 // return XInterface interface
114 Reference< XInterface > x(
115 static_cast< lang::XTypeProvider * >( this ) );
116 return makeAny( x );
118 if (type.equals(::cppu::UnoType<lang::XServiceInfo>::get()))
120 // return XServiceInfo interface
121 Reference< lang::XServiceInfo > x(
122 static_cast< lang::XServiceInfo * >( this ) );
123 return makeAny( x );
125 if (type.equals(::cppu::UnoType<mymodule::XSomething>::get()))
127 // return sample interface
128 Reference< ::mymodule::XSomething > x(
129 static_cast< ::mymodule::XSomething * >( this ) );
130 return makeAny( x );
132 // querying for unsupported type
133 return Any();
136 void MyService1Impl::acquire() SAL_NOEXCEPT
138 // thread-safe incrementation of reference count
139 ::osl_atomic_increment( &m_refcount );
142 void MyService1Impl::release() SAL_NOEXCEPT
144 // thread-safe decrementation of reference count
145 if (0 == ::osl_atomic_decrement( &m_refcount ))
147 delete this; // shutdown this object
151 // XTypeProvider implementation
152 Sequence< Type > MyService1Impl::getTypes()
154 Sequence< Type > seq( 3 );
155 seq[ 0 ] = ::cppu::UnoType<lang::XTypeProvider>::get();
156 seq[ 1 ] = ::cppu::UnoType<lang::XServiceInfo>::get();
157 seq[ 2 ] = ::cppu::UnoType<mymodule::XSomething>::get();
158 return seq;
161 Sequence< sal_Int8 > MyService1Impl::getImplementationId()
163 return css::uno::Sequence<sal_Int8>();
166 // XSomething implementation
167 OUString MyService1Impl::methodOne( OUString const & str )
169 m_sData = str;
170 return OUString( "called methodOne() of MyService1 implementation: " ) + m_sData;
173 OUString MyService1Impl::methodTwo( )
175 return OUString( "called methodTwo() of MyService1 implementation: " ) + m_sData;
178 // XServiceInfo implementation
179 OUString MyService1Impl::getImplementationName()
181 // unique implementation name
182 return OUString("mymodule.my_sc_implementation.MyService1");
184 sal_Bool MyService1Impl::supportsService( OUString const & serviceName )
186 return cppu::supportsService(this, serviceName);
188 Sequence< OUString > MyService1Impl::getSupportedServiceNames()
190 // this object only supports one service
191 OUString serviceName("mymodule.MyService1");
192 return Sequence< OUString >( &serviceName, 1 );
195 Reference< XInterface > SAL_CALL create_MyService1Impl(
196 Reference< XComponentContext > const & xContext )
198 return static_cast< lang::XTypeProvider * >( new MyService1Impl( xContext) );
201 // forward decl: implemented in service2_impl.cxx
202 Reference< XInterface > SAL_CALL create_MyService2Impl(
203 Reference< XComponentContext > const & );
207 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */