1 /***********************************************************************/
2 /* Open Visualization Data Explorer                                    */
3 /* (C) Copyright IBM Corp. 1989,1999                                   */
4 /* ALL RIGHTS RESERVED                                                 */
5 /* This code licensed under the                                        */
6 /*    "IBM PUBLIC LICENSE - Open Visualization Data Explorer"          */
7 /***********************************************************************/
8 
9 #include <dxconfig.h>
10 #include "../base/defines.h"
11 
12 
13 #if defined(HAVE_MALLOC_H)
14 #include <malloc.h>
15 #endif
16 #include <string.h>
17 
18 #include "dxlP.h"
19 
20 DXLError
DXLSync(DXLConnection * conn)21 DXLSync(DXLConnection *conn)
22 {
23     DXLError r;
24 
25     if (conn->syncing)
26         return OK;
27 
28     conn->syncing = 1;
29     if (conn->dxuiConnected) {
30         r = DXLQuery(conn, "query sync", 0, NULL) >= 0 ? OK : ERROR;
31     } else {
32 	DXLEvent event;
33 	r = ERROR;
34 	/* FIXME: we really need to fix DXLQuery() for the exec. */
35         r = DXLSendImmediate(conn,"sync");
36 	if (r) {
37 	    int packetId = DXLSendPacket(conn, PACK_FOREGROUND,
38 					"Executive(\"nop\");\n");
39             r = (packetId >= 0) && DXLGetPacketId(conn, PACK_COMPLETE,
40                                                         packetId,  &event);
41 	    if (r)
42 		DXLClearEvent(&event);
43 	}
44     }
45 
46     conn->syncing = 0;
47     return r;
48 
49 }
50 DXLError
uiDXLSyncExecutive(DXLConnection * conn)51 uiDXLSyncExecutive(DXLConnection *conn)
52 {
53     DXLError r;
54 
55     if (conn->dxuiConnected) {
56         r = DXLQuery(conn,"query sync-exec", 0,NULL) >= 0 ? OK : ERROR;
57     } else {
58         r = DXLSync(conn);
59     }
60 
61     return r;
62 
63 }
64 
65 DXLError
DXLGetValue(DXLConnection * conn,const char * varname,const int valueLen,char * value)66 DXLGetValue(DXLConnection *conn, const char *varname,
67 		const int valueLen, char *value)
68 {
69     int l = strlen(varname);
70     char *buffer = MALLOC(l + 16);
71     int sts;
72 
73     if (!conn->dxuiConnected) {
74 	FREE(buffer);
75 	return ERROR;
76     }
77 
78     sprintf(buffer, "query value %s",varname) ;
79     sts = DXLQuery(conn, buffer, valueLen, value);
80     FREE(buffer);
81     return sts >= 0 ? OK : ERROR;
82 }
83 
84 
85 DXLError
DXLGetInputValue(DXLConnection * conn,const char * macro,const char * module,const int instance,const int number,const int valueLen,char * value)86 DXLGetInputValue(DXLConnection *conn,
87     const char *macro, const char *module, const int instance, const int number,
88     const int valueLen, char *value)
89 {
90     int l = strlen(macro) + strlen(module);
91     char *varname = MALLOC(l + 64);
92     int sts;
93 
94     sprintf(varname, "%s_%s_%d_in_%d", macro, module, instance, number);
95     sts = DXLGetValue(conn, varname, valueLen, value);
96     FREE(varname);
97     return sts;
98 }
99 
100 
101 DXLError
DXLGetInputInteger(DXLConnection * conn,const char * macro,const char * module,const int instance,const int number,int * value)102 DXLGetInputInteger(DXLConnection *conn,
103     const char *macro, const char *module, const int instance, const int number,
104     int *value)
105 {
106     char rbuf[128];
107     int sts;
108 
109     sts = DXLGetInputValue(conn, macro, module, instance,number,
110 					sizeof(rbuf), rbuf);
111     if (sts == OK && sscanf(rbuf, "%d", value) != 1)
112 	sts = ERROR;
113     return sts;
114 }
115 
116 DXLError
DXLGetInputScalar(DXLConnection * conn,const char * macro,const char * module,const int instance,const int number,double * value)117 DXLGetInputScalar(DXLConnection *conn,
118     const char *macro, const char *module, const int instance, const int number,
119     double *value)
120 {
121     char rbuf[128];
122     int sts;
123 
124     sts = DXLGetInputValue(conn, macro, module, instance,number,
125 					sizeof(rbuf), rbuf);
126     if (sts == OK && sscanf(rbuf, "%lg", value) != 1)
127 	sts = ERROR;
128     return sts;
129 }
130 DXLError
DXLGetInputString(DXLConnection * conn,const char * macro,const char * module,const int instance,const int number,const int valueLen,char * value)131 DXLGetInputString(DXLConnection *conn,
132     const char *macro, const char *module, const int instance, const int number,
133     const int valueLen, char *value)
134 {
135     char *rbuf = MALLOC(valueLen + 32);
136     int sts;
137 
138     sts = DXLGetInputValue(conn, macro, module, instance,number,
139 					sizeof(rbuf), rbuf);
140     if (sts == OK && sscanf(rbuf, "\"%s\"", value) != 1)
141 	sts = ERROR;
142     FREE(rbuf);
143     return sts;
144 }
145 
146 
147 DXLError
DXLGetOutputValue(DXLConnection * conn,const char * macro,const char * module,const int instance,const int number,const int valueLen,char * value)148 DXLGetOutputValue(DXLConnection *conn,
149     const char *macro, const char *module, const int instance, const int number,
150     const int valueLen, char *value)
151 {
152     int l = strlen(macro) + strlen(module);
153     char *varname = MALLOC(l + 50);
154     int sts;
155 
156     sprintf(varname, "%s_%s_%d_out_%d", macro, module, instance, number);
157     sts = DXLGetValue(conn, varname, valueLen, value);
158     FREE(varname);
159     return sts;
160 }
161 
162 DXLError
DXLGetOutputInteger(DXLConnection * conn,const char * macro,const char * module,const int instance,const int number,int * value)163 DXLGetOutputInteger(DXLConnection *conn,
164     const char *macro, const char *module, const int instance, const int number,
165     int *value)
166 {
167     char rbuf[128];
168     int sts;
169 
170     sts = DXLGetOutputValue(conn, macro, module, instance,number,
171 					sizeof(rbuf), rbuf);
172     if (sts == OK && sscanf(rbuf, "%d", value) != 1)
173 	sts = ERROR;
174     return sts;
175 }
176 
177 DXLError
DXLGetOutputScalar(DXLConnection * conn,const char * macro,const char * module,const int instance,const int number,double * value)178 DXLGetOutputScalar(DXLConnection *conn,
179     const char *macro, const char *module, const int instance, const int number,
180     double *value)
181 {
182     char rbuf[128];
183     int sts;
184 
185     sts = DXLGetOutputValue(conn, macro, module, instance,number,
186 					sizeof(rbuf), rbuf);
187     if (sts == OK && sscanf(rbuf, "%lg", value) != 1)
188 	sts = ERROR;
189     return sts;
190 }
191 DXLError
DXLGetOutputString(DXLConnection * conn,const char * macro,const char * module,const int instance,const int number,const int valueLen,char * value)192 DXLGetOutputString(DXLConnection *conn,
193     const char *macro, const char *module, const int instance, const int number,
194     const int valueLen, char *value)
195 {
196     char *rbuf = MALLOC(valueLen + 32);
197     int sts;
198 
199     sts = DXLGetOutputValue(conn, macro, module, instance,number,
200 					sizeof(rbuf), rbuf);
201     if (sts == OK && sscanf(rbuf, "\"%s\"", value) != 1)
202 	sts = ERROR;
203     FREE(rbuf);
204     return sts;
205 }
206