// Author: Wim Lavrijsen   Aug 2007

#ifndef ROOT_TPyDispatcher
#define ROOT_TPyDispatcher

//////////////////////////////////////////////////////////////////////////////
//                                                                          //
// TPyDispatcher                                                            //
//                                                                          //
// Dispatcher for CINT callbacks into python code.                          //
//                                                                          //
//////////////////////////////////////////////////////////////////////////////


// ROOT
#ifndef ROOT_TObject
#include "TObject.h"
#endif

class TDNDData;
class TEveDigitSet;
class TEveElement;
class TEveTrack;
class TEveWindow;
class TGFrame;
class TGListTreeItem;
class TGMdiFrame;
class TGLPhysicalShape;
class TGShutterItem;
class TGLVEntry;
class TGLViewerBase;
class TGVFileSplitter;
class TList;
class TObject;
class TPad;
class TProofProgressInfo;
class TQCommand;
class TSlave;
class TSocket;
class TVirtualPad;

struct Event_t;

// Python
struct _object;
typedef _object PyObject;


class TPyDispatcher : public TObject {
public:
   TPyDispatcher( PyObject* callable );
   TPyDispatcher( const TPyDispatcher& );
   TPyDispatcher& operator=( const TPyDispatcher& );
   ~TPyDispatcher();

public:
#ifndef __CINT__
   PyObject* DispatchVA( const char* format = 0, ... );
#else
   PyObject* DispatchVA( const char* format, ... );
#endif
   PyObject* DispatchVA1( const char* clname, void* obj, const char* format, ... );

// pre-defined dispatches, same as per TQObject::Emit(); note that
// Emit() maps exclusively to this set, so several builtin types (e.g.
// Int_t, Bool_t, Float_t, etc.) have been omitted here
   PyObject* Dispatch() { return DispatchVA( 0 ); }
   PyObject* Dispatch( const char* param ) { return DispatchVA( "s", param ); }
   PyObject* Dispatch( Double_t param )    { return DispatchVA( "d", param ); }
   PyObject* Dispatch( Long_t param )      { return DispatchVA( "l", param ); }
   PyObject* Dispatch( Long64_t param )    { return DispatchVA( "L", param ); }

// further selection of pre-defined, existing dispatches
   PyObject* Dispatch( Bool_t param )      { return DispatchVA( "i", param ); }
   PyObject* Dispatch( char* param )       { return DispatchVA( "s", param ); }
   PyObject* Dispatch( const char* text, Int_t len ) { return DispatchVA( "si", text, len ); }
   PyObject* Dispatch( Int_t param )       { return DispatchVA( "i", param ); }
   PyObject* Dispatch( Int_t x, Int_t y )  { return DispatchVA( "ii", x, y ); }
   PyObject* Dispatch( ULong_t param )     { return DispatchVA( "k", param ); }
                // ULong_t also for Handle_t (and Window_t, etc. ... )

