List:NDB Connectors« Previous MessageNext Message »
From:Monty Taylor Date:November 18 2007 1:07am
Subject:Rev 262: Fixed return codes/errors for getLogEvent for Java. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/devel
View as plain text  
At http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/devel

------------------------------------------------------------
revno: 262
revision-id: mtaylor@stripped
parent: mtaylor@stripped
committer: Monty Taylor <mtaylor@stripped>
branch nick: devel
timestamp: Sat 2007-11-17 17:00:39 -0800
message:
  Fixed return codes/errors for getLogEvent for Java.
modified:
  interface/mgmapi/NdbLogEvent.i ndblogevent.i-20070906065931-8drgzkovsy4cdn0b-1
  interface/mgmapi/NdbLogEventManager.i
ndbmgmlogeventhandle-20070906065939-pj4qrhof8kkzg3d1-1
  java/mgmj.i                    mgmapi.i-20070415064013-80k9rsqzumm2kjaf-1
=== modified file 'interface/mgmapi/NdbLogEvent.i'
--- a/interface/mgmapi/NdbLogEvent.i	2007-11-17 21:15:41 +0000
+++ b/interface/mgmapi/NdbLogEvent.i	2007-11-18 01:00:39 +0000
@@ -83,6 +83,7 @@
 
 %inline %{
 
+
   class BaseEvent { 
   protected: 
     BaseEvent(); 
@@ -90,6 +91,7 @@
   };
 
 
+
   class ConnectedEvent : public BaseEvent { 
   public:
     ConnectedEvent(ndb_logevent theEvent) { 
@@ -925,3 +927,12 @@
 
 
   %}
+
+%{
+
+  struct BaseEventWrapper { 
+    int ret; 
+    BaseEvent * theEvent; 
+  };
+
+  %}

=== modified file 'interface/mgmapi/NdbLogEventManager.i'
--- a/interface/mgmapi/NdbLogEventManager.i	2007-11-17 20:11:59 +0000
+++ b/interface/mgmapi/NdbLogEventManager.i	2007-11-18 01:00:39 +0000
@@ -43,20 +43,20 @@
     virtual void handleEvent(ndb_logevent * event) {}
     virtual Ndb_logevent_type getEventType() { return NDB_LE_ILLEGAL_TYPE; } 
   };
-
+  
   class NdbLogEventManager { 
-
+    
     ndb_logevent_handle * handle; 
-
+    
     std::map<Ndb_logevent_type,std::vector<NdbLogEventTypeListener *> >
evtListeners; 
     std::map<ndb_mgm_event_category,std::vector<NdbLogEventCategoryListener *>
> evtCategoryListeners;
-
+    
   public: 
-
+    
     NdbLogEventManager(ndb_logevent_handle * theHandle) { 
       this->handle=theHandle;
     }
-
+    
     // Returns -1 on error, 0 otherwise
     int registerListener(NdbLogEventTypeListener * listener) { 
       Ndb_logevent_type theType = listener->getEventType();
@@ -68,7 +68,7 @@
 	evtVec = evtListeners.at(theType);
       } catch (std::out_of_range e) { 
 	if
(!(evtListeners.insert(std::make_pair<Ndb_logevent_type,std::vector<NdbLogEventTypeListener
*> >(theType,evtVec))).second) { 
-	    return -1;
+	  return -1;
 	}
       }; 
       evtVec.push_back(listener);
@@ -97,62 +97,60 @@
       return 0;
     }
     
-
-  BaseEvent * getLogEvent(unsigned timeout_in_milliseconds) { 
-
-    //TODO: replace malloc with a pinned byte-array, until get_next_event()
-    // is called, then unpin it
-
-    /*ndb_logevent* event = (ndb_logevent*) malloc (sizeof(ndb_logevent));
-    if (event==0) { 
-      return NULL; 
-      }*/
-    ndb_logevent event; 
-
-    //int r= ndb_logevent_get_next(handle,&(*event),timeout_in_milliseconds);
-    int r= ndb_logevent_get_next(handle,&event,timeout_in_milliseconds);
-
-    BaseEvent * theEvent = NULL;
-    //TODO: Figure out how to deal with no event properly
-    if (r<=0) { 
-      //free(event);
-      return NULL;
-    }
-    
-    switch(event.type) { 
-    case NDB_LE_Connected:
-      theEvent = (BaseEvent *)(new ConnectedEvent(event));
-      break;
-    default:
-      break;
-    }
-    // r > 0, event exists; 
-    // r==0, no event (timeout)
-    // r==-1, error
-
-    
-    return theEvent; 
-
-  }
+    
+    BaseEventWrapper * getLogEvent(unsigned timeout_in_milliseconds) { 
+      
+      //TODO: replace malloc with a pinned byte-array, until get_next_event()
+      // is called, then unpin it
+      
+      /*ndb_logevent* event = (ndb_logevent*) malloc (sizeof(ndb_logevent));
+	if (event==0) { 
+	return NULL; 
+	}*/
+      ndb_logevent event; 
+      BaseEventWrapper * eventWrapper = (BaseEventWrapper
*)malloc(sizeof(BaseEventWrapper)); 
+      
+      //int r= ndb_logevent_get_next(handle,&(*event),timeout_in_milliseconds);
+      eventWrapper->ret =
ndb_logevent_get_next(handle,&event,timeout_in_milliseconds);
+      
+      eventWrapper->theEvent = NULL;
+      //TODO: Figure out how to deal with no event properly
+      if (eventWrapper->ret > 0) { 
+	
+	switch(event.type) { 
+	case NDB_LE_Connected:
+	  eventWrapper->theEvent = (BaseEvent *)(new ConnectedEvent(event));
+	  break;
+	default:
+	  break;
+	}
+	// r > 0, event exists; 
+	// r==0, no event (timeout)
+	// r==-1, error
+	
+      }    
+      return eventWrapper; 
+    
+    }  
   };
