public inbox for frysk-cvs@sourceware.org
help / color / mirror / Atom feed
* [SCM]  master: Add JNI log methods; work-in-progress.
@ 2008-04-16  0:48 cagney
  0 siblings, 0 replies; only message in thread
From: cagney @ 2008-04-16  0:48 UTC (permalink / raw)
  To: frysk-cvs

The branch, master has been updated
       via  641ed177f921ccaa93d7086b54fe64fa3bdb5b00 (commit)
      from  4f78e3be3b50e343d6c8d84e629dc46feef29637 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email.

- Log -----------------------------------------------------------------
commit 641ed177f921ccaa93d7086b54fe64fa3bdb5b00
Author: Andrew Cagney <cagney@redhat.com>
Date:   Tue Apr 15 20:46:36 2008 -0400

    Add JNI log methods; work-in-progress.
    
    frysk-sys/frysk/rsl/ChangeLog
    2008-04-15  Andrew Cagney  <cagney@redhat.com>
    
    	* jni/Log.cxx: New.
    	* jni/Log.hxx: New.

-----------------------------------------------------------------------

Summary of changes:
 frysk-sys/frysk/rsl/ChangeLog   |    5 +
 frysk-sys/frysk/rsl/jni/Log.cxx |  159 +++++++++++++++++++++++++++++++++++++++
 frysk-sys/frysk/rsl/jni/Log.hxx |   47 ++++++++++++
 3 files changed, 211 insertions(+), 0 deletions(-)
 create mode 100644 frysk-sys/frysk/rsl/jni/Log.cxx
 create mode 100644 frysk-sys/frysk/rsl/jni/Log.hxx

First 500 lines of diff:
diff --git a/frysk-sys/frysk/rsl/ChangeLog b/frysk-sys/frysk/rsl/ChangeLog
index 353843f..60122d5 100644
--- a/frysk-sys/frysk/rsl/ChangeLog
+++ b/frysk-sys/frysk/rsl/ChangeLog
@@ -1,3 +1,8 @@
+2008-04-15  Andrew Cagney  <cagney@redhat.com>
+
+	* jni/Log.cxx: New.
+	* jni/Log.hxx: New.
+
 2008-04-04  Andrew Cagney  <cagney@redhat.com>
 
 	* Log.java: Move printing code to ...
