Files
libreoffice/extensions/workben/pythontest.cxx

541 lines
20 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes (at least) relevant parts of: linecap: Reintegrating finished LineCap feature Patch contributed by Regina Henschel http://svn.apache.org/viewvc?view=revision&revision=1232507 Patches contributed by Sven Jacobi impress212: #i81610# fixed animation export http://svn.apache.org/viewvc?view=revision&revision=1167620 impress212: drawinglayer gbuild environment changes http://svn.apache.org/viewvc?view=revision&revision=1167627 http://svn.apache.org/viewvc?view=revision&revision=1167628 impress212: DffPropSet -> minor code improvements, removing table http://svn.apache.org/viewvc?view=revision&revision=1167634 impress212: #158494# fixed excel import (text rotation) http://svn.apache.org/viewvc?view=revision&revision=1167638 Patches contributed by Armin Le Grand Svg: Reintegrated Svg replacement from /branches/alg/svgreplavement http://svn.apache.org/viewvc?view=revision&revision=1220836 #118728# changed indentifying definitions for Svg file detection http://svn.apache.org/viewvc?view=revision&revision=1229961 #118838# LineGeometry creation for complicated cases optimized to create single Polygons http://svn.apache.org/viewvc?view=revision&revision=1236232 #119176# corrected file type detection for SVG for svg files without xml header http://svn.apache.org/viewvc?view=revision&revision=1309445 #118728# Extended Svg file detection http://svn.apache.org/viewvc?view=revision&revision=1230531 #118529# solve break converters and convert commands for OLEs and images http://svn.apache.org/viewvc?view=revision&revision=1186168 svg: added WaE changes from branch svgreplacement to trunc http://svn.apache.org/viewvc?view=revision&revision=1222974 svg: corrected missing member initialization http://svn.apache.org/viewvc?view=revision&revision=1226134 fix for #118525#: Using primitives for chart sub-geometry visualisation http://svn.apache.org/viewvc?view=revision&revision=1226879 #118898# Adapted ImpGraphic::ImplGetBitmap to correctly convert metafiles to bitmapEx ... http://svn.apache.org/viewvc?view=revision&revision=1293316 fix for #118525#: removed no longer used variable maOriginalMapMode, one more exception eliminated http://svn.apache.org/viewvc?view=revision&revision=1227097 #16758# Added buffering to the VDev usages of the VclProcessor2D derivates... http://svn.apache.org/viewvc?view=revision&revision=1229521 #116758# Secured VDev buffer device to Vcl deinit http://svn.apache.org/viewvc?view=revision&revision=1230574 #116758# added remembering allocated VDevs for VDevBuffer to be able to also delete these when vcl goes down; it should never happen, but You never know http://svn.apache.org/viewvc?view=revision&revision=1230927 #118730# Changed SvgClipPathNode to use MaskPrimitive2D for primitive representation instead of TransparencePrimitive2D http://svn.apache.org/viewvc?view=revision&revision=1231198 #118822# secured 3D geometry creation (slices) by subdividing the 2D source polyPolygon early http://svn.apache.org/viewvc?view=revision&revision=1234749 #118829# enhanced Svg gradient quality, obstacles avoided http://svn.apache.org/viewvc?view=revision&revision=1235361 #118834# Unified usage of TextBreakupHelper as single tooling class for i18n text primitive breakup http://svn.apache.org/viewvc?view=revision&revision=1236110 #118853# added square pixel size limit to conversion of TransparencePrimitive2D to Metafile action http://svn.apache.org/viewvc?view=revision&revision=1237656 #118824# coreccted mirroring and boundrect when the graphicmanager is used for bitmap output http://svn.apache.org/viewvc?view=revision&revision=1240097 #115092# Corrected VclProcessor2D::RenderPolygonStrokePrimitive2D for various optimization scenarios http://svn.apache.org/viewvc?view=revision&revision=1241434 #118783# Corrected errors in ID strings, corrected Svg line/fill export, corrected polygon close state http://svn.apache.org/viewvc?view=revision&revision=1232006 #118796# corrected null-pointer usage in SVG text exporter http://svn.apache.org/viewvc?view=revision&revision=1240262 #118729# Use GraphicStreamUrl and GraphicUrl to allow multi image import with linked graphics, too http://svn.apache.org/viewvc?view=revision&revision=1229962 #118898# corrected error in GDIMetaFile::GetBoundRect in handling MetaFloatTransparentAction http://svn.apache.org/viewvc?view=revision&revision=1293349 #118855# Corrected handling of possibly created empty clipRegions after PolyPolygon clipping http://svn.apache.org/viewvc?view=revision&revision=1237725 #115962# Better (but not yet optimal, see comments in task) handling of MetaFloatTransparentAction in PDF export http://svn.apache.org/viewvc?view=revision&revision=1241078 IP clearance: #118466# This patch removes librsvg, libcroco, libgsf, ... http://svn.apache.org/viewvc?view=revision&revision=1200879 118779# Added svg content streaming in/out to ImpGraphic stream operators http://svn.apache.org/viewvc?view=revision&revision=1231908 linecap: correctons for WaE and mac drawing http://svn.apache.org/viewvc?view=revision&revision=1232793 svg: uses current system Dpi for Svg replacement image creation http://svn.apache.org/viewvc?view=revision&revision=1233948 Patches contributed by Mathias Bauer (and others) gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394326 http://svn.apache.org/viewvc?view=revision&revision=1396797 http://svn.apache.org/viewvc?view=revision&revision=1397315 http://svn.apache.org/viewvc?view=revision&revision=1394326 Remove duplicate header includes. cws mba34issues01: #i117720#: convert assertion into warning http://svn.apache.org/viewvc?view=revision&revision=1172352 118485 - Styles for OLEs are not saved. Submitted by Armin Le Grand. http://svn.apache.org/viewvc?view=revision&revision=1182166 cws mba34issues01: #i117714#: remove assertion http://svn.apache.org/viewvc?view=revision&revision=1172357 Patch contributed by Jurgen Schmidt add some additional checks to ensure proper reading operations http://svn.apache.org/viewvc?view=revision&revision=1209022 mostly prefer our stream / bounds checking work. Patches contributed by Herbert Duerr #i118816# add clarifying comment regarding Font::*Color*() methods http://svn.apache.org/viewvc?view=revision&revision=1233833 extend macro->string handling for empty strings http://svn.apache.org/viewvc?view=revision&revision=1175801 avoid magic constants for SALCOLOR_NONE http://svn.apache.org/viewvc?view=revision&revision=1177543 initialize slant properly in ImplFontMetricData constructor (author=iorsh) http://svn.apache.org/viewvc?view=revision&revision=1177551 #i118675# make check for extension updates more stable http://svn.apache.org/viewvc?view=revision&revision=1214797 #a118617# remove VBasicEventListener.dll binary There are no known users depending on its CLSID http://svn.apache.org/viewvc?view=revision&revision=1203697 Patches contributed by Ariel Constenla-Haile Fix build breaker on Linux/gcc http://svn.apache.org/viewvc?view=revision&revision=1221104 Fix crash when trying to instantiate css.graphic.GraphicRasterizer_RSVG http://svn.apache.org/viewvc?view=revision&revision=1215559 Patches contributed by Oliver-Rainer Wittmann sw34bf06: #i117962# - method <SwFlyFrm::IsPaint(..)> - consider instances of <SwFlyDrawObj> http://svn.apache.org/viewvc?view=revision&revision=1172120 sw34bf06: #i117783# - Writer's implementation of XPagePrintable - apply print settings to new printing routines http://svn.apache.org/viewvc?view=revision&revision=1172115 gnumake4 work variously from Hans-Joachim Lankenau http://svn.apache.org/viewvc?view=revision&revision=1397315 http://svn.apache.org/viewvc?view=revision&revision=1396797 http://svn.apache.org/viewvc?view=revision&revision=1396782 http://svn.apache.org/viewvc?view=revision&revision=1394707 plus some amount of re-splitting of legacy headers. Patch contributed by Pavel Janik WaE: Remove unused variables. http://svn.apache.org/viewvc?view=revision&revision=1230697 Patches contributed by Takashi Ono mingwport35: i#117795: MinGW port fix for vcl2gnumake http://svn.apache.org/viewvc?view=revision&revision=1172091 mingwport35: i#117795: MinGW port fix for vcl2gnumake http://svn.apache.org/viewvc?view=revision&revision=1172091 Patch contributed by Christian Lippka impress212: #i98044# re enable Text menu for outline and title shapes http://svn.apache.org/viewvc?view=revision&revision=1167639 Patch contributed by Andre Fischer 118674: Made category B code optional and disabled by default. http://svn.apache.org/viewvc?view=revision&revision=1215131 118881: Ignore empty paragraphs after bullets. http://svn.apache.org/viewvc?view=revision&revision=1296205 Patches contributed by Philipp Lohmann ooo340fixes: #i117780# use rtl allocator http://svn.apache.org/viewvc?view=revision&revision=1172087 ooo34gsl02: #i117807# fix an off by one error (index actually inside the pfb section header) http://svn.apache.org/viewvc?view=revision&revision=1167576 various cleanups, related compilation fixes, warning cleanups, re-working of obsolete stl template pieces to use boost instead, changed string classes, re-adapt KDE about data, about dialog, fixing warnings, and other fixes & improvements. Disable svg import / render for about/ branding code-paths for now. Restore full icon theme set. Remove OS/2 conditionals and sources. Remove conflicting gtk/full-screen monitors support. Retain existing svg rasterizer files - temporarily disabled. Standardize stringificaiton and fixup dllpostfix issues. Rename SvgGradientHelper::== to equalTo to avoid overloading issues. Use the flat GdiPlus API for LineCaps calls.
2012-10-09 12:22:23 +01:00
/*
* This file is part of the LibreOffice project.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*
* This file incorporates work covered by the following license notice:
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed
* with this work for additional information regarding copyright
* ownership. The ASF licenses this file to you under the Apache
* License, Version 2.0 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
2000-09-18 15:18:56 +00:00
2000-09-18 15:18:56 +00:00
#include <stdio.h>
#include <stardiv/uno/repos/implementationregistration.hxx>
#include <stardiv/uno/script/script.hxx>
#include <stardiv/uno/beans/exactname.hxx>
#include <rtl/ustring.hxx>
2010-10-10 19:46:46 -05:00
#include <osl/diagnose.h>
2000-09-18 15:18:56 +00:00
#include <usr/services.hxx>
#include <vcl/svapp.hxx>
#include <usr/ustring.hxx>
#include <usr/weak.hxx>
2010-10-11 16:11:20 -05:00
#include <osl/conditn.hxx>
2000-09-18 15:18:56 +00:00
using namespace usr;
2011-02-26 01:14:41 +01:00
using ::rtl::StringToOUString;
2000-09-18 15:18:56 +00:00
#define PCHAR_TO_USTRING(x) StringToOUString(String(x),CHARSET_SYSTEM)
class NullEngineListenerRef : public XEngineListenerRef
{
virtual void interrupt(const InterruptEngineEvent& Evt) THROWS( (UsrSystemException) ) {}
virtual void running(const EventObject& Evt) THROWS( (UsrSystemException) ) {}
virtual void finished(const FinishEngineEvent& Evt) THROWS( (UsrSystemException) ) {}
};
#define USTRING_TO_PCHAR(x) OUStringToString(x , CHARSET_DONTKNOW ).GetCharStr()
class CmdDebugger :
public XEngineListener,
public OWeakObject
{
public:
CmdDebugger()
{
m_pDebuggingRef = 0;
m_pEngineRef = 0;
m_bIsTerminating = FALSE;
m_bIsRunning = FALSE;
}
CmdDebugger( XDebuggingRef *p, XEngineRef *pEngine , XInvokationRef *pInvokation)
{
attach( p , pEngine , pInvokation );
}
~CmdDebugger()
{
if( m_pDebuggingRef ) {
detach();
}
}
BOOL queryInterface( Uik aUik, XInterfaceRef & rOut );
void acquire() { OWeakObject::acquire(); }
void release() { OWeakObject::release(); }
void* getImplementation(Reflection *p) { return OWeakObject::getImplementation(p); }
void attach( XDebuggingRef *p , XEngineRef *pEngine , XInvokationRef *pInvokation )
{
m_pDebuggingRef = p;
m_pEngineRef = pEngine;
m_pInvokationRef = pInvokation;
m_bIsRunning = FALSE;
m_bIsTerminating = FALSE;
}
void detach( );
virtual void disposing( const EventObject &o )
{
if( m_pDebuggingRef ) {
detach();
}
}
virtual void interrupt(const InterruptEngineEvent& Evt) THROWS( (UsrSystemException) )
{
if( m_pDebuggingRef && ! m_bIsTerminating ) {
(*m_pDebuggingRef)->stop();
fprintf( stderr, "%s\n" , USTRING_TO_PCHAR(Evt.ErrorMessage ) );
fprintf( stderr, "%s.%s (%d)\n", USTRING_TO_PCHAR(Evt.SourceCode),
USTRING_TO_PCHAR(Evt.Name ),
Evt.StartLine );
m_aDebugCondition.set();
m_bIsRunning = TRUE;
}
}
virtual void running(const EventObject& Evt) THROWS( (UsrSystemException) )
{
if( m_pDebuggingRef && ! m_bIsTerminating ) {
(*m_pDebuggingRef)->stop();
m_aDebugCondition.set();
m_bIsRunning = TRUE;
fprintf( stderr, "%s\n" , "Script starts\n" );
}
}
virtual void finished(const FinishEngineEvent& Evt) THROWS( (UsrSystemException) )
{
if( m_pDebuggingRef && ! m_bIsTerminating ) {
m_aDebugCondition.set();
m_bIsRunning = FALSE;
fprintf( stderr , "%s\n", USTRING_TO_PCHAR( Evt.ErrorMessage ) );
}
}
void dumpIntrospectionToStream( const XIntrospectionAccessRef &, FILE *f );
void dumpVarToStream( const char *pcName, const UsrAny &any, FILE *f );
void cmdLine();
protected:
2010-10-11 16:11:20 -05:00
osl::Condition m_aDebugCondition;
2000-09-18 15:18:56 +00:00
XDebuggingRef *m_pDebuggingRef;
XEngineRef *m_pEngineRef;
XInvokationRef *m_pInvokationRef;
int m_bIsRunning;
int m_bIsTerminating; // The listeners ignore everything when set
};
void CmdDebugger::cmdLine()
{
char pcLine[80];
fprintf( stderr, "entering debugger\n" );
while( TRUE ) {
m_aDebugCondition.wait();
fprintf( stderr , "(debug %d) : " , m_bIsRunning );
fflush( stderr);
fgets( pcLine , 79 , stdin );
if( strlen( pcLine) ) pcLine[strlen(pcLine)-1] =0;
String sLine( pcLine );
if( ! strcmp( pcLine , "g" ) ) {
if( m_bIsRunning ) {
m_aDebugCondition.reset();
(*m_pDebuggingRef)->doContinue();
}
else fprintf( stderr,"no script running !\n" );
}
else if( ! strcmp( pcLine , "s" ) ) {
if( m_bIsRunning ) {
m_aDebugCondition.reset();
(*m_pDebuggingRef)->stepOver();
}
else fprintf(stderr, "no script running !\n" );
}
else if( ! strcmp( pcLine , "so" ) ) {
if( m_bIsRunning ) {
m_aDebugCondition.reset();
(*m_pDebuggingRef)->stepOut();
}
else fprintf(stderr, "no script running !\n" );
}
else if( ! strcmp( pcLine , "si" ) ) {
if( m_bIsRunning ) {
m_aDebugCondition.reset();
(*m_pDebuggingRef)->stepIn();
}
else fprintf(stderr, "no script running !\n" );
}
else if( ! strncmp( pcLine , "sbp" , 3 ) ){
if( m_bIsRunning ) {
(*m_pDebuggingRef)->setBreakPoint( UString( L"<string>" ),
atoi(&pcLine[3]) , TRUE );
}
}
else if( ! strncmp( pcLine , "rbp" , 3 ) ){
if( m_bIsRunning ) {
(*m_pDebuggingRef)->setBreakPoint( UString( L"<string>" ),
atoi(&pcLine[3]) , FALSE );
}
}
else if( ! strncmp( pcLine , "dv " , 3 ) ) {
if( m_bIsRunning ) {
int nCallstack = 0;
if( sLine.GetQuotedTokenCount( String("''"),' ' ) == 3 ) {
nCallstack = atoi( sLine.GetQuotedToken( 3 , String("''"), ' ' ).GetCharStr() );
}
UString str = (*m_pDebuggingRef)->dumpVariable(
PCHAR_TO_USTRING( &pcLine[3]),nCallstack);
fprintf( stderr, "%s\n" , USTRING_TO_PCHAR( str ) );
}
}
else if( ! strncmp( pcLine , "sv " , 3 ) ) {
int nCallstack = 0;
if( sLine.GetQuotedTokenCount( String("''"),' ' ) == 3 ) {
nCallstack = atoi( sLine.GetQuotedToken( 3 , String("''"), ' ' ).GetCharStr() );
}
(*m_pDebuggingRef)->setVariable(
StringToOUString( sLine.GetQuotedToken( 1 , String("''"), ' ' ), CHARSET_SYSTEM ),
StringToOUString( sLine.GetQuotedToken( 2 , String("''"), ' ' ), CHARSET_SYSTEM ),
nCallstack );
}
else if( ! strncmp( pcLine , "ci" ,2 ) ) {
if( m_bIsRunning ) {
UString *aUString ;
ContextInformation ci = (*m_pDebuggingRef)->getContextInformation(atoi(&pcLine[2]));
int i,iMax;
fprintf( stderr, "File %s (%d)\n", USTRING_TO_PCHAR(ci.Name),
ci.StartLine );
fprintf( stderr, "Available variables : \n" );
aUString = ci.LocalVariableNames.getArray();
iMax = ci.LocalVariableNames.getLen();
for( i = 0 ; i < iMax ; i++ ) {
fprintf( stderr, " %s\n" , USTRING_TO_PCHAR( aUString[i]) );
}
}
}
else if ( !strcmp( pcLine , "d" ) ) {
if( m_bIsRunning ) {
UString * aUString ;
Sequence<UString> seq = (*m_pDebuggingRef)->getStackTrace();
aUString = seq.getArray();
int iMax = seq.getLen();
for( int i = 0; i < iMax ; i++ ) {
fprintf( stderr , "%s\n" , USTRING_TO_PCHAR( aUString[i] ) );
}
}
}
else if( !strcmp( pcLine , "c" ) ) {
if( m_bIsRunning ) {
(*m_pEngineRef)->cancel();
m_aDebugCondition.reset();
}
else fprintf( stderr,"no script running !\n" );
}
else if( !strcmp( pcLine , "q" ) ) {
if( m_bIsRunning ) {
m_aDebugCondition.reset();
(*m_pEngineRef)->cancel();
}
else {
m_bIsTerminating = TRUE;
fprintf(stderr, "Debugger terminates\n" );
break;
}
}
else if( ! strcmp( pcLine , "id" ) ) {
XIntrospectionAccessRef ref = (*m_pInvokationRef)->getIntrospection();
dumpIntrospectionToStream( ref , stderr );
}
else if( ! strncmp( pcLine , "idv" , 3) ) {
try {
2000-09-18 15:18:56 +00:00
UsrAny any = (*m_pInvokationRef)->getValue( PCHAR_TO_USTRING( &(pcLine[4]) ) );
dumpVarToStream( &(pcLine[4]) , any , stderr );
}
catch(UnknownPropertyException& e ) {
2000-09-18 15:18:56 +00:00
fprintf( stderr, "UnknownPropertyException\n" );
}
catch(IllegalArgumentException& e ) {
2000-09-18 15:18:56 +00:00
fprintf( stderr, "IllegalArgumentException\n" );
}
}
else if( !strcmp( pcLine , "t" ) ) {
}
else if( !strcmp( pcLine , "h" ) ) {
fprintf( stderr , "\nvalid commands :\n"
"Go : g\n"
"StepOver : s\n"
"StepIn : si\n"
"StepOut : so\n"
"Set BreakPoint : sbp Line [ModuleName]\n"
"Remove BreakPoint : rbp [Line] [ModuleName]\n"
"via XDebugging Interface :\n"
" dump Variable : dv varname [CallStack]\n"
" set Variable : sv varname value [CallStack]\n"
"globals via XInvokation Interface :\n"
" dump Global vars : id\n"
" dump Variable : idv varname\n"
" set Variable : isv varname value\n"
"ContextInformation : ci\n"
"Dump callstack : d\n"
"Cancel : c (stops actual script)\n"
"Quit : q (exits debugger)\n"
);
}
else if( ! strlen( pcLine ) ) {
}
else {
fprintf( stderr , "unknown command %s\n" , pcLine );
}
}
}
void CmdDebugger::dumpIntrospectionToStream( const XIntrospectionAccessRef &ref, FILE *f )
{
int i,iMax;
fprintf( stderr, "Callable Attributes (Methods) :\n" );
Sequence<XIdlMethodRef> seq = ref->getMethods( 0 );
iMax = seq.getLen();
XIdlMethodRef *aRef = seq.getArray();
for( i = 0; i < iMax ; i++ ) {
fprintf( f, " %s\n" , USTRING_TO_PCHAR( aRef[i]->getName( ) ) );
}
fprintf( stderr, "Other attributes\n" );
Sequence<Property> seqProp = ref->getProperties( 0 );
iMax = seqProp.getLen();
Property *aProp = seqProp.getArray();
for( i = 0; i < iMax ; i ++ ) {
fprintf( f, " %s %s\n" , USTRING_TO_PCHAR( aProp[i].Type->getName() ),
USTRING_TO_PCHAR( aProp[i].Name ) );
}
}
void CmdDebugger::dumpVarToStream( const char *pc , const UsrAny &aValue, FILE *f )
{
TypeClass type = aValue.getReflection()->getTypeClass();
if( TypeClass_INT == type ) {
fprintf( f, "INT32 %s : %d\n" , pc , aValue.getINT32() );
}
else if( TypeClass_ENUM == type ) {
fprintf( f, "ENUM %s : %d\n", pc , aValue.getEnumAsINT32() );
}
else if( TypeClass_STRING == type ) {
fprintf( f, "STRING %s : %s\n" , pc , USTRING_TO_PCHAR( aValue.getString()) );
}
else if( TypeClass_BOOLEAN == type ) {
fprintf( f, "BOOL %s : %d\n", pc , aValue.getBOOL() );
}
else if( TypeClass_CHAR == type ) {
fprintf( f, "char %s : %d\n", pc , ( INT32) aValue.getChar() );
}
else if( TypeClass_SHORT == type ) {
fprintf( f, "INT16 %s : %d\n", pc , (INT32) aValue.getINT16());
}
else if( TypeClass_LONG == type ) {
fprintf( f, "LONG %s : %d\n", pc , (INT32) aValue.getINT32());
}
else if( TypeClass_UNSIGNED_SHORT == type ) {
fprintf( f, "UINT16 %s : %d\n", pc , (INT32) aValue.getUINT16() );
}
else if( TypeClass_UNSIGNED_BYTE == type ) {
fprintf( f, "Byte %s : %d\n", pc , (INT32) aValue.getBYTE() );
}
else if( TypeClass_UNSIGNED_INT == type ) {
fprintf( f, "UINT32 %s : %d\n", pc , aValue.getUINT32() );
}
else if( TypeClass_FLOAT == type ) {
fprintf( f, "float %s : %f\n" , pc , aValue.getFloat() );
}
else if( TypeClass_DOUBLE == type ) {
fprintf( f, "double %s : %f\n" , pc , aValue.getDouble() );
}
else if( TypeClass_VOID == type ) {
fprintf( f, "void %s :\n" , pc );
}
else if( TypeClass_INTERFACE == type ) {
// Check, what has been put in
if( aValue.getReflection() == XPropertySet_getReflection() ) {
// XPropertySet !
XPropertySetRef *pRef = ( XPropertySetRef * ) aValue.get();
XPropertySetInfoRef refInfo = (*pRef)->getPropertySetInfo();
Sequence< Property > seq = refInfo->getProperties();
int i,iMax = seq.getLen();
Property *pArray;
pArray = seq.getArray();
fprintf( stderr, "Property List :\n" );
for( i = 0; i < iMax ; i ++ ) {
fprintf( f, "%s\t %s\n" , USTRING_TO_PCHAR(pArray[i].Type->getName()),
USTRING_TO_PCHAR( pArray[i].Name ) );
}
}
else if( aValue.getReflection() == XInvokation_getReflection() ) {
XInvokationRef *pRef = ( XInvokationRef * ) aValue.get();
XIntrospectionAccessRef refIntro = (*pRef)->getIntrospection();
dumpIntrospectionToStream( refIntro, stderr );
}
}
else if( TypeClass_SEQUENCE == type ) {
fprintf( f , "%s Sequence \n" , pc );
String s( " " );
s += pc;
SequenceReflection *pSeqRefl = ( SequenceReflection * ) aValue.getReflection();
int i,iMax = pSeqRefl->getLen( aValue );
for( i = 0 ; i < iMax ; i ++ ) {
dumpVarToStream( s.GetCharStr() , pSeqRefl->get( aValue , i ) , stderr );
}
}
else {
fprintf( f, "%s : unknown %d\n" , pc , type );
}
}
void CmdDebugger::detach()
{
OSL_ASSERT( m_pDebuggingRef );
2000-09-18 15:18:56 +00:00
m_bIsRunning = FALSE;
m_pDebuggingRef = 0;
m_pEngineRef = 0;
m_pInvokationRef = 0;
}
// Methoden von XInterface
BOOL CmdDebugger::queryInterface( Uik aUik, XInterfaceRef & rOut )
{
if( aUik == XEngineListener::getSmartUik() )
rOut = (XEngineListener*)this;
else
return OWeakObject::queryInterface( aUik, rOut );
return TRUE;
}
/*
* main.
*/
int SAL_CALL main (int argc, char **argv)
2000-09-18 15:18:56 +00:00
{
XMultiServiceFactoryRef xSMgr = createRegistryServiceManager();
registerUsrServices( xSMgr );
setProcessServiceManager( xSMgr );
XInterfaceRef x = xSMgr->createInstance( L"stardiv.uno.repos.ImplementationRegistration" );
XImplementationRegistrationRef xReg( x, USR_QUERY );
sal_Char szBuf[1024];
ORealDynamicLoader::computeModuleName( "pythonengine", szBuf, 1024 );
UString aDllName( StringToOUString( szBuf, CHARSET_SYSTEM ) );
xReg->registerImplementation( L"stardiv.loader.SharedLibrary", aDllName, XSimpleRegistryRef() );
ORealDynamicLoader::computeModuleName( "aps", szBuf, 1024 );
aDllName = UString( StringToOUString( szBuf, CHARSET_SYSTEM ) );
xReg->registerImplementation( L"stardiv.loader.SharedLibrary", aDllName, XSimpleRegistryRef() );
XInterfaceRef y = xSMgr->createInstance( L"stardiv.script.Python" );
XEngineRef yEngine( y, USR_QUERY );
x = xSMgr->createInstance( L"stardiv.script.Python" );
XEngineRef xEngine( x, USR_QUERY );
UString Script;
Sequence<UsrAny> args(3);
UsrAny *pArray = args.getArray();
pArray[0].setString( L"Arg_0" );
pArray[1].setString( L"Arg_1" );
pArray[2].setString( L"Arg_2" );
if( argc > 2) {
Script = StringToOUString( String( argv[2] ) , CHARSET_DONTKNOW );
}
XInvokationRef xInvokation( x , USR_QUERY );
XDebuggingRef xDebug( x , USR_QUERY );
CmdDebugger *pDbg = new CmdDebugger( &xDebug , &xEngine , &xInvokation );
XEngineListenerRef xDebugRef( (XEngineListener *) pDbg , USR_QUERY);
xEngine->addEngineListener( xDebugRef );
if( argc >1 && ! strcmp( argv[1] , "1" ) ) {
fprintf( stderr, "one thread only\n" );
Script = UString( L"print 'Hello World'\n" );
xEngine->runAsync( Script , XInterfaceRef(), args , XEngineListenerRef() );
}
else if( argc >1 && ! strcmp( argv[1] , "2" ) ) {
xEngine->runAsync( UString( L"x=1\nprint 1\n") , XInterfaceRef(), args , XEngineListenerRef() );
xEngine->runAsync( UString( L"x=x+1\nprint 2\n") , XInterfaceRef(), args , XEngineListenerRef() );
xEngine->runAsync( UString( L"x=x+1\nprint 3\n") , XInterfaceRef(), args , XEngineListenerRef());
xEngine->runAsync( UString( L"x=x+1\nprint 4\n") , XInterfaceRef(), args , XEngineListenerRef() );
}
else if( argc >1 && ! strcmp( argv[1] , "3" ) ) {
fprintf( stderr , "1st thread in engine y, next 5 threads in engine x\n" );
yEngine->runAsync( UString( L"print 1\n") , XInterfaceRef(), args , XEngineListenerRef() );
xEngine->runAsync( UString( L"print 2\n") , XInterfaceRef(), args , XEngineListenerRef() );
xEngine->runAsync( UString( L"print 3\n") , XInterfaceRef(), args , XEngineListenerRef() );
xEngine->runAsync( UString( L"print 4\n") , XInterfaceRef(), args , XEngineListenerRef());
xEngine->runAsync( UString( L"print 5\n") , XInterfaceRef(), args , XEngineListenerRef());
xEngine->runAsync( UString( L"print 6\n") , XInterfaceRef(), args , XEngineListenerRef());
}
pDbg->cmdLine();
xEngine->removeEngineListener( xDebugRef );
xReg->revokeImplementation( aDllName, XSimpleRegistryRef() );
fprintf( stderr, "main terminates\n" );
return 0;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */