]> rtime.felk.cvut.cz Git - orte.git/blob - orte/libjorte/JGetORTEConstant.c
6c2be0a0c773c180d80fcf67a8ed01e015a2797b
[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) return (-1);
120
121   return (const_value);
122
123 }
124
125
126
127 /*
128 X 10
129
130 int main(void) {
131
132 const char *c = "MAX";
133
134 #ifdef c
135  printf("je definovano \n");
136  return(1);
137 #endif
138
139  printf("neni definovano \n");
140  return(0);
141
142 }
143
144 int get_const(char *konstanta)
145 {
146 #define xxx(name) if (strcmp((const char *)konstanta, (const char*)#name)) return name
147         xxx(MAX);
148         xxx(MIN);
149 }
150
151
152 // command cpp c_file
153 // napoveda cpp
154
155 */
156
157
158
159