diff --git a/frysk-sys/frysk/rsl/jni/Log.cxx b/frysk-sys/frysk/rsl/jni/Log.cxx
new file mode 100644
index 0000000..2bbaf4a
--- /dev/null
+++ b/frysk-sys/frysk/rsl/jni/Log.cxx
@@ -0,0 +1,159 @@
+// This file is part of the program FRYSK.
+//
+// Copyright 2008, Red Hat Inc.
+//
+// FRYSK is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// FRYSK is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with FRYSK; if not, write to the Free Software Foundation,
+// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+// 
+// In addition, as a special exception, Red Hat, Inc. gives You the
+// additional right to link the code of FRYSK with code not covered
+// under the GNU General Public License ("Non-GPL Code") and to
+// distribute linked combinations including the two, subject to the
+// limitations in this paragraph. Non-GPL Code permitted under this
+// exception must only link to the code of FRYSK through those well
+// defined interfaces identified in the file named EXCEPTION found in
+// the source code files (the "Approved Interfaces"). The files of
+// Non-GPL Code may instantiate templates or use macros or inline
+// functions from the Approved Interfaces without causing the
+// resulting work to be covered by the GNU General Public
+// License. Only Red Hat, Inc. may make changes or additions to the
+// list of Approved Interfaces. You must obey the GNU General Public
+// License in all respects for all of the FRYSK code and other code
+// used in conjunction with FRYSK except the Non-GPL Code covered by
+// this exception. If you modify this file, you may extend this
+// exception to your version of the file, but you are not obligated to
+// do so. If you do not wish to provide this exception without
+// modification, you must delete this exception statement from your
+// version and license this file solely under the GPL without
+// exception.
+
+#include <stdarg.h>
+#include <stdlib.h>
+
+#include <jni.h>
+
+#include "frysk/rsl/jni/Log.hxx"
+
+static bool
+logging(JNIEnv* env, jobject logger) {
+  static jmethodID loggingID = NULL;
+  if (loggingID == NULL) {
+    jclass klass = env->GetObjectClass(logger);
+    if (klass == NULL) {
+      fprintf(stderr, "frysk.rsl: failed to find logger class\n");
+      return false; // will lead to caller returning.
+    }
+    loggingID = env->GetMethodID(klass, "logging", "()B");
+    if (loggingID == NULL) {
+      fprintf(stderr, "frysk.rsl: failed to find logger method\n");
+      return false; // Just assume.
+    }
+  }
+  return env->CallBooleanMethod(logger, loggingID);
+}
+
+static jstring
+vajprintf(JNIEnv* env, const char *fmt, va_list ap) {
+  char* message = NULL;
+  if (::vasprintf(&message, fmt, ap) < 0) {
+    return NULL;
+  }
+  jstring jmessage = env->NewStringUTF(message);  
+  ::free(message);  
+  if (jmessage == NULL) {
+    return NULL;
+  }
+  return jmessage;
+}
+
+static void
+log(JNIEnv* env, jobject logger, jstring msg) {
+  static jmethodID logID = NULL;
+  if (logID == NULL) {
+    jclass klass = env->GetObjectClass(logger);
+    if (klass == NULL) {
+      fprintf(stderr, "frysk.rsl: failed to find logger class\n");
+      return; // will lead to caller returning.
+    }
+    logID = env->GetMethodID(klass, "log", "(Ljava/lang/String;)V");
+    if (logID == NULL) {
+      fprintf(stderr, "frysk.rsl: failed to find logger method\n");
+      return; // Just assume.
+    }
+  }
+  env->CallVoidMethod(logger, logID, msg);
+}
+
+void
+logf(JNIEnv *env, jobject logger, const char* format, ...) {
+  if (!logging(env, logger))
+    return;
+  va_list ap;
+  va_start(ap, format);
+  jstring message = vajprintf(env, format, ap);
+  log(env, logger, message);
+  va_end(ap);
+}
+
+void
+logf(JNIEnv *env, jobject logger, jobject object, const char* format, ...) {
+  if (!logging(env, logger))
+    return;
+  va_list ap;
+  va_start(ap, format);
+  jstring message = vajprintf(env, format, ap);
+  log(env, logger, message);
+  va_end(ap);
+}
+
+void
+log(JNIEnv *env, jobject logger, const char* p1, jobject p2) {
+  if (!logging(env, logger))
+    return;
+  static jmethodID logID = NULL;
+  if (logID == NULL) {
+    jclass klass = env->GetObjectClass(logger);
+    if (klass == NULL) {
+      fprintf(stderr, "frysk.rsl: failed to find logger class\n");
+      return; // will lead to caller returning.
+    }
+    logID = env->GetMethodID(klass, "log",
+			     "(Ljava/lang/String;Ljava/lang/Object;)V");
+    if (logID == NULL) {
+      fprintf(stderr, "frysk.rsl: failed to find logger method\n");
+      return; // Just assume.
+    }
+  }
+  env->CallVoidMethod(logger, logID, env->NewStringUTF(p1), p2);
+}
+
+void
+log(JNIEnv *env, jobject logger, jobject self, const char* p1, jobject p2) {
+  if (!logging(env, logger))
+    return;
+  static jmethodID logID = NULL;
+  if (logID == NULL) {
+    jclass klass = env->GetObjectClass(logger);
+    if (klass == NULL) {
+      fprintf(stderr, "frysk.rsl: failed to find logger class\n");
+      return; // will lead to caller returning.
+    }
+    logID = env->GetMethodID(klass, "log",
+			     "(Ljava/lang/Object;Ljava/lang/String;Ljava/lang/Object;)V");
+    if (logID == NULL) {
+      fprintf(stderr, "frysk.rsl: failed to find logger method\n");
+      return; // Just assume.
+    }
+  }
+  env->CallVoidMethod(logger, logID, self, env->NewStringUTF(p1), p2);
+}
diff --git a/frysk-sys/frysk/rsl/jni/Log.hxx b/frysk-sys/frysk/rsl/jni/Log.hxx
new file mode 100644
index 0000000..7174bf2
--- /dev/null
+++ b/frysk-sys/frysk/rsl/jni/Log.hxx
@@ -0,0 +1,47 @@
+// This file is part of the program FRYSK.
+//
+// Copyright 2008, Red Hat Inc.
+//
+// FRYSK is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by
+// the Free Software Foundation; version 2 of the License.
+//
+// FRYSK is distributed in the hope that it will be useful, but
+// WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+// 
+// You should have received a copy of the GNU General Public License
+// along with FRYSK; if not, write to the Free Software Foundation,
+// Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+// 
+// In addition, as a special exception, Red Hat, Inc. gives You the
+// additional right to link the code of FRYSK with code not covered
+// under the GNU General Public License ("Non-GPL Code") and to
+// distribute linked combinations including the two, subject to the
+// limitations in this paragraph. Non-GPL Code permitted under this
+// exception must only link to the code of FRYSK through those well
+// defined interfaces identified in the file named EXCEPTION found in
+// the source code files (the "Approved Interfaces"). The files of
+// Non-GPL Code may instantiate templates or use macros or inline
+// functions from the Approved Interfaces without causing the
+// resulting work to be covered by the GNU General Public
+// License. Only Red Hat, Inc. may make changes or additions to the
+// list of Approved Interfaces. You must obey the GNU General Public
+// License in all respects for all of the FRYSK code and other code
+// used in conjunction with FRYSK except the Non-GPL Code covered by
+// this exception. If you modify this file, you may extend this
+// exception to your version of the file, but you are not obligated to
+// do so. If you do not wish to provide this exception without
+// modification, you must delete this exception statement from your
+// version and license this file solely under the GPL without
+// exception.
+
+extern void logf(jobject, const char*, ...)
+  __attribute__((format(printf, 2, 3)));
+
+extern void logf(jobject, jobject, const char*, ...)
+  __attribute__((format(printf, 3, 4)));
+
+extern void log(jobject, const char*, jobject);
+extern void log(jobject, jobject, const char*, jobject);


hooks/post-receive
--
frysk system monitor/debugger


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2008-04-16  0:48 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-04-16  0:48 [SCM] master: Add JNI log methods; work-in-progress cagney

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).