7f2debb2 |
1 | // Copyright (c) 2014 OPEN CASCADE SAS |
2 | // |
3 | // This file is part of Open CASCADE Technology software library. |
4 | // |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
10 | // |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
13 | |
14 | #include <OcctJni_MsgPrinter.hxx> |
15 | |
16 | #include <TCollection_AsciiString.hxx> |
17 | #include <TCollection_ExtendedString.hxx> |
18 | |
19 | #include <android/log.h> |
20 | |
7f2debb2 |
21 | IMPLEMENT_STANDARD_RTTIEXT(OcctJni_MsgPrinter, Message_Printer) |
22 | |
23 | // ======================================================================= |
24 | // function : OcctJni_MsgPrinter |
25 | // purpose : |
26 | // ======================================================================= |
27 | OcctJni_MsgPrinter::OcctJni_MsgPrinter (JNIEnv* theJEnv, |
28 | jobject theJObj) |
29 | : myJEnv (theJEnv), |
30 | myJObj (theJEnv->NewGlobalRef (theJObj)), |
31 | myJMet (NULL) |
32 | { |
33 | jclass aJClass = theJEnv->GetObjectClass (theJObj); |
34 | myJMet = theJEnv->GetMethodID (aJClass, "postMessage", "(Ljava/lang/String;)V"); |
35 | if (myJMet == NULL) |
36 | { |
37 | __android_log_write (ANDROID_LOG_FATAL, "jniSample", "Broken initialization of OcctJni_MsgPrinter!"); |
38 | } |
39 | } |
40 | |
41 | // ======================================================================= |
42 | // function : ~OcctJni_MsgPrinter |
43 | // purpose : |
44 | // ======================================================================= |
45 | OcctJni_MsgPrinter::~OcctJni_MsgPrinter() |
46 | { |
47 | //myJEnv->DeleteGlobalRef (myJObj); |
48 | } |
49 | |
50 | // ======================================================================= |
51 | // function : Send |
52 | // purpose : |
53 | // ======================================================================= |
54 | void OcctJni_MsgPrinter::Send (const TCollection_ExtendedString& theString, |
55 | const Message_Gravity theGravity, |
56 | const Standard_Boolean theToPutEndl) const |
57 | { |
58 | if (theGravity >= myTraceLevel) |
59 | { |
60 | const TCollection_AsciiString aStr (theString); |
61 | OcctJni_MsgPrinter::Send (aStr, theGravity, theToPutEndl); |
62 | } |
63 | } |
64 | |
65 | // ======================================================================= |
66 | // function : Send |
67 | // purpose : |
68 | // ======================================================================= |
69 | void OcctJni_MsgPrinter::Send (const TCollection_AsciiString& theString, |
70 | const Message_Gravity theGravity, |
71 | const Standard_Boolean theToPutEndl) const |
72 | { |
73 | if (theGravity < myTraceLevel) |
74 | { |
75 | return; |
76 | } |
77 | |
78 | ///__android_log_write (ANDROID_LOG_DEBUG, "OcctJni_MsgPrinter", (TCollection_AsciiString(" @@ ") + theString).ToCString()); |
79 | if (myJMet == NULL) |
80 | { |
81 | return; |
82 | } |
83 | |
84 | jstring aJStr = myJEnv->NewStringUTF ((theString + "\n").ToCString()); |
85 | myJEnv->CallObjectMethod (myJObj, myJMet, aJStr); |
86 | myJEnv->DeleteLocalRef (aJStr); |
87 | } |
88 | |
89 | // ======================================================================= |
90 | // function : Send |
91 | // purpose : |
92 | // ======================================================================= |
93 | void OcctJni_MsgPrinter::Send (const Standard_CString& theString, |
94 | const Message_Gravity theGravity, |
95 | const Standard_Boolean theToPutEndl) const |
96 | { |
97 | if (theGravity >= myTraceLevel) |
98 | { |
99 | OcctJni_MsgPrinter::Send (TCollection_AsciiString (theString), theGravity, theToPutEndl); |
100 | } |
101 | } |