00001 #include <stdlib.h>
00002 #include "xdr.h"
00003
00004 int db__send_float(float d)
00005 {
00006 XDR xdrs;
00007 int stat;
00008
00009 stat = DB_OK;
00010
00011 xdr_begin_send (&xdrs);
00012 if(!xdr_float (&xdrs, &d))
00013 stat = DB_PROTOCOL_ERR;
00014 xdr_end_send (&xdrs);
00015
00016 if (stat == DB_PROTOCOL_ERR)
00017 db_protocol_error();
00018 return stat;
00019 }
00020
00021 int db__recv_float (float *d)
00022 {
00023 XDR xdrs;
00024 int stat;
00025
00026 stat = DB_OK;
00027 xdr_begin_recv (&xdrs);
00028 if(!xdr_float (&xdrs, d))
00029 stat = DB_PROTOCOL_ERR;
00030 xdr_end_recv (&xdrs);
00031
00032 if (stat == DB_PROTOCOL_ERR)
00033 db_protocol_error();
00034 return stat;
00035 }
00036
00037 int db__send_float_array (float *x, int n)
00038 {
00039 XDR xdrs;
00040 int i;
00041 int stat;
00042
00043 stat = DB_OK;
00044
00045 xdr_begin_send (&xdrs);
00046
00047 if(!xdr_int (&xdrs, &n))
00048 stat = DB_PROTOCOL_ERR;
00049 for (i = 0; stat == DB_OK && i < n; i++)
00050 {
00051 if(!xdr_float (&xdrs, x))
00052 stat = DB_PROTOCOL_ERR;
00053 x++;
00054 }
00055
00056 xdr_end_send (&xdrs);
00057
00058 if (stat == DB_PROTOCOL_ERR)
00059 db_protocol_error();
00060 return stat;
00061 }
00062
00063
00064
00065
00066 int db__recv_float_array (float **x, int *n)
00067 {
00068 XDR xdrs;
00069 int i, count, stat;
00070 float y, *a;
00071
00072 *x = NULL;
00073 *n = 0;
00074
00075 stat = DB_OK;
00076 xdr_begin_recv (&xdrs);
00077 if (xdr_int (&xdrs, &count))
00078 {
00079 if (count <= 0)
00080 stat = DB_PROTOCOL_ERR;
00081 a = (float *)db_calloc (count, sizeof (float));
00082 if (a == NULL && stat == DB_OK)
00083 stat = DB_MEMORY_ERR;
00084
00085 for (i = 0; i < count; i++)
00086 {
00087 if (!xdr_float (&xdrs, &y))
00088 {
00089 stat = DB_PROTOCOL_ERR;
00090 break;
00091 }
00092 if (a) a[i] = y;
00093 }
00094 if (stat != DB_OK)
00095 {
00096 if (a != NULL) free(a);
00097 a = NULL;
00098 }
00099 }
00100 else
00101 stat = DB_PROTOCOL_ERR;
00102
00103 if (stat == DB_OK)
00104 {
00105 *x = a;
00106 *n = count;
00107 }
00108 else if (stat == DB_PROTOCOL_ERR)
00109 db_protocol_error();
00110
00111 xdr_end_recv (&xdrs);
00112 return stat;
00113 }