   PyObject* Dispatch( Event_t* event )    { return DispatchVA1( "Event_t", event, 0 ); }
   PyObject* Dispatch( Event_t* event, ULong_t wid ) { return DispatchVA1( "Event_t", event, "k", wid ); }
   PyObject* Dispatch( TEveDigitSet* qs, Int_t idx ) { return DispatchVA1( "TEveDigitSet", qs, "i", idx ); }
   PyObject* Dispatch( TEveElement* el )   { return DispatchVA1( "TEveElement", el, 0 ); }
   PyObject* Dispatch( TEveTrack* et )     { return DispatchVA1( "TEveTrack", et, 0 ); }
   PyObject* Dispatch( TEveWindow* window ) { return DispatchVA1( "TEveWindow", window, 0 ); }
   PyObject* Dispatch( TGFrame* frame )    { return DispatchVA1( "TGFrame", frame, 0 ); }
   PyObject* Dispatch( TGFrame* frame, Int_t btn ) {
      return DispatchVA1( "TGFrame", frame, "i", btn ); }
   PyObject* Dispatch( TGFrame* frame, Int_t btn, Int_t x, Int_t y ) {
      return DispatchVA1( "TGFrame", frame, "iii", btn, x, y ); }
   PyObject* Dispatch( TGFrame* frame, UInt_t keysym, UInt_t mask ) {
      return DispatchVA1( "TGFrame", frame, "II", keysym, mask ); }
   PyObject* Dispatch( TGListTreeItem* entry ) { return DispatchVA1( "TGListTreeItem", entry, 0 ); }
   PyObject* Dispatch( TGListTreeItem* entry, UInt_t mask ) {
      return DispatchVA1( "TGListTreeItem", entry, "I", mask ); }
   PyObject* Dispatch( TGListTreeItem* entry, UInt_t keysym, UInt_t mask ) {
      return DispatchVA1( "TGListTreeItem", entry, "II", keysym, mask ); }
   PyObject* Dispatch( TGListTreeItem* entry, Int_t btn ) {
      return DispatchVA1( "TGListTreeItem", entry, "i", btn ); }
   PyObject* Dispatch( TGListTreeItem* entry, Int_t btn, Int_t x, Int_t y ) {
      return DispatchVA1( "TGListTreeItem", entry, "iii", btn, x, y ); }
   PyObject* Dispatch( TGLVEntry* entry, Int_t btn ) {
      return DispatchVA1( "TGLVEntry", entry, "i", btn ); }
   PyObject* Dispatch( TGLVEntry* entry, Int_t btn, Int_t x, Int_t y ) {
      return DispatchVA1( "TGLVEntry", entry, "iii", btn, x, y ); }
   PyObject* Dispatch( TGLViewerBase* viewer ) {
      return DispatchVA1( "TGLViewerBase", viewer, 0 ); }
   PyObject* Dispatch( TGLPhysicalShape* shape ) {
      return DispatchVA1( "TGLPhysicalShape", shape, 0 ); }
   PyObject* Dispatch( TGLPhysicalShape* shape, UInt_t u1, UInt_t u2 ) {
      return DispatchVA1( "TGLPhysicalShape", shape, "II", u1, u2 ); }
   PyObject* Dispatch( TGMdiFrame* frame ) { return DispatchVA1( "TGMdiFrame", frame, 0 ); }
   PyObject* Dispatch( TGShutterItem* item ) { return DispatchVA1( "TGShutterItem", item, 0 ); }
   PyObject* Dispatch( TGVFileSplitter* frame ) { return DispatchVA1( "TGVFileSplitter", frame, 0 ); }
   PyObject* Dispatch( TList* objs )       { return DispatchVA1( "TList", objs, 0 ); }
   PyObject* Dispatch( TObject* obj )      { return DispatchVA1( "TObject", obj, 0 ); }
   PyObject* Dispatch( TObject* obj, Bool_t check ) {
      return DispatchVA1( "TObject", obj, "i", check ); }
   PyObject* Dispatch( TObject* obj, UInt_t state ) {
      return DispatchVA1( "TObject", obj, "I", state ); }
   PyObject* Dispatch( TObject* obj, UInt_t button, UInt_t state ) {
      return DispatchVA1( "TObject", obj, "II", button, state ); }
   PyObject* Dispatch( TSocket* sock )     { return DispatchVA1( "TSocket", sock, 0 ); }
   PyObject* Dispatch( TVirtualPad* pad )  { return DispatchVA1( "TVirtualPad", pad, 0 ); }