-
-
-  /**
-   * Attempt to retrieve next log event and will fill in the supplied
-   * struct dst
-   *
-   * @param dst Pointer to struct to fill in event information
-   * @param timeout_in_milliseconds Timeout for waiting for event
-   *
-   * @return     >0 if event exists, 0 no event (timed out), or -1 on error.
-   *
-   * @note Return value <=0 will leave dst untouched
-   */
+    
+
+    /**
+     * Attempt to retrieve next log event and will fill in the supplied
+     * struct dst
+     *
+     * @param dst Pointer to struct to fill in event information
+     * @param timeout_in_milliseconds Timeout for waiting for event
+     *
+     * @return     >0 if event exists, 0 no event (timed out), or -1 on error.
+     *
+     * @note Return value <=0 will leave dst untouched
+     */
 /*  int getNext(ndb_logevent *dst,
-	      unsigned timeout_in_milliseconds) { 
+    unsigned timeout_in_milliseconds) { 
     return ndb_logevent_get_next($self, dst, timeout_in_milliseconds);
     }*/
-		    
+    
 
     %}
 
@@ -190,8 +188,14 @@
   int registerListener(NdbLogEventTypeListener * listener);   
   bool unregisterListener(NdbLogEventTypeListener * listener);
   int registerCategoryListener(NdbLogEventCategoryListener * listener);
-  BaseEvent * getLogEvent(unsigned timeout_in_milliseconds);
-  
+  %ndbexception("MgmApiException") { 
+    $action
+      if (result->ret < 0) { 
+	NDB_exception(NdbApiException,"Error fetching ndb_logevent object!");
+      }
+  }
+  BaseEventWrapper * getLogEvent(unsigned timeout_in_milliseconds);
+  %ndbnoexception; 
 };
   
 

=== modified file 'java/mgmj.i'
--- a/java/mgmj.i	2007-11-06 22:59:00 +0000
+++ b/java/mgmj.i	2007-11-18 01:00:39 +0000
@@ -27,6 +27,7 @@
 */
 
 %{
+
 #define NDB_exception(excp, msg) { ndb_throw_exception(jenv, #excp, msg);  } 
 
 void ndb_throw_exception(JNIEnv *jenv, const char * excp, const char *msg) { 
@@ -41,6 +42,18 @@
 }
 %}
 
+%typemap(out) (BaseEventWrapper *) {
+  $result=$1->theEvent; 
+ } 
+//%typemap(jtype) (BaseEventWrapper *) "BaseEvent";
+%typemap(jstype) (BaseEventWrapper *) "BaseEvent";
+%typemap(jni) (BaseEventWrapper *) "BaseEvent *";
+
+%typemap(javaout) (BaseEventWrapper *) { 
+  long cPtr = $jnicall; 
+  return (cPtr == 0) ? null :  new BaseEvent(cPtr,true);
+ }
+%typemap(newfree) (BaseEventWrapper *) "free($1);";
 /*
 %rename NdbMgmLogEventManager NdbMgmLogEventManagerRef;
 %rename NdbMgmReply NdbMgmReplyRef;

Thread
Rev 262: Fixed return codes/errors for getLogEvent for Java. in http://bazaar.launchpad.net/~ndb-connectors/ndb-connectors/develMonty Taylor18 Nov