]> rtime.felk.cvut.cz Git - orte.git/blob - orte/libjorte/JNtpTimeToStringMs.c
Reformat the sources with orte/uncrustify script
[orte.git] / orte / libjorte / JNtpTimeToStringMs.c
1 /* JNtpTimeToStringMs.c */
2 /**
3   * This code provides conversion between JAVA a C environments.
4   * The C functions are calling here and results are send to JAVA
5   * native functions. It uses the header pregenerated by JAVA
6   * (by command 'javah -jni class_with_native_function')
7   *
8   * @author Lukas Pokorny (lukas_pokorny@centrum.cz)
9   * @author CTU FEE Prague - Department of Control Engineering (dce.felk.cvut.cz)
10   * @author Project ORTE - OCERA Real Time Ethernet (www.ocera.org)
11   * @author dedication to Kj
12   * @version 0.1
13   *
14   *
15   * This program is free software; you can redistribute it and/or modify
16   * it under the terms of the GNU General Public License as published by
17   * the Free Software Foundation; either version 2 of the License, or
18   * (at your option) any later version.
19   *
20   * This program is distributed in the hope that it will be useful,
21   * but WITHOUT ANY WARRANTY; without even the implied warranty of
22   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23   * GNU General Public License for more details.
24   *
25   */
26
27
28 // origin orte headers
29 #include "orte.h"
30 // pregenerated header
31 #include "jorte/org_ocera_orte_types_NtpTime.h"
32
33
34
35 /* native function - prototype declared in pregenerated header */
36 JNIEXPORT jstring JNICALL
37 Java_org_ocera_orte_types_NtpTime_NtpTimeToStringMs
38   (JNIEnv *env, jclass class, jobject j_ntpTime)
39 {
40   char             buff[65];  // 32 + 32 + 1 end char
41   NtpTime          time;
42   jfieldID         fieldID;
43   jclass           ntpTimeClass;
44
45
46   // NtpTime - get object's class
47   ntpTimeClass = (*env)->GetObjectClass(env, j_ntpTime);
48
49   // seconds - get object field ID
50   fieldID = (*env)->GetFieldID(env, ntpTimeClass, "seconds", "I");
51   if (fieldID == NULL)
52     return((*env)->NewStringUTF(env, "error when reading Java-ntpTime"));
53   // get objects value
54   time.seconds = (int32_t)(*env)->GetIntField(env, j_ntpTime, fieldID);
55
56   // reset pointer
57   fieldID = NULL;
58
59   // fraction - get object field ID
60   fieldID = (*env)->GetFieldID(env, ntpTimeClass, "fraction", "J");
61   if (fieldID == NULL)
62     return((*env)->NewStringUTF(env, "error when reading Java-ntpTime"));
63   // get object's value
64   time.fraction = (uint32_t)(*env)->GetLongField(env, j_ntpTime, fieldID);
65
66   // calling original liborte function
67   NtpTimeToStringMs(time, buff);
68   // return result of the conversion
69   return((*env)->NewStringUTF(env, buff));
70 }