0031501: Foundation Classes, Message_Printer - remove theToPutEndl argument
[occt.git] / samples / java / jniviewer / jni / OcctJni_MsgPrinter.cxx
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
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_AsciiString& theString,
55                                const Message_Gravity theGravity) const
56 {
57   if (theGravity < myTraceLevel)
58   {
59     return;
60   }
61
62   ///__android_log_write (ANDROID_LOG_DEBUG, "OcctJni_MsgPrinter", (TCollection_AsciiString(" @@ ") + theString).ToCString());
63   if (myJMet == NULL)
64   {
65     return;
66   }
67
68   jstring aJStr = myJEnv->NewStringUTF ((theString + "\n").ToCString());
69   myJEnv->CallObjectMethod (myJObj, myJMet, aJStr);
70   myJEnv->DeleteLocalRef (aJStr);
71 }