List:NDB Connectors« Previous MessageNext Message »
From:Monty Taylor Date:September 17 2007 2:40am
Subject:Rev 156: Some work to get the Event Callback stuff working. Of course, I can't find anything that uses it... in http://bazaar.launchpad.net/~ndb-conn...
View as plain text  
At http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/ndbjmerge

------------------------------------------------------------
revno: 156
revision-id: mtaylor@stripped
parent: mtaylor@stripped
committer: Monty Taylor <mtaylor@stripped>
branch nick: ndbjmerge
timestamp: Mon 2007-09-17 04:39:35 +0200
message:
  Some work to get the Event Callback stuff working. Of course, I can't find anything that
uses it... 
added:
  java/com/mysql/cluster/ndbj/INdbEventCallable.java
indbeventcallable.ja-20070917023819-swpmhdhl7jsponid-1
modified:
  java/ndbj.i                    ndbj.i-20070913223244-5938mztpztyn9sry-1
  swig/ndbglobals.i              globals.i-20070228021421-qkr4cbpxymyqdrf3-7
=== added file 'java/com/mysql/cluster/ndbj/INdbEventCallable.java'
--- a/java/com/mysql/cluster/ndbj/INdbEventCallable.java	1970-01-01 00:00:00 +0000
+++ b/java/com/mysql/cluster/ndbj/INdbEventCallable.java	2007-09-17 02:39:35 +0000
@@ -0,0 +1,8 @@
+package com.mysql.cluster.ndbj;
+
+
+public interface INdbEventCallable { 
+
+  void callback(NdbEventOperation theOp, Ndb theNdb);
+
+};

=== modified file 'java/ndbj.i'
--- a/java/ndbj.i	2007-09-17 02:16:25 +0000
+++ b/java/ndbj.i	2007-09-17 02:39:35 +0000
@@ -59,6 +59,14 @@
   jobject obj; 
 };
 
+typedef struct
+event_callback_t
+{  
+  JNIEnv *env; 
+  jobject obj; 
+};
+
+
 static void JavaCallBack(int result,
                      NdbTransaction *trans,
                      void *aObject)
@@ -76,7 +84,28 @@
     env->ThrowNew(clazz,"No callback method!");
   }
 
-  env->CallVoidMethod(callback_data->obj,mid,trans,(jlong)result);
+  env->CallVoidMethod(callback_data->obj,mid,(jlong)result,trans);
+
+}
+
+static void EventCallBack(NdbEventOperation *theOp,
+                     Ndb *theNdb,
+                     void *aObject)
+{
+
+  event_callback_t * callback_data = (event_callback_t *)aObject;
+
+  JNIEnv *env = callback_data->env; 
+
+  jclass callablecls = env->GetObjectClass((callback_data->obj));
+
+  jmethodID mid = env->GetMethodID(callablecls, "callback", "(ILNdb;)V");
+  if (mid == NULL) { 
+    jclass clazz = env->FindClass("java/lang/RuntimeException");
+    env->ThrowNew(clazz,"No callback method!");
+  }
+
+  env->CallVoidMethod(callback_data->obj,mid,theOp,theNdb);
 
 }
 
@@ -107,15 +136,25 @@
     $1 = callback_data;
  %}
 
+%typemap(in) event_callback_t * cb
+%{ 
+  event_callback_t * callback_data; 
+    callback_data = new event_callback_t;
+    callback_data->env = jenv; 
+    callback_data->obj = $input;
+    
+    $1 = callback_data;
+ %}
+
 %typemap(jni) asynch_callback_t * "jobject" 
 %typemap(jtype) asynch_callback_t * "Object"
 %typemap(jstype) asynch_callback_t * "INdbCallable"
 %typemap(javain) asynch_callback_t * "(Object)$javainput"
 
-/*%typemap(javaimports) NdbFactory, Ndb, Ndb_cluster_connection, NdbTransaction,
NdbOperation, NdbIndexOperation, NdbScanOperation, NdbIndexScanOperation, NdbBlob,
NdbDictDictionary, NdbDictColumn, NdbDictIndex, NdbDictTable, NdbDictObject,
NdbScanFilter, NdbEvent, NdbEventOperation, NdbRecAttr "import
com.mysql.cluster.errors.*;"
-%pragma(java) moduleimports="import com.mysql.cluster.errors.*;"
-%pragma(java) jniclassimports="import com.mysql.cluster.errors.*;"
-*/
+%typemap(jni) event_callback_t * "jobject" 
+%typemap(jtype) event_callback_t * "Object"
+%typemap(jstype) event_callback_t * "INdbEventCallable"
+%typemap(javain) event_callback_t * "(Object)$javainput"
 
 %typemap(jni) MYSQL_TIME * "jobject"
 %typemap(jtype) MYSQL_TIME * "Object"

=== modified file 'swig/ndbglobals.i'
--- a/swig/ndbglobals.i	2007-09-17 02:16:25 +0000
+++ b/swig/ndbglobals.i	2007-09-17 02:39:35 +0000
@@ -41,7 +41,25 @@
     BaseCallback * cb = (BaseCallback *)anyObject;
     cb->callback(ret, trans);
   }
-  
+
+  class BaseEventCallback {
+
+    public: 
+      virtual ~BaseEventCallback() {};
+      virtual void callback(NdbEventOperation *theOp, Ndb *theNdb) {
+        printf("In BaseEventCallback::callback.\n\tOperation: %p\n\tNdb: %p\n",
+               theOp,theNdb);
+    }
+  };
+
+
+  void theNdbEventCallback(NdbEventOperation * theOp, Ndb * theNdb, void * anyObject) { 
+    BaseEventCallback * cb = (BaseEventCallback *)anyObject;
+    cb->callback(theOp,theNdb);
+  }
+
+
+
 typedef Uint32 NdbTimestamp;
 
 typedef NdbDictionary::Object NdbDictObject;
@@ -99,6 +117,7 @@
 };
 
 typedef void (* NdbAsynchCallback)(int, NdbTransaction*, void*);
+typedef void (* NdbEventCallback)(NdbEventOperation*, Ndb*, void*);
 
 typedef const char * NdbDatetime;
 typedef const char * NdbDate;
@@ -114,3 +133,13 @@
   virtual void callback(int res, NdbTransaction * trans);
   
 };
+
+%feature("director") BaseEventCallback;
+
+class BaseEventCallback {
+
+  public:
+    virtual ~BaseEventCallback() {};
+    virtual void callback(NdbEventOperation *theOp, Ndb *theNdb);
+};
+

Thread
Rev 156: Some work to get the Event Callback stuff working. Of course, I can't find anything that uses it... in http://bazaar.launchpad.net/~ndb-conn...Monty Taylor18 Sep