summaryrefslogtreecommitdiff
path: root/patches/scsolver/scsolver-source-service-service-cxx.diff
blob: 214f46404c4b4d712ba4c6f31cba7e3be946344a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
--- /dev/null	
+++ scsolver/source/service/service.cxx	
@@ -0,0 +1,328 @@
+/*************************************************************************
+ *
+ *  The Contents of this file are made available subject to
+ *  the terms of GNU Lesser General Public License Version 2.1.
+ *
+ *
+ *    GNU Lesser General Public License Version 2.1
+ *    =============================================
+ *    Copyright 2005 by Kohei Yoshida.
+ *    1039 Kingsway Dr., Apex, NC 27502, USA
+ *
+ *    This library is free software; you can redistribute it and/or
+ *    modify it under the terms of the GNU Lesser General Public
+ *    License version 2.1, as published by the Free Software Foundation.
+ *
+ *    This library is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *    Lesser General Public License for more details.
+ *
+ *    You should have received a copy of the GNU Lesser General Public
+ *    License along with this library; if not, write to the Free Software
+ *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ *    MA  02111-1307  USA
+ *
+ ************************************************************************/
+
+
+#include <solver.hxx>
+#include <global.hxx>
+#include <dialog.hxx>
+#include <lpbuilder.hxx>
+#include <xcalc.hxx>
+#include "option.hxx"
+#include <solvemodel.hxx>
+#include <numeric/matrix.hxx>
+
+#include "cppuhelper/implementationentry.hxx"
+#include "com/sun/star/lang/XComponent.hpp"
+#include "com/sun/star/frame/XDispatch.hpp"
+
+#include <memory>
+
+using namespace std;
+
+namespace scsolver {
+
+//--------------------------------------------------------------------------
+// Component operations
+
+static uno::Sequence< rtl::OUString > SAL_CALL getSupportedServiceNames_SolverImpl();
+static rtl::OUString getImplementationName_SolverImpl();
+static Reference< uno::XInterface > SAL_CALL create_SolverImpl(
+    Reference< uno::XComponentContext > const & xContext )
+    SAL_THROW( () );
+
+
+SolverImpl::SolverImpl( Reference< uno::XComponentContext > const & xContext ) :
+	m_pResMgr( NULL ),
+	m_pDlg( NULL ), m_pCalc( new CalcInterface( xContext ) ),
+	m_pOption( new OptionData )
+{
+}
+
+SolverImpl::~SolverImpl()
+{
+	delete m_pResMgr;
+}
+
+//--------------------------------------------------------------------------
+// UNO Component Interface Methods
+
+void SolverImpl::initialize( const Sequence< Any >& aArgs ) throw( Exception )
+{
+    Debug( "SolverImpl::initialize" );
+}
+
+rtl::OUString SolverImpl::getImplementationName()
+    throw( RuntimeException )
+{
+    return rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(IMPLEMENTATION_NAME) );
+}
+
+sal_Bool SolverImpl::supportsService( rtl::OUString const & serviceName )
+    throw( RuntimeException )
+{
+    return serviceName.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM(SERVICE_NAME) );
+}
+
+Sequence< rtl::OUString > SolverImpl::getSupportedServiceNames()
+    throw( RuntimeException )
+{
+    return getSupportedServiceNames_SolverImpl();
+}
+
+Reference< frame::XDispatch > SAL_CALL SolverImpl::queryDispatch(
+    const util::URL& aURL, const ::rtl::OUString& sTargetFrameName, sal_Int32 nSearchFlags )
+    throw ( RuntimeException )
+{
+    Debug( "SolverImpl::queryDispatch" );
+    
+    Reference< frame::XDispatch > xRet;
+    if ( aURL.Protocol.compareToAscii( "scsolver.SolverImpl:" ) == 0 )
+    {
+        if ( aURL.Path.compareToAscii( "execute" ) == 0 )
+            xRet = this;
+    }
+    return xRet;
+}
+
+Sequence< Reference< frame::XDispatch > > SAL_CALL SolverImpl::queryDispatches(
+    const Sequence< frame::DispatchDescriptor >& seqDescripts )
+    throw ( RuntimeException )
+{
+    sal_Int32 nCount = seqDescripts.getLength();
+    Sequence< Reference< frame::XDispatch > > lDispatcher( nCount );
+    
+    for ( sal_Int32 i = 0; i < nCount; ++i )
+        lDispatcher[i] = queryDispatch( 
+            seqDescripts[i].FeatureURL, seqDescripts[i].FrameName, seqDescripts[i].SearchFlags );
+    
+    return lDispatcher;
+}
+
+void SAL_CALL SolverImpl::dispatch( 
+    const util::URL& aURL, const Sequence< beans::PropertyValue >& lArgs )
+    throw ( RuntimeException )
+{
+    Debug( "SolverImpl::dispatch" );
+
+    if ( aURL.Protocol.compareToAscii( "scsolver.SolverImpl:" ) == 0 )
+    {
+        if ( aURL.Path.compareToAscii( "execute" ) == 0 )
+        {
+            execute();
+        }
+    }
+}
+
+void SAL_CALL SolverImpl::addStatusListener( 
+    const Reference< frame::XStatusListener >& xControl, const util::URL& aURL )
+    throw ( RuntimeException )
+{
+    Debug( "SolverImpl::addStatusListener" );
+}
+
+void SAL_CALL SolverImpl::removeStatusListener( 
+    const Reference< frame::XStatusListener >& xControl, const util::URL& aURL )
+    throw ( RuntimeException )
+{
+    Debug( "SolverImpl::removeStatusListener" );
+}
+
+void SAL_CALL SolverImpl::dispatchWithNotification(
+    const util::URL& aURL, const Sequence< beans::PropertyValue >& lArgs,
+    const Reference< frame::XDispatchResultListener >& xDRL )
+    throw ( RuntimeException )
+{
+    Debug( "SolverImpl::dispatchWithNotification" );
+}
+
+SolverDialog* SolverImpl::getMainDialog()
+{
+	if ( m_pDlg.get() == NULL )
+		m_pDlg.reset( new SolverDialog( this ) );
+
+	return m_pDlg.get();
+}
+
+CalcInterface* SolverImpl::getCalcInterface() const
+{
+	return m_pCalc.get();
+}
+
+OptionData* SolverImpl::getOptionData() const
+{
+	return m_pOption.get();
+}
+
+void SolverImpl::setTitle( const ::rtl::OUString& aTitle )
+		throw (uno::RuntimeException)
+{
+    Debug( "SolverImpl::setTitle - unimplemented ..." );
+}
+
+sal_Int16 SolverImpl::execute()
+		throw (::com::sun::star::uno::RuntimeException)
+{
+    Debug( "SolverImpl::executeDialog" );
+	
+	getMainDialog()->setVisible( true );
+
+	return 0;
+}
+
+sal_Bool SolverImpl::solveModel()
+{	
+	std::auto_ptr<SolveModel> p( new SolveModel( this ) );
+	try
+	{
+		p->solve();
+	}
+	catch( const RuntimeError& e )
+	{
+		getMainDialog()->showSolveError( e.getMessage() );
+	}
+
+	if ( p->isSolved() )
+	{
+		Debug( "solution available" );
+		return true;
+	}
+	
+	return false;
+}
+
+void SolverImpl::initLocale()
+{
+	rtl::OString aModName( "scsolver" );
+	aModName += rtl::OString::valueOf( sal_Int32( SUPD ) );
+
+	m_pResMgr = ResMgr::CreateResMgr( aModName.getStr(), m_eLocale );
+}
+
+ResMgr* SolverImpl::getResMgr()
+{
+	if( !m_pResMgr )
+		initLocale();
+	return m_pResMgr;
+}
+
+rtl::OUString SolverImpl::getResStr( int resid )
+{
+	rtl::OUString sStr = String( ResId( resid, getResMgr() ) );
+	return sStr;
+}
+
+// XLocalizable
+
+void SAL_CALL SolverImpl::setLocale( const lang::Locale& eLocale )
+	throw(::com::sun::star::uno::RuntimeException)
+{
+	m_eLocale = eLocale;
+	initLocale();
+}
+
+lang::Locale SAL_CALL SolverImpl::getLocale()
+	throw(::com::sun::star::uno::RuntimeException)
+{
+	return m_eLocale;
+}
+
+//---------------------------------------------------------------------------
+// Component operations
+
+static Sequence< rtl::OUString > getSupportedServiceNames_SolverImpl()
+{
+    static Sequence < rtl::OUString > *pNames = 0;
+    if( !pNames )
+    {
+        static Sequence< rtl::OUString > seqNames(1);
+        seqNames.getArray()[0] = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(SERVICE_NAME));
+        pNames = &seqNames;
+    }
+    return *pNames;
+}
+
+static rtl::OUString getImplementationName_SolverImpl()
+{
+    static rtl::OUString *pImplName = 0;
+    if( !pImplName )
+    {
+        static rtl::OUString implName(
+            RTL_CONSTASCII_USTRINGPARAM(IMPLEMENTATION_NAME));
+        pImplName = &implName;
+    }
+    return *pImplName;
+}
+
+static Reference< uno::XInterface > SAL_CALL create_SolverImpl(
+    Reference< uno::XComponentContext > const & xContext )
+    SAL_THROW( () )
+{
+	Debug ("Create Solver");
+    return static_cast< lang::XTypeProvider * >( new SolverImpl( xContext ) );
+}
+
+
+static struct ::cppu::ImplementationEntry s_component_entries [] =
+{
+    {
+        create_SolverImpl, getImplementationName_SolverImpl,
+        getSupportedServiceNames_SolverImpl, ::cppu::createSingleComponentFactory,
+        0, 0
+    },
+    { 0, 0, 0, 0, 0, 0 }
+};
+
+   
+}
+
+
+//------------------------------------------------------------------------------
+// Shared library symbol exports
+
+extern "C"
+{
+    void SAL_DLLPUBLIC_EXPORT component_getImplementationEnvironment(
+        sal_Char const ** ppEnvTypeName, uno_Environment ** ppEnv )
+    {
+        *ppEnvTypeName = CPPU_CURRENT_LANGUAGE_BINDING_NAME;
+    }
+    
+    sal_Bool SAL_DLLPUBLIC_EXPORT component_writeInfo(
+        lang::XMultiServiceFactory * xMgr, registry::XRegistryKey * xRegistry )
+    {		
+        return ::cppu::component_writeInfoHelper(
+            xMgr, xRegistry, ::scsolver::s_component_entries );
+    }
+
+    void SAL_DLLPUBLIC_EXPORT *component_getFactory(
+        sal_Char const * implName, lang::XMultiServiceFactory * xMgr,
+        registry::XRegistryKey * xRegistry )
+    {
+        return ::cppu::component_getFactoryHelper(
+            implName, xMgr, xRegistry, ::scsolver::s_component_entries );
+    }
+}