   PyObject* Dispatch( TPad* selpad, TObject* selected, Int_t event );
   PyObject* Dispatch( Int_t event, Int_t x, Int_t y, TObject* selected );
   PyObject* Dispatch( TVirtualPad* pad, TObject* obj, Int_t event );
   PyObject* Dispatch( TGListTreeItem* item, TDNDData* data );
   PyObject* Dispatch( const char* name, const TList* attr );

// for PROOF
   PyObject* Dispatch( const char* msg, Bool_t all ) { return DispatchVA( "si", msg, all ); }
   PyObject* Dispatch( Long64_t total, Long64_t processed ) {
      return DispatchVA( "LL", total, processed );
   }
   PyObject* Dispatch( Long64_t total, Long64_t processed, Long64_t bytesread,
                       Float_t initTime, Float_t procTime,
                       Float_t evtrti, Float_t mbrti ) {
      return DispatchVA( "LLLffff", total, processed, bytesread, initTime, procTime, evtrti, mbrti );
   }
   PyObject* Dispatch( Long64_t total, Long64_t processed, Long64_t bytesread,
                       Float_t initTime, Float_t procTime,
                       Float_t evtrti, Float_t mbrti,
                       Int_t actw, Int_t tses, Float_t eses ) {
      return DispatchVA( "LLLffffiif",
         total, processed, bytesread, initTime, procTime, evtrti, mbrti, actw, tses, eses );
   }
   PyObject* Dispatch( const char* sel, Int_t sz, Long64_t fst, Long64_t ent ) {
      return DispatchVA( "siLL", sel, sz, fst, ent );
   }
   PyObject* Dispatch( const char* msg, Bool_t status, Int_t done, Int_t total ) {
      return DispatchVA( "siii", msg, status, done, total );
   }

   PyObject* Dispatch( TSlave* slave, Long64_t total, Long64_t processed ) {
      return DispatchVA1( "TSlave", slave, "LL", total, processed );
   }
   PyObject* Dispatch( TProofProgressInfo* pi ) { return DispatchVA1( "TProofProgressInfo", pi, 0 ); }
   PyObject* Dispatch( TSlave* slave ) { return DispatchVA( "TSlave", slave, 0 ); }
   PyObject* Dispatch( TSlave* slave, TProofProgressInfo* pi );

   ClassDef( TPyDispatcher, 1 );   // Python dispatcher class

private:
   PyObject* fCallable;            //! callable object to be dispatched
};

