]> rtime.felk.cvut.cz Git - orte.git/blob - orte/libjorte/JGetORTEConstant.c
Merge branch 'master' of https://github.com/Vajnar/orte
[orte.git] / orte / libjorte / JGetORTEConstant.c
1 /* JGetORTEConstant.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 #include <string.h>
28 /* pregenerated header */
29 #include "jorte/org_ocera_orte_tools_GetORTEConstant.h"
30 /* library header file's path */
31 #include "orte.h"
32
33 /* macro for comparing 2 strings */
34 /* if(a==b) -> strcmp = 0 */
35 #define compare(a, b) ((strcmp((const char *)(a), (const char *)(b)) == 0) ? 1 : 0)
36
37
38 /* global variables */
39 /*
40 JNIEnv    *globalJavaEnv;
41 jclass     javaClass;
42 jobj       javaObject;
43 jmethodID  globalMid;
44 */
45
46
47 /* native function - prototype declared in pregenerated header */
48 JNIEXPORT jint JNICALL
49 Java_org_ocera_tools_GetORTEConstant_getConstant
50   (JNIEnv *env, jobject jobj, jstring jname)
51 {
52   const char    *constant;
53   int            const_value = 0;
54
55   /* get the constant name from JAVA Enviromnent*/
56   constant = (*env)->GetStringUTFChars(env, jname, 0);
57
58
59
60
61   /* check if the name of the constant is correct *
62    * if yes, return the constant value            *
63    */
64
65   /* RTPS_HEADER_LENGTH */
66   #ifdef RTPS_HEADER_LENGTH
67   if (compare(constant, "RTPS_HEADER_LENGTH"))
68     const_value = RTPS_HEADER_LENGTH;
69   #endif
70
71
72   /* MAX_PATHNAME */
73   #ifdef MAX_PATHNAME
74   if (compare(constant, "MAX_PATHNAME"))
75     const_value = MAX_PATHNAME;
76   #endif
77
78
79   /* MAX_TYPENAME */
80   #ifdef MAX_TYPENAME
81   if (compare(constant, "MAX_TYPENAME"))
82     const_value = MAX_TYPENAME;
83   #endif
84
85
86   /* ORTE_TRUE */
87   #ifdef ORTE_TRUE
88   if (compare(constant, "ORTE_TRUE"))
89     const_value = ORTE_TRUE;
90   #endif
91
92
93   /* ORTE_FALSE */
94   #ifdef ORTE_FALSE
95   if (compare(constant, "ORTE_FALSE"))
96     const_value = ORTE_FALSE;
97   #endif
98
99 /*
100 HID_UNKNOWN
101
102 AID_UNKNOWN
103
104 MANAGEDAPPLICATION
105
106 MANAGER
107
108 OID_UNKNOWN
109
110 OID_APP
111
112 OID_WRITE_APPSELF
113
114
115 */
116
117
118   /* return the result value*/
119   if (const_value == 0)
120     return (-1);
121
122   return (const_value);
123
124 }
125
126
127
128 /*
129 X 10
130
131 int main(void) {
132
133 const char *c = "MAX";
134
135 #ifdef c
136  printf("je definovano \n");
137  return(1);
138 #endif
139
140  printf("neni definovano \n");
141  return(0);
142
143 }
144
145 int get_const(char *konstanta)
146 {
147 #define xxx(name) if (strcmp((const char *)konstanta, (const char*)#name)) return name
148         xxx(MAX);
149         xxx(MIN);
150 }
151
152
153 // command cpp c_file
154 // napoveda cpp
155
156 */