1*2a97ec55SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*2a97ec55SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*2a97ec55SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*2a97ec55SAndrew Rist * distributed with this work for additional information 6*2a97ec55SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*2a97ec55SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*2a97ec55SAndrew Rist * "License"); you may not use this file except in compliance 9*2a97ec55SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*2a97ec55SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*2a97ec55SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*2a97ec55SAndrew Rist * software distributed under the License is distributed on an 15*2a97ec55SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*2a97ec55SAndrew Rist * KIND, either express or implied. See the License for the 17*2a97ec55SAndrew Rist * specific language governing permissions and limitations 18*2a97ec55SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*2a97ec55SAndrew Rist *************************************************************/ 21*2a97ec55SAndrew Rist 22*2a97ec55SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_extensions.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <stdio.h> 28cdf0e10cSrcweir #include <stardiv/uno/repos/implementationregistration.hxx> 29cdf0e10cSrcweir #include <stardiv/uno/script/script.hxx> 30cdf0e10cSrcweir #include <stardiv/uno/beans/exactname.hxx> 31cdf0e10cSrcweir 32cdf0e10cSrcweir #include <rtl/ustring.hxx> 33cdf0e10cSrcweir #include <vos/dynload.hxx> 34cdf0e10cSrcweir #include <vos/diagnose.hxx> 35cdf0e10cSrcweir #include <usr/services.hxx> 36cdf0e10cSrcweir #include <vcl/svapp.hxx> 37cdf0e10cSrcweir #include <usr/ustring.hxx> 38cdf0e10cSrcweir #include <usr/weak.hxx> 39cdf0e10cSrcweir #include <tools/string.hxx> 40cdf0e10cSrcweir #include <vos/conditn.hxx> 41cdf0e10cSrcweir 42cdf0e10cSrcweir using namespace rtl; 43cdf0e10cSrcweir using namespace vos; 44cdf0e10cSrcweir using namespace usr; 45cdf0e10cSrcweir 46cdf0e10cSrcweir #define PCHAR_TO_USTRING(x) StringToOUString(String(x),CHARSET_SYSTEM) 47cdf0e10cSrcweir 48cdf0e10cSrcweir 49cdf0e10cSrcweir 50cdf0e10cSrcweir class NullEngineListenerRef : public XEngineListenerRef 51cdf0e10cSrcweir { 52cdf0e10cSrcweir virtual void interrupt(const InterruptEngineEvent& Evt) THROWS( (UsrSystemException) ) {} 53cdf0e10cSrcweir virtual void running(const EventObject& Evt) THROWS( (UsrSystemException) ) {} 54cdf0e10cSrcweir virtual void finished(const FinishEngineEvent& Evt) THROWS( (UsrSystemException) ) {} 55cdf0e10cSrcweir }; 56cdf0e10cSrcweir 57cdf0e10cSrcweir #define USTRING_TO_PCHAR(x) OUStringToString(x , CHARSET_DONTKNOW ).GetCharStr() 58cdf0e10cSrcweir 59cdf0e10cSrcweir class CmdDebugger : 60cdf0e10cSrcweir public XEngineListener, 61cdf0e10cSrcweir public OWeakObject 62cdf0e10cSrcweir { 63cdf0e10cSrcweir public: 64cdf0e10cSrcweir 65cdf0e10cSrcweir CmdDebugger() 66cdf0e10cSrcweir { 67cdf0e10cSrcweir m_pDebuggingRef = 0; 68cdf0e10cSrcweir m_pEngineRef = 0; 69cdf0e10cSrcweir m_bIsTerminating = FALSE; 70cdf0e10cSrcweir m_bIsRunning = FALSE; 71cdf0e10cSrcweir } 72cdf0e10cSrcweir 73cdf0e10cSrcweir 74cdf0e10cSrcweir CmdDebugger( XDebuggingRef *p, XEngineRef *pEngine , XInvokationRef *pInvokation) 75cdf0e10cSrcweir { 76cdf0e10cSrcweir attach( p , pEngine , pInvokation ); 77cdf0e10cSrcweir } 78cdf0e10cSrcweir 79cdf0e10cSrcweir ~CmdDebugger() 80cdf0e10cSrcweir { 81cdf0e10cSrcweir if( m_pDebuggingRef ) { 82cdf0e10cSrcweir detach(); 83cdf0e10cSrcweir } 84cdf0e10cSrcweir } 85cdf0e10cSrcweir 86cdf0e10cSrcweir BOOL queryInterface( Uik aUik, XInterfaceRef & rOut ); 87cdf0e10cSrcweir void acquire() { OWeakObject::acquire(); } 88cdf0e10cSrcweir void release() { OWeakObject::release(); } 89cdf0e10cSrcweir void* getImplementation(Reflection *p) { return OWeakObject::getImplementation(p); } 90cdf0e10cSrcweir 91cdf0e10cSrcweir 92cdf0e10cSrcweir void attach( XDebuggingRef *p , XEngineRef *pEngine , XInvokationRef *pInvokation ) 93cdf0e10cSrcweir { 94cdf0e10cSrcweir m_pDebuggingRef = p; 95cdf0e10cSrcweir m_pEngineRef = pEngine; 96cdf0e10cSrcweir m_pInvokationRef = pInvokation; 97cdf0e10cSrcweir m_bIsRunning = FALSE; 98cdf0e10cSrcweir m_bIsTerminating = FALSE; 99cdf0e10cSrcweir } 100cdf0e10cSrcweir 101cdf0e10cSrcweir void detach( ); 102cdf0e10cSrcweir 103cdf0e10cSrcweir 104cdf0e10cSrcweir virtual void disposing( const EventObject &o ) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir if( m_pDebuggingRef ) { 107cdf0e10cSrcweir detach(); 108cdf0e10cSrcweir } 109cdf0e10cSrcweir } 110cdf0e10cSrcweir virtual void interrupt(const InterruptEngineEvent& Evt) THROWS( (UsrSystemException) ) 111cdf0e10cSrcweir { 112cdf0e10cSrcweir if( m_pDebuggingRef && ! m_bIsTerminating ) { 113cdf0e10cSrcweir (*m_pDebuggingRef)->stop(); 114cdf0e10cSrcweir fprintf( stderr, "%s\n" , USTRING_TO_PCHAR(Evt.ErrorMessage ) ); 115cdf0e10cSrcweir fprintf( stderr, "%s.%s (%d)\n", USTRING_TO_PCHAR(Evt.SourceCode), 116cdf0e10cSrcweir USTRING_TO_PCHAR(Evt.Name ), 117cdf0e10cSrcweir Evt.StartLine ); 118cdf0e10cSrcweir m_aDebugCondition.set(); 119cdf0e10cSrcweir m_bIsRunning = TRUE; 120cdf0e10cSrcweir } 121cdf0e10cSrcweir } 122cdf0e10cSrcweir 123cdf0e10cSrcweir virtual void running(const EventObject& Evt) THROWS( (UsrSystemException) ) 124cdf0e10cSrcweir { 125cdf0e10cSrcweir if( m_pDebuggingRef && ! m_bIsTerminating ) { 126cdf0e10cSrcweir (*m_pDebuggingRef)->stop(); 127cdf0e10cSrcweir 128cdf0e10cSrcweir m_aDebugCondition.set(); 129cdf0e10cSrcweir m_bIsRunning = TRUE; 130cdf0e10cSrcweir fprintf( stderr, "%s\n" , "Script starts\n" ); 131cdf0e10cSrcweir } 132cdf0e10cSrcweir } 133cdf0e10cSrcweir 134cdf0e10cSrcweir virtual void finished(const FinishEngineEvent& Evt) THROWS( (UsrSystemException) ) 135cdf0e10cSrcweir { 136cdf0e10cSrcweir if( m_pDebuggingRef && ! m_bIsTerminating ) { 137cdf0e10cSrcweir m_aDebugCondition.set(); 138cdf0e10cSrcweir m_bIsRunning = FALSE; 139cdf0e10cSrcweir fprintf( stderr , "%s\n", USTRING_TO_PCHAR( Evt.ErrorMessage ) ); 140cdf0e10cSrcweir } 141cdf0e10cSrcweir } 142cdf0e10cSrcweir 143cdf0e10cSrcweir void dumpIntrospectionToStream( const XIntrospectionAccessRef &, FILE *f ); 144cdf0e10cSrcweir void dumpVarToStream( const char *pcName, const UsrAny &any, FILE *f ); 145cdf0e10cSrcweir 146cdf0e10cSrcweir 147cdf0e10cSrcweir void cmdLine(); 148cdf0e10cSrcweir protected: 149cdf0e10cSrcweir 150cdf0e10cSrcweir OCondition m_aDebugCondition; 151cdf0e10cSrcweir XDebuggingRef *m_pDebuggingRef; 152cdf0e10cSrcweir XEngineRef *m_pEngineRef; 153cdf0e10cSrcweir XInvokationRef *m_pInvokationRef; 154cdf0e10cSrcweir int m_bIsRunning; 155cdf0e10cSrcweir int m_bIsTerminating; // The listeners ignore everything when set 156cdf0e10cSrcweir }; 157cdf0e10cSrcweir 158cdf0e10cSrcweir 159cdf0e10cSrcweir 160cdf0e10cSrcweir void CmdDebugger::cmdLine() 161cdf0e10cSrcweir { 162cdf0e10cSrcweir char pcLine[80]; 163cdf0e10cSrcweir fprintf( stderr, "entering debugger\n" ); 164cdf0e10cSrcweir while( TRUE ) { 165cdf0e10cSrcweir 166cdf0e10cSrcweir m_aDebugCondition.wait(); 167cdf0e10cSrcweir 168cdf0e10cSrcweir fprintf( stderr , "(debug %d) : " , m_bIsRunning ); 169cdf0e10cSrcweir fflush( stderr); 170cdf0e10cSrcweir fgets( pcLine , 79 , stdin ); 171cdf0e10cSrcweir 172cdf0e10cSrcweir if( strlen( pcLine) ) pcLine[strlen(pcLine)-1] =0; 173cdf0e10cSrcweir String sLine( pcLine ); 174cdf0e10cSrcweir 175cdf0e10cSrcweir if( ! strcmp( pcLine , "g" ) ) { 176cdf0e10cSrcweir if( m_bIsRunning ) { 177cdf0e10cSrcweir m_aDebugCondition.reset(); 178cdf0e10cSrcweir (*m_pDebuggingRef)->doContinue(); 179cdf0e10cSrcweir } 180cdf0e10cSrcweir else fprintf( stderr,"no script running !\n" ); 181cdf0e10cSrcweir } 182cdf0e10cSrcweir else if( ! strcmp( pcLine , "s" ) ) { 183cdf0e10cSrcweir if( m_bIsRunning ) { 184cdf0e10cSrcweir m_aDebugCondition.reset(); 185cdf0e10cSrcweir (*m_pDebuggingRef)->stepOver(); 186cdf0e10cSrcweir } 187cdf0e10cSrcweir else fprintf(stderr, "no script running !\n" ); 188cdf0e10cSrcweir } 189cdf0e10cSrcweir else if( ! strcmp( pcLine , "so" ) ) { 190cdf0e10cSrcweir if( m_bIsRunning ) { 191cdf0e10cSrcweir m_aDebugCondition.reset(); 192cdf0e10cSrcweir (*m_pDebuggingRef)->stepOut(); 193cdf0e10cSrcweir } 194cdf0e10cSrcweir else fprintf(stderr, "no script running !\n" ); 195cdf0e10cSrcweir } 196cdf0e10cSrcweir else if( ! strcmp( pcLine , "si" ) ) { 197cdf0e10cSrcweir if( m_bIsRunning ) { 198cdf0e10cSrcweir m_aDebugCondition.reset(); 199cdf0e10cSrcweir (*m_pDebuggingRef)->stepIn(); 200cdf0e10cSrcweir } 201cdf0e10cSrcweir else fprintf(stderr, "no script running !\n" ); 202cdf0e10cSrcweir } 203cdf0e10cSrcweir else if( ! strncmp( pcLine , "sbp" , 3 ) ){ 204cdf0e10cSrcweir if( m_bIsRunning ) { 205cdf0e10cSrcweir (*m_pDebuggingRef)->setBreakPoint( UString( L"<string>" ), 206cdf0e10cSrcweir atoi(&pcLine[3]) , TRUE ); 207cdf0e10cSrcweir } 208cdf0e10cSrcweir } 209cdf0e10cSrcweir else if( ! strncmp( pcLine , "rbp" , 3 ) ){ 210cdf0e10cSrcweir if( m_bIsRunning ) { 211cdf0e10cSrcweir (*m_pDebuggingRef)->setBreakPoint( UString( L"<string>" ), 212cdf0e10cSrcweir atoi(&pcLine[3]) , FALSE ); 213cdf0e10cSrcweir } 214cdf0e10cSrcweir } 215cdf0e10cSrcweir else if( ! strncmp( pcLine , "dv " , 3 ) ) { 216cdf0e10cSrcweir if( m_bIsRunning ) { 217cdf0e10cSrcweir int nCallstack = 0; 218cdf0e10cSrcweir if( sLine.GetQuotedTokenCount( String("''"),' ' ) == 3 ) { 219cdf0e10cSrcweir nCallstack = atoi( sLine.GetQuotedToken( 3 , String("''"), ' ' ).GetCharStr() ); 220cdf0e10cSrcweir } 221cdf0e10cSrcweir 222cdf0e10cSrcweir UString str = (*m_pDebuggingRef)->dumpVariable( 223cdf0e10cSrcweir PCHAR_TO_USTRING( &pcLine[3]),nCallstack); 224cdf0e10cSrcweir fprintf( stderr, "%s\n" , USTRING_TO_PCHAR( str ) ); 225cdf0e10cSrcweir } 226cdf0e10cSrcweir } 227cdf0e10cSrcweir else if( ! strncmp( pcLine , "sv " , 3 ) ) { 228cdf0e10cSrcweir int nCallstack = 0; 229cdf0e10cSrcweir if( sLine.GetQuotedTokenCount( String("''"),' ' ) == 3 ) { 230cdf0e10cSrcweir nCallstack = atoi( sLine.GetQuotedToken( 3 , String("''"), ' ' ).GetCharStr() ); 231cdf0e10cSrcweir } 232cdf0e10cSrcweir (*m_pDebuggingRef)->setVariable( 233cdf0e10cSrcweir StringToOUString( sLine.GetQuotedToken( 1 , String("''"), ' ' ), CHARSET_SYSTEM ), 234cdf0e10cSrcweir StringToOUString( sLine.GetQuotedToken( 2 , String("''"), ' ' ), CHARSET_SYSTEM ), 235cdf0e10cSrcweir nCallstack ); 236cdf0e10cSrcweir 237cdf0e10cSrcweir } 238cdf0e10cSrcweir else if( ! strncmp( pcLine , "ci" ,2 ) ) { 239cdf0e10cSrcweir if( m_bIsRunning ) { 240cdf0e10cSrcweir UString *aUString ; 241cdf0e10cSrcweir ContextInformation ci = (*m_pDebuggingRef)->getContextInformation(atoi(&pcLine[2])); 242cdf0e10cSrcweir int i,iMax; 243cdf0e10cSrcweir 244cdf0e10cSrcweir fprintf( stderr, "File %s (%d)\n", USTRING_TO_PCHAR(ci.Name), 245cdf0e10cSrcweir ci.StartLine ); 246cdf0e10cSrcweir fprintf( stderr, "Available variables : \n" ); 247cdf0e10cSrcweir aUString = ci.LocalVariableNames.getArray(); 248cdf0e10cSrcweir iMax = ci.LocalVariableNames.getLen(); 249cdf0e10cSrcweir 250cdf0e10cSrcweir for( i = 0 ; i < iMax ; i++ ) { 251cdf0e10cSrcweir fprintf( stderr, " %s\n" , USTRING_TO_PCHAR( aUString[i]) ); 252cdf0e10cSrcweir } 253cdf0e10cSrcweir } 254cdf0e10cSrcweir } 255cdf0e10cSrcweir else if ( !strcmp( pcLine , "d" ) ) { 256cdf0e10cSrcweir if( m_bIsRunning ) { 257cdf0e10cSrcweir UString * aUString ; 258cdf0e10cSrcweir Sequence<UString> seq = (*m_pDebuggingRef)->getStackTrace(); 259cdf0e10cSrcweir 260cdf0e10cSrcweir aUString = seq.getArray(); 261cdf0e10cSrcweir int iMax = seq.getLen(); 262cdf0e10cSrcweir for( int i = 0; i < iMax ; i++ ) { 263cdf0e10cSrcweir fprintf( stderr , "%s\n" , USTRING_TO_PCHAR( aUString[i] ) ); 264cdf0e10cSrcweir } 265cdf0e10cSrcweir } 266cdf0e10cSrcweir } 267cdf0e10cSrcweir else if( !strcmp( pcLine , "c" ) ) { 268cdf0e10cSrcweir if( m_bIsRunning ) { 269cdf0e10cSrcweir (*m_pEngineRef)->cancel(); 270cdf0e10cSrcweir m_aDebugCondition.reset(); 271cdf0e10cSrcweir } 272cdf0e10cSrcweir else fprintf( stderr,"no script running !\n" ); 273cdf0e10cSrcweir } 274cdf0e10cSrcweir else if( !strcmp( pcLine , "q" ) ) { 275cdf0e10cSrcweir if( m_bIsRunning ) { 276cdf0e10cSrcweir m_aDebugCondition.reset(); 277cdf0e10cSrcweir (*m_pEngineRef)->cancel(); 278cdf0e10cSrcweir } 279cdf0e10cSrcweir else { 280cdf0e10cSrcweir m_bIsTerminating = TRUE; 281cdf0e10cSrcweir fprintf(stderr, "Debugger terminates\n" ); 282cdf0e10cSrcweir break; 283cdf0e10cSrcweir } 284cdf0e10cSrcweir } 285cdf0e10cSrcweir else if( ! strcmp( pcLine , "id" ) ) { 286cdf0e10cSrcweir 287cdf0e10cSrcweir XIntrospectionAccessRef ref = (*m_pInvokationRef)->getIntrospection(); 288cdf0e10cSrcweir 289cdf0e10cSrcweir dumpIntrospectionToStream( ref , stderr ); 290cdf0e10cSrcweir 291cdf0e10cSrcweir 292cdf0e10cSrcweir } 293cdf0e10cSrcweir else if( ! strncmp( pcLine , "idv" , 3) ) { 294cdf0e10cSrcweir try { 295cdf0e10cSrcweir UsrAny any = (*m_pInvokationRef)->getValue( PCHAR_TO_USTRING( &(pcLine[4]) ) ); 296cdf0e10cSrcweir dumpVarToStream( &(pcLine[4]) , any , stderr ); 297cdf0e10cSrcweir } 298cdf0e10cSrcweir catch(UnknownPropertyException& e ) { 299cdf0e10cSrcweir fprintf( stderr, "UnknownPropertyException\n" ); 300cdf0e10cSrcweir } 301cdf0e10cSrcweir catch(IllegalArgumentException& e ) { 302cdf0e10cSrcweir fprintf( stderr, "IllegalArgumentException\n" ); 303cdf0e10cSrcweir } 304cdf0e10cSrcweir } 305cdf0e10cSrcweir else if( !strcmp( pcLine , "t" ) ) { 306cdf0e10cSrcweir } 307cdf0e10cSrcweir else if( !strcmp( pcLine , "h" ) ) { 308cdf0e10cSrcweir fprintf( stderr , "\nvalid commands :\n" 309cdf0e10cSrcweir "Go : g\n" 310cdf0e10cSrcweir "StepOver : s\n" 311cdf0e10cSrcweir "StepIn : si\n" 312cdf0e10cSrcweir "StepOut : so\n" 313cdf0e10cSrcweir "Set BreakPoint : sbp Line [ModuleName]\n" 314cdf0e10cSrcweir "Remove BreakPoint : rbp [Line] [ModuleName]\n" 315cdf0e10cSrcweir "via XDebugging Interface :\n" 316cdf0e10cSrcweir " dump Variable : dv varname [CallStack]\n" 317cdf0e10cSrcweir " set Variable : sv varname value [CallStack]\n" 318cdf0e10cSrcweir "globals via XInvokation Interface :\n" 319cdf0e10cSrcweir " dump Global vars : id\n" 320cdf0e10cSrcweir " dump Variable : idv varname\n" 321cdf0e10cSrcweir " set Variable : isv varname value\n" 322cdf0e10cSrcweir "ContextInformation : ci\n" 323cdf0e10cSrcweir "Dump callstack : d\n" 324cdf0e10cSrcweir "Cancel : c (stops actual script)\n" 325cdf0e10cSrcweir "Quit : q (exits debugger)\n" 326cdf0e10cSrcweir ); 327cdf0e10cSrcweir } 328cdf0e10cSrcweir else if( ! strlen( pcLine ) ) { 329cdf0e10cSrcweir } 330cdf0e10cSrcweir else { 331cdf0e10cSrcweir fprintf( stderr , "unknown command %s\n" , pcLine ); 332cdf0e10cSrcweir } 333cdf0e10cSrcweir } 334cdf0e10cSrcweir } 335cdf0e10cSrcweir 336cdf0e10cSrcweir void CmdDebugger::dumpIntrospectionToStream( const XIntrospectionAccessRef &ref, FILE *f ) 337cdf0e10cSrcweir { 338cdf0e10cSrcweir int i,iMax; 339cdf0e10cSrcweir fprintf( stderr, "Callable Attributes (Methods) :\n" ); 340cdf0e10cSrcweir Sequence<XIdlMethodRef> seq = ref->getMethods( 0 ); 341cdf0e10cSrcweir iMax = seq.getLen(); 342cdf0e10cSrcweir XIdlMethodRef *aRef = seq.getArray(); 343cdf0e10cSrcweir for( i = 0; i < iMax ; i++ ) { 344cdf0e10cSrcweir fprintf( f, " %s\n" , USTRING_TO_PCHAR( aRef[i]->getName( ) ) ); 345cdf0e10cSrcweir } 346cdf0e10cSrcweir 347cdf0e10cSrcweir fprintf( stderr, "Other attributes\n" ); 348cdf0e10cSrcweir Sequence<Property> seqProp = ref->getProperties( 0 ); 349cdf0e10cSrcweir iMax = seqProp.getLen(); 350cdf0e10cSrcweir Property *aProp = seqProp.getArray(); 351cdf0e10cSrcweir for( i = 0; i < iMax ; i ++ ) { 352cdf0e10cSrcweir fprintf( f, " %s %s\n" , USTRING_TO_PCHAR( aProp[i].Type->getName() ), 353cdf0e10cSrcweir USTRING_TO_PCHAR( aProp[i].Name ) ); 354cdf0e10cSrcweir } 355cdf0e10cSrcweir 356cdf0e10cSrcweir } 357cdf0e10cSrcweir 358cdf0e10cSrcweir void CmdDebugger::dumpVarToStream( const char *pc , const UsrAny &aValue, FILE *f ) 359cdf0e10cSrcweir { 360cdf0e10cSrcweir TypeClass type = aValue.getReflection()->getTypeClass(); 361cdf0e10cSrcweir 362cdf0e10cSrcweir if( TypeClass_INT == type ) { 363cdf0e10cSrcweir fprintf( f, "INT32 %s : %d\n" , pc , aValue.getINT32() ); 364cdf0e10cSrcweir } 365cdf0e10cSrcweir else if( TypeClass_ENUM == type ) { 366cdf0e10cSrcweir fprintf( f, "ENUM %s : %d\n", pc , aValue.getEnumAsINT32() ); 367cdf0e10cSrcweir } 368cdf0e10cSrcweir else if( TypeClass_STRING == type ) { 369cdf0e10cSrcweir fprintf( f, "STRING %s : %s\n" , pc , USTRING_TO_PCHAR( aValue.getString()) ); 370cdf0e10cSrcweir } 371cdf0e10cSrcweir else if( TypeClass_BOOLEAN == type ) { 372cdf0e10cSrcweir fprintf( f, "BOOL %s : %d\n", pc , aValue.getBOOL() ); 373cdf0e10cSrcweir } 374cdf0e10cSrcweir else if( TypeClass_CHAR == type ) { 375cdf0e10cSrcweir fprintf( f, "char %s : %d\n", pc , ( INT32) aValue.getChar() ); 376cdf0e10cSrcweir } 377cdf0e10cSrcweir else if( TypeClass_SHORT == type ) { 378cdf0e10cSrcweir fprintf( f, "INT16 %s : %d\n", pc , (INT32) aValue.getINT16()); 379cdf0e10cSrcweir } 380cdf0e10cSrcweir else if( TypeClass_LONG == type ) { 381cdf0e10cSrcweir fprintf( f, "LONG %s : %d\n", pc , (INT32) aValue.getINT32()); 382cdf0e10cSrcweir } 383cdf0e10cSrcweir else if( TypeClass_UNSIGNED_SHORT == type ) { 384cdf0e10cSrcweir fprintf( f, "UINT16 %s : %d\n", pc , (INT32) aValue.getUINT16() ); 385cdf0e10cSrcweir } 386cdf0e10cSrcweir else if( TypeClass_UNSIGNED_BYTE == type ) { 387cdf0e10cSrcweir fprintf( f, "Byte %s : %d\n", pc , (INT32) aValue.getBYTE() ); 388cdf0e10cSrcweir } 389cdf0e10cSrcweir else if( TypeClass_UNSIGNED_INT == type ) { 390cdf0e10cSrcweir fprintf( f, "UINT32 %s : %d\n", pc , aValue.getUINT32() ); 391cdf0e10cSrcweir } 392cdf0e10cSrcweir else if( TypeClass_FLOAT == type ) { 393cdf0e10cSrcweir fprintf( f, "float %s : %f\n" , pc , aValue.getFloat() ); 394cdf0e10cSrcweir } 395cdf0e10cSrcweir else if( TypeClass_DOUBLE == type ) { 396cdf0e10cSrcweir fprintf( f, "double %s : %f\n" , pc , aValue.getDouble() ); 397cdf0e10cSrcweir } 398cdf0e10cSrcweir else if( TypeClass_VOID == type ) { 399cdf0e10cSrcweir fprintf( f, "void %s :\n" , pc ); 400cdf0e10cSrcweir } 401cdf0e10cSrcweir else if( TypeClass_INTERFACE == type ) { 402cdf0e10cSrcweir // Check, what has been put in 403cdf0e10cSrcweir if( aValue.getReflection() == XPropertySet_getReflection() ) { 404cdf0e10cSrcweir // XPropertySet ! 405cdf0e10cSrcweir XPropertySetRef *pRef = ( XPropertySetRef * ) aValue.get(); 406cdf0e10cSrcweir XPropertySetInfoRef refInfo = (*pRef)->getPropertySetInfo(); 407cdf0e10cSrcweir Sequence< Property > seq = refInfo->getProperties(); 408cdf0e10cSrcweir int i,iMax = seq.getLen(); 409cdf0e10cSrcweir 410cdf0e10cSrcweir Property *pArray; 411cdf0e10cSrcweir pArray = seq.getArray(); 412cdf0e10cSrcweir fprintf( stderr, "Property List :\n" ); 413cdf0e10cSrcweir for( i = 0; i < iMax ; i ++ ) { 414cdf0e10cSrcweir fprintf( f, "%s\t %s\n" , USTRING_TO_PCHAR(pArray[i].Type->getName()), 415cdf0e10cSrcweir USTRING_TO_PCHAR( pArray[i].Name ) ); 416cdf0e10cSrcweir } 417cdf0e10cSrcweir } 418cdf0e10cSrcweir else if( aValue.getReflection() == XInvokation_getReflection() ) { 419cdf0e10cSrcweir XInvokationRef *pRef = ( XInvokationRef * ) aValue.get(); 420cdf0e10cSrcweir XIntrospectionAccessRef refIntro = (*pRef)->getIntrospection(); 421cdf0e10cSrcweir 422cdf0e10cSrcweir dumpIntrospectionToStream( refIntro, stderr ); 423cdf0e10cSrcweir } 424cdf0e10cSrcweir } 425cdf0e10cSrcweir else if( TypeClass_SEQUENCE == type ) { 426cdf0e10cSrcweir fprintf( f , "%s Sequence \n" , pc ); 427cdf0e10cSrcweir String s( " " ); 428cdf0e10cSrcweir s += pc; 429cdf0e10cSrcweir SequenceReflection *pSeqRefl = ( SequenceReflection * ) aValue.getReflection(); 430cdf0e10cSrcweir 431cdf0e10cSrcweir int i,iMax = pSeqRefl->getLen( aValue ); 432cdf0e10cSrcweir 433cdf0e10cSrcweir for( i = 0 ; i < iMax ; i ++ ) { 434cdf0e10cSrcweir dumpVarToStream( s.GetCharStr() , pSeqRefl->get( aValue , i ) , stderr ); 435cdf0e10cSrcweir } 436cdf0e10cSrcweir } 437cdf0e10cSrcweir else { 438cdf0e10cSrcweir fprintf( f, "%s : unknown %d\n" , pc , type ); 439cdf0e10cSrcweir } 440cdf0e10cSrcweir 441cdf0e10cSrcweir } 442cdf0e10cSrcweir 443cdf0e10cSrcweir void CmdDebugger::detach() 444cdf0e10cSrcweir { 445cdf0e10cSrcweir OSL_ASSERT( m_pDebuggingRef ); 446cdf0e10cSrcweir 447cdf0e10cSrcweir m_bIsRunning = FALSE; 448cdf0e10cSrcweir m_pDebuggingRef = 0; 449cdf0e10cSrcweir m_pEngineRef = 0; 450cdf0e10cSrcweir m_pInvokationRef = 0; 451cdf0e10cSrcweir } 452cdf0e10cSrcweir 453cdf0e10cSrcweir // Methoden von XInterface 454cdf0e10cSrcweir BOOL CmdDebugger::queryInterface( Uik aUik, XInterfaceRef & rOut ) 455cdf0e10cSrcweir { 456cdf0e10cSrcweir if( aUik == XEngineListener::getSmartUik() ) 457cdf0e10cSrcweir rOut = (XEngineListener*)this; 458cdf0e10cSrcweir else 459cdf0e10cSrcweir return OWeakObject::queryInterface( aUik, rOut ); 460cdf0e10cSrcweir return TRUE; 461cdf0e10cSrcweir } 462cdf0e10cSrcweir 463cdf0e10cSrcweir 464cdf0e10cSrcweir 465cdf0e10cSrcweir 466cdf0e10cSrcweir 467cdf0e10cSrcweir 468cdf0e10cSrcweir /* 469cdf0e10cSrcweir * main. 470cdf0e10cSrcweir */ 471cdf0e10cSrcweir int __LOADONCALLAPI main (int argc, char **argv) 472cdf0e10cSrcweir { 473cdf0e10cSrcweir XMultiServiceFactoryRef xSMgr = createRegistryServiceManager(); 474cdf0e10cSrcweir registerUsrServices( xSMgr ); 475cdf0e10cSrcweir setProcessServiceManager( xSMgr ); 476cdf0e10cSrcweir 477cdf0e10cSrcweir XInterfaceRef x = xSMgr->createInstance( L"stardiv.uno.repos.ImplementationRegistration" ); 478cdf0e10cSrcweir XImplementationRegistrationRef xReg( x, USR_QUERY ); 479cdf0e10cSrcweir sal_Char szBuf[1024]; 480cdf0e10cSrcweir 481cdf0e10cSrcweir ORealDynamicLoader::computeModuleName( "pythonengine", szBuf, 1024 ); 482cdf0e10cSrcweir UString aDllName( StringToOUString( szBuf, CHARSET_SYSTEM ) ); 483cdf0e10cSrcweir xReg->registerImplementation( L"stardiv.loader.SharedLibrary", aDllName, XSimpleRegistryRef() ); 484cdf0e10cSrcweir 485cdf0e10cSrcweir ORealDynamicLoader::computeModuleName( "aps", szBuf, 1024 ); 486cdf0e10cSrcweir aDllName = UString( StringToOUString( szBuf, CHARSET_SYSTEM ) ); 487cdf0e10cSrcweir xReg->registerImplementation( L"stardiv.loader.SharedLibrary", aDllName, XSimpleRegistryRef() ); 488cdf0e10cSrcweir 489cdf0e10cSrcweir XInterfaceRef y = xSMgr->createInstance( L"stardiv.script.Python" ); 490cdf0e10cSrcweir XEngineRef yEngine( y, USR_QUERY ); 491cdf0e10cSrcweir 492cdf0e10cSrcweir x = xSMgr->createInstance( L"stardiv.script.Python" ); 493cdf0e10cSrcweir XEngineRef xEngine( x, USR_QUERY ); 494cdf0e10cSrcweir 495cdf0e10cSrcweir 496cdf0e10cSrcweir UString Script; 497cdf0e10cSrcweir 498cdf0e10cSrcweir Sequence<UsrAny> args(3); 499cdf0e10cSrcweir UsrAny *pArray = args.getArray(); 500cdf0e10cSrcweir pArray[0].setString( L"Arg_0" ); 501cdf0e10cSrcweir pArray[1].setString( L"Arg_1" ); 502cdf0e10cSrcweir pArray[2].setString( L"Arg_2" ); 503cdf0e10cSrcweir 504cdf0e10cSrcweir if( argc > 2) { 505cdf0e10cSrcweir Script = StringToOUString( String( argv[2] ) , CHARSET_DONTKNOW ); 506cdf0e10cSrcweir } 507cdf0e10cSrcweir 508cdf0e10cSrcweir XInvokationRef xInvokation( x , USR_QUERY ); 509cdf0e10cSrcweir XDebuggingRef xDebug( x , USR_QUERY ); 510cdf0e10cSrcweir 511cdf0e10cSrcweir CmdDebugger *pDbg = new CmdDebugger( &xDebug , &xEngine , &xInvokation ); 512cdf0e10cSrcweir 513cdf0e10cSrcweir XEngineListenerRef xDebugRef( (XEngineListener *) pDbg , USR_QUERY); 514cdf0e10cSrcweir xEngine->addEngineListener( xDebugRef ); 515cdf0e10cSrcweir 516cdf0e10cSrcweir 517cdf0e10cSrcweir if( argc >1 && ! strcmp( argv[1] , "1" ) ) { 518cdf0e10cSrcweir fprintf( stderr, "one thread only\n" ); 519cdf0e10cSrcweir Script = UString( L"print 'Hello World'\n" ); 520cdf0e10cSrcweir xEngine->runAsync( Script , XInterfaceRef(), args , XEngineListenerRef() ); 521cdf0e10cSrcweir } 522cdf0e10cSrcweir else if( argc >1 && ! strcmp( argv[1] , "2" ) ) { 523cdf0e10cSrcweir 524cdf0e10cSrcweir xEngine->runAsync( UString( L"x=1\nprint 1\n") , XInterfaceRef(), args , XEngineListenerRef() ); 525cdf0e10cSrcweir xEngine->runAsync( UString( L"x=x+1\nprint 2\n") , XInterfaceRef(), args , XEngineListenerRef() ); 526cdf0e10cSrcweir xEngine->runAsync( UString( L"x=x+1\nprint 3\n") , XInterfaceRef(), args , XEngineListenerRef()); 527cdf0e10cSrcweir xEngine->runAsync( UString( L"x=x+1\nprint 4\n") , XInterfaceRef(), args , XEngineListenerRef() ); 528cdf0e10cSrcweir 529cdf0e10cSrcweir 530cdf0e10cSrcweir 531cdf0e10cSrcweir } 532cdf0e10cSrcweir else if( argc >1 && ! strcmp( argv[1] , "3" ) ) { 533cdf0e10cSrcweir 534cdf0e10cSrcweir fprintf( stderr , "1st thread in engine y, next 5 threads in engine x\n" ); 535cdf0e10cSrcweir yEngine->runAsync( UString( L"print 1\n") , XInterfaceRef(), args , XEngineListenerRef() ); 536cdf0e10cSrcweir xEngine->runAsync( UString( L"print 2\n") , XInterfaceRef(), args , XEngineListenerRef() ); 537cdf0e10cSrcweir xEngine->runAsync( UString( L"print 3\n") , XInterfaceRef(), args , XEngineListenerRef() ); 538cdf0e10cSrcweir xEngine->runAsync( UString( L"print 4\n") , XInterfaceRef(), args , XEngineListenerRef()); 539cdf0e10cSrcweir xEngine->runAsync( UString( L"print 5\n") , XInterfaceRef(), args , XEngineListenerRef()); 540cdf0e10cSrcweir xEngine->runAsync( UString( L"print 6\n") , XInterfaceRef(), args , XEngineListenerRef()); 541cdf0e10cSrcweir 542cdf0e10cSrcweir 543cdf0e10cSrcweir } 544cdf0e10cSrcweir pDbg->cmdLine(); 545cdf0e10cSrcweir 546cdf0e10cSrcweir xEngine->removeEngineListener( xDebugRef ); 547cdf0e10cSrcweir 548cdf0e10cSrcweir xReg->revokeImplementation( aDllName, XSimpleRegistryRef() ); 549cdf0e10cSrcweir 550cdf0e10cSrcweir fprintf( stderr, "main terminates\n" ); 551cdf0e10cSrcweir return 0; 552cdf0e10cSrcweir } 553cdf0e10cSrcweir 554