#endif
 TPyDispatcher.h:1
 TPyDispatcher.h:2
 TPyDispatcher.h:3
 TPyDispatcher.h:4
 TPyDispatcher.h:5
 TPyDispatcher.h:6
 TPyDispatcher.h:7
 TPyDispatcher.h:8
 TPyDispatcher.h:9
 TPyDispatcher.h:10
 TPyDispatcher.h:11
 TPyDispatcher.h:12
 TPyDispatcher.h:13
 TPyDispatcher.h:14
 TPyDispatcher.h:15
 TPyDispatcher.h:16
 TPyDispatcher.h:17
 TPyDispatcher.h:18
 TPyDispatcher.h:19
 TPyDispatcher.h:20
 TPyDispatcher.h:21
 TPyDispatcher.h:22
 TPyDispatcher.h:23
 TPyDispatcher.h:24
 TPyDispatcher.h:25
 TPyDispatcher.h:26
 TPyDispatcher.h:27
 TPyDispatcher.h:28
 TPyDispatcher.h:29
 TPyDispatcher.h:30
 TPyDispatcher.h:31
 TPyDispatcher.h:32
 TPyDispatcher.h:33
 TPyDispatcher.h:34
 TPyDispatcher.h:35
 TPyDispatcher.h:36
 TPyDispatcher.h:37
 TPyDispatcher.h:38
 TPyDispatcher.h:39
 TPyDispatcher.h:40
 TPyDispatcher.h:41
 TPyDispatcher.h:42
 TPyDispatcher.h:43
 TPyDispatcher.h:44
 TPyDispatcher.h:45
 TPyDispatcher.h:46
 TPyDispatcher.h:47
 TPyDispatcher.h:48
 TPyDispatcher.h:49
 TPyDispatcher.h:50
 TPyDispatcher.h:51
 TPyDispatcher.h:52
 TPyDispatcher.h:53
 TPyDispatcher.h:54
 TPyDispatcher.h:55
 TPyDispatcher.h:56
 TPyDispatcher.h:57
 TPyDispatcher.h:58
 TPyDispatcher.h:59
 TPyDispatcher.h:60
 TPyDispatcher.h:61
 TPyDispatcher.h:62
 TPyDispatcher.h:63
 TPyDispatcher.h:64
 TPyDispatcher.h:65
 TPyDispatcher.h:66
 TPyDispatcher.h:67
 TPyDispatcher.h:68
 TPyDispatcher.h:69
 TPyDispatcher.h:70
 TPyDispatcher.h:71
 TPyDispatcher.h:72
 TPyDispatcher.h:73
 TPyDispatcher.h:74
 TPyDispatcher.h:75
 TPyDispatcher.h:76
 TPyDispatcher.h:77
 TPyDispatcher.h:78
 TPyDispatcher.h:79
 TPyDispatcher.h:80
 TPyDispatcher.h:81
 TPyDispatcher.h:82
 TPyDispatcher.h:83
 TPyDispatcher.h:84
 TPyDispatcher.h:85
 TPyDispatcher.h:86
 TPyDispatcher.h:87
 TPyDispatcher.h:88
 TPyDispatcher.h:89
 TPyDispatcher.h:90
 TPyDispatcher.h:91
 TPyDispatcher.h:92
 TPyDispatcher.h:93
 TPyDispatcher.h:94
 TPyDispatcher.h:95
 TPyDispatcher.h:96
 TPyDispatcher.h:97
 TPyDispatcher.h:98
 TPyDispatcher.h:99
 TPyDispatcher.h:100
 TPyDispatcher.h:101
 TPyDispatcher.h:102
 TPyDispatcher.h:103
 TPyDispatcher.h:104
 TPyDispatcher.h:105
 TPyDispatcher.h:106
 TPyDispatcher.h:107
 TPyDispatcher.h:108
 TPyDispatcher.h:109
 TPyDispatcher.h:110
 TPyDispatcher.h:111
 TPyDispatcher.h:112
 TPyDispatcher.h:113
 TPyDispatcher.h:114
 TPyDispatcher.h:115
 TPyDispatcher.h:116
 TPyDispatcher.h:117
 TPyDispatcher.h:118
 TPyDispatcher.h:119
 TPyDispatcher.h:120
 TPyDispatcher.h:121
 TPyDispatcher.h:122
 TPyDispatcher.h:123
 TPyDispatcher.h:124
 TPyDispatcher.h:125
 TPyDispatcher.h:126
 TPyDispatcher.h:127
 TPyDispatcher.h:128
 TPyDispatcher.h:129
 TPyDispatcher.h:130
 TPyDispatcher.h:131
 TPyDispatcher.h:132
 TPyDispatcher.h:133
 TPyDispatcher.h:134
 TPyDispatcher.h:135
 TPyDispatcher.h:136
 TPyDispatcher.h:137
 TPyDispatcher.h:138
 TPyDispatcher.h:139
 TPyDispatcher.h:140
 TPyDispatcher.h:141
 TPyDispatcher.h:142
 TPyDispatcher.h:143
 TPyDispatcher.h:144
 TPyDispatcher.h:145
 TPyDispatcher.h:146
 TPyDispatcher.h:147
 TPyDispatcher.h:148
 TPyDispatcher.h:149
 TPyDispatcher.h:150
 TPyDispatcher.h:151
 TPyDispatcher.h:152
 TPyDispatcher.h:153
 TPyDispatcher.h:154
 TPyDispatcher.h:155
 TPyDispatcher.h:156
 TPyDispatcher.h:157
 TPyDispatcher.h:158
 TPyDispatcher.h:159
 TPyDispatcher.h:160
 TPyDispatcher.h:161
 TPyDispatcher.h:162
 TPyDispatcher.h:163
 TPyDispatcher.h:164
 TPyDispatcher.h:165
 TPyDispatcher.h:166
 TPyDispatcher.h:167
 TPyDispatcher.h:168
 TPyDispatcher.h:169
 TPyDispatcher.h:170
 TPyDispatcher.h:171