12 madara::filters::JavaBufferFilter::JavaBufferFilter (
21 "JavaBufferFilter::constructor:" \
22 " allocating global reference for object\n");
24 obj_ = (jobject)jvm.
env->NewGlobalRef (obj);
29 "JavaBufferFilter::constructor:" \
30 " allocating global reference for object's class\n");
32 class_ = (jclass)jvm.
env->NewGlobalRef (jvm.
env->GetObjectClass (obj_));
36 "JavaBufferFilter::constructor:" \
37 " class and object obtained successfully\n");
42 "JavaBufferFilter::constructor:" \
43 " ERROR: class object inaccessible\n");
49 "JavaBufferFilter::constructor:" \
50 " ERROR: object is invalid\n");
56 "JavaBufferFilter::constructor:" \
57 " ERROR: unable to acquire JAVA environment\n");
62 madara::filters::JavaBufferFilter::~JavaBufferFilter ()
68 "JavaBufferFilter::destructor:" \
69 " Deleting global references\n");
71 jvm.
env->DeleteGlobalRef (obj_);
72 jvm.
env->DeleteGlobalRef (class_);
77 madara::filters::JavaBufferFilter::encode (
78 unsigned char * source,
int size,
int max_size)
const 84 "JavaBufferFilter::encode:" \
85 " Obtaining user-defined encode method\n");
87 jmethodID call = jvm.
env->GetMethodID (class_,
"encode",
"([BJJ)J");
92 "JavaBufferFilter::encode:" \
93 " Creating a Java byte array and copying values\n");
97 jbyteArray new_array = jvm.
env->NewByteArray (max_size);
98 void * data = jvm.
env->GetPrimitiveArrayCritical ((jarray)new_array, &isCopy);
101 memcpy (data, source, (
size_t)size);
104 "JavaBufferFilter::encode:" \
105 " Calling user-defined encode method\n");
106 result = jvm.
env->CallIntMethod (obj_, call, new_array, size, max_size);
109 "JavaBufferFilter::encode:" \
110 " Copying values from java byte array to the C buffer\n");
113 memcpy (source, data, (
size_t)result);
116 "JavaBufferFilter::encode:" \
117 " Deleting local Java variables\n");
120 jvm.
env->ReleaseByteArrayElements (new_array, (jbyte *)data, JNI_ABORT);
121 jvm.
env->DeleteLocalRef (new_array);
126 "JavaBufferFilter::encode:" \
127 " ERROR: Unable to find user-defined encode method\n");
134 madara::filters::JavaBufferFilter::decode (
135 unsigned char * source,
int size,
int max_size)
const 141 "JavaBufferFilter::decode:" \
142 " Obtaining user-defined decode method\n");
144 jmethodID call = jvm.
env->GetMethodID (class_,
"decode",
"([BJJ)J");
149 "JavaBufferFilter::decode:" \
150 " Creating a Java byte array and copying values\n");
154 jbyteArray new_array = jvm.
env->NewByteArray (max_size);
155 void * data = jvm.
env->GetPrimitiveArrayCritical ((jarray)new_array, &isCopy);
158 "JavaBufferFilter::decode:" \
159 " Copying values from java byte array to the C buffer\n");
162 memcpy (data, source, (
size_t)size);
165 "JavaBufferFilter::decode:" \
166 " Calling user-defined decode method\n");
167 result = jvm.
env->CallIntMethod (obj_, call, new_array, size, max_size);
170 memcpy (source, data, (
size_t)result);
173 "JavaBufferFilter::decode:" \
174 " Deleting local Java variables\n");
177 jvm.
env->ReleaseByteArrayElements (new_array, (jbyte *)data, JNI_ABORT);
178 jvm.
env->DeleteLocalRef (new_array);
183 "JavaBufferFilter::decode:" \
184 " ERROR: Unable to find user-defined decode method\n");
190 #endif // _MADARA_JAVA_ JNIEnv * env
The Java environment.
This class encapsulates attaching and detaching to a VM.
Provides knowledge logging services to files and terminals.
A multi-threaded logger for logging to one or more destinations.
#define madara_logger_ptr_log(logger, level,...)
Fast version of the madara::logger::log method for Logger pointers.