You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by bh...@apache.org on 2014/07/30 21:06:22 UTC

[05/38] git commit: BB10: Setup slog2 for logging and add some basic logging.

BB10: Setup slog2 for logging and add some basic logging.


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/commit/f9abc8b8
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/tree/f9abc8b8
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/diff/f9abc8b8

Branch: refs/heads/lyon-g11n
Commit: f9abc8b8a4d84c30c5099f23ac1dc24881cd707e
Parents: bdaf847
Author: Lianghui Chen <li...@blackberry.com>
Authored: Wed Jul 23 10:34:51 2014 -0400
Committer: Lianghui Chen <li...@blackberry.com>
Committed: Mon Jul 28 15:10:45 2014 -0400

----------------------------------------------------------------------
 .../native/src/globalization_js.cpp             | 47 ++++++++++++++++++++
 1 file changed, 47 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-globalization/blob/f9abc8b8/src/blackberry10/native/src/globalization_js.cpp
----------------------------------------------------------------------
diff --git a/src/blackberry10/native/src/globalization_js.cpp b/src/blackberry10/native/src/globalization_js.cpp
index a40b44e..a496a1d 100644
--- a/src/blackberry10/native/src/globalization_js.cpp
+++ b/src/blackberry10/native/src/globalization_js.cpp
@@ -15,11 +15,51 @@
  */
 
 #include <string>
+#include <sys/slog2.h>
 #include "globalization_js.hpp"
 #include "globalization_ndk.hpp"
 
 using namespace std;
 
+// This can be any 16 bit integer value. It is used only for our own
+// logs identification when calling slog2f().
+const unsigned short ID_G11N = 22549;
+
+void setupLogging()
+{
+    static bool inited = false;
+
+    if (inited)
+        return;
+
+    inited = true;
+
+    // Reset the log buffers in case this is after a fork. (If there were no log buffers, this does
+    // nothing.)
+    int rc = slog2_reset();
+    if (rc < 0) {
+        fprintf(stderr, "Globalization: Error resetting slog2 buffer!\n");
+        return;
+    }
+
+    // Set up default slog2 buffer
+    slog2_buffer_set_config_t bufferConfigSet;
+    bufferConfigSet.buffer_set_name = "Globalization";
+    bufferConfigSet.num_buffers = 1;
+    bufferConfigSet.verbosity_level = SLOG2_INFO;
+    bufferConfigSet.buffer_config[0].buffer_name = "default";
+    bufferConfigSet.buffer_config[0].num_pages = 8;
+
+    slog2_buffer_t bufferHandle;
+    rc = slog2_register(&bufferConfigSet, &bufferHandle, 0);
+    if (rc < 0) {
+        fprintf(stderr, "Globalization: Error registering slogger2 buffer!\n");
+        return;
+    }
+
+    slog2_set_default_buffer(bufferHandle);
+}
+
 /**
  * Default constructor.
  */
@@ -50,6 +90,11 @@ char* onGetObjList() {
  * an object is created on the JavaScript server side.
  */
 JSExt* onCreateObject(const string& className, const string& id) {
+	setupLogging();
+
+	slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationJS::onCreateObject(%s, %s)",
+			className.c_str(), id.c_str());
+
 	if (className == "Globalization") {
 		return new GlobalizationJS(id);
 	}
@@ -71,6 +116,8 @@ bool GlobalizationJS::CanDelete() {
  * called on the JavaScript side with this native objects id.
  */
 string GlobalizationJS::InvokeMethod(const string& command) {
+	slog2f(0, ID_G11N, SLOG2_ERROR, "GlobalizationJS::InvokeMethod(%s)", command.c_str());
+
 	// format must be: "command callbackId params"
 	size_t commandIndex = command.find_first_of(" ");
 	std::string strCommand = command.substr(0, commandIndex);