~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Tina4/src/tools/fgrabber/client.c

Version: ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2 Client: client.c
  3 
  4 Client for server
  5 
  6 Author: A.J.Lacey
  7 Date: 15-1-93; version 1.0
  8       15.1.96; version 2.0
  9 
 10 */
 11 
 12 #include <sys/types.h>
 13 #include <sys/socket.h>
 14 #include <netinet/in.h>
 15 #include <stdio.h>
 16 #include <netdb.h>
 17 #include <math.h>
 18 #include <tina/sys.h>
 19 #include <tina/sysfuncs.h>
 20 #include <tina/math.h>
 21 #include <tina/mathfuncs.h>
 22 #include <tina/grabdefs.h>
 23 #include <tina/grabsrv.h>
 24 #include <tina/grabpro.h>
 25 
 26 
 27 
 28 int      sock_connect(Grabber *grptr)
 29 {
 30         struct sockaddr_in       server;
 31         struct servent          *sp;
 32         struct hostent          *hp;
 33         char buf[512];
 34         int sock;
 35 
 36         if ((sp = getservbyname(grptr->service, "tcp")) == NULL)
 37         {
 38                 format("Grab tool: unknown service, %s\n", grptr->service);
 39                 return (-1);
 40         }
 41 
 42         if ((hp = gethostbyname(grptr->host)) == NULL)
 43         {
 44                 format("Grab tool: %s unknown host\n", grptr->host);
 45                 return (-1);
 46         }
 47 /*
 48         Clear buffer and fill with host Internet address
 49 */
 50         bzero((char *)&server, sizeof server);
 51         bcopy(hp->h_addr, (char *)&server.sin_addr, hp->h_length);
 52         server.sin_family = hp->h_addrtype;
 53         server.sin_port = sp->s_port;
 54 
 55         if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
 56         {
 57                 format("Grab tool: socket creation error\n");
 58                 return (-1);
 59         }
 60 
 61         if (connect(sock, (struct sockaddr *)&server, sizeof server) < 0)
 62         {
 63                 format("Grab tool: connection error\n");
 64                 return (-1);
 65         }
 66 
 67         return sock;
 68 }
 69 
 70 
 71 
 72 int             read_data(int sock, Grabber *params)
 73 {
 74 /*
 75         - read packets of image data from server
 76         - return any read errors
 77         - allow 3 passes of incomplete packet reads before error
 78 */
 79 
 80         unsigned char  *imptr;
 81         unsigned int    image_size;
 82         int                     data_blocks, final_blocks, amount, passes;
 83         int                     err, packet_error;
 84 
 85         imptr = params->im_buffer;
 86         image_size = params->width * params->length;
 87         data_blocks = image_size/MAX_PACKET;
 88         final_blocks = image_size%MAX_PACKET;
 89         amount = MAX_PACKET;
 90         packet_error = 0;
 91         err = 0;
 92         passes = 0;
 93 
 94         do
 95         {
 96                 do
 97                 {
 98                         passes++;
 99                         if ((err = rm_read(sock, imptr, amount)) == -1)
100                            return (err);
101 
102                         else
103                         if (err != amount)
104                         {
105                                 format("Incomplete packet read\n");
106                                 imptr += err;
107                                 if (++packet_error == 3)
108                                    return (-3);
109                         }
110                         
111                         else
112                                 imptr += amount;
113 
114                 } while(passes < data_blocks);
115 
116                 packet_error = 0;
117                 amount = final_blocks;
118 
119         } while((passes != (data_blocks + 1)) && (amount != 0));
120 
121         return (0);
122 }
123 
124 
125 
126 int             read_aiff_data(int sock, Imrect *imptr)
127 {
128 /*
129         - read packets of image data from server into aiff IMRECT
130         - return any read errors
131         - allow 3 passes of incomplete packet reads before error
132 */
133 
134         char                    buf[MAX_PACKET];
135         char               *buffer;
136         unsigned int    image_size;
137         int                     data_blocks, final_blocks, a, p;
138         int                     err, packet_error;
139         int                     x, y, z;
140 
141         buffer = buf;
142         image_size = imptr->width * imptr->height;
143         data_blocks = image_size/MAX_PACKET;
144         final_blocks = image_size%MAX_PACKET;
145         a = MAX_PACKET;
146         packet_error = 0;
147         err = 0;
148         p = 0;
149         x = y = z = 0;
150 
151         do
152         {
153                 do
154                 {
155                         z = 0;
156                         p++;
157                         if ((err = rm_read(sock, buffer, a)) == -1)
158                            return (err);
159 
160                         else
161                         if (err != a)
162                         {
163                                 format("Incomplete packet read\n");
164                                 buffer += err;
165                                 if (++packet_error == 3)
166                                    return (-3);
167                         }
168                         
169                         else
170                         {
171                                 do
172                                 {
173                                         IM_UCHAR(imptr, x, y) = buffer [z++];
174                                         if (++y == imptr->width)
175                                         {
176                                                 y = 0;
177                                                 x++;
178                                         }
179                                 } while (z < a);
180                         }
181                                 
182                 } while(p < data_blocks);
183 
184                 packet_error = 0;
185                 a = final_blocks;
186 
187         } while((p != (data_blocks + 1)) && (a != 0));
188 
189         return (0);
190 }
191 
192 
193 
194 void            retrieve_st_pair(int s, Imrect *iml, Imrect *imr, Grabber *gp)
195 {
196 
197         int             result;
198 
199         if (gp->format == AIFF)
200         {
201                 if ((result = read_aiff_data(s, iml)) < 0)
202                 {
203                         format("Grab tool: image read error: %d\n", result);
204                         return;
205                 }
206 
207                 if ((result = read_aiff_data(s, imr)) < 0)
208                 {       
209                         format("Grab tool: image read error: %d\n", result);
210                         return;
211                 }
212                 
213                 if (file_format(gp, iml, 0, LEFT_IM) == -1)
214                 {       
215                         format("Grab tool: file error\n");
216                         return;
217                 }
218 
219                 if (file_format(gp, imr, 0, RIGHT_IM) == -1)
220                 {       
221                         format("Grab tool: file error\n");
222                         return;
223                 }
224 
225         }
226 
227         else
228         {
229                 if ((result = read_data(s, gp)) < 0)
230                 {
231                         format("Grab tool: image read error: %d\n", result);
232                         return;
233                 }
234 
235                 if (file_format(gp, iml, 0, LEFT_IM) == -1)
236                 {       
237                         format("Grab tool: file error\n");
238                         return;
239                 }
240 
241                 if ((result = read_data(s, gp)) < 0)
242                 {
243                         format("Grab tool: image read error: %d\n", result);
244                         return;
245                 }
246 
247                 if (file_format(gp, imr, 0, RIGHT_IM) == -1)
248                 {       
249                         format("Grab tool: file error\n");
250                         return;
251                 }
252         }
253 
254 }
255 
256 
257 
258 void            retrieve_mono(int s, Imrect *im, Grabber *gp)
259 {
260         int             result, i;
261 
262         if (gp->count != 0)
263         {
264                 for(i = 0; i < gp->number; i++)
265                 {
266                         if (gp->format == AIFF)
267                         {
268                                 if ((result = read_aiff_data(s, im)) < 0)
269                                 {
270                                         format("Grab tool: image read error: %d\n", result);
271                                         return;
272                                 }
273                         }
274 
275                         else
276                         {
277                                 if ((result = read_data(s, gp)) < 0)
278                                 {
279                                         format("Grab tool: image read error: %d\n", result);
280                                         return;
281                                 }
282                         }
283                         
284                         if (file_format(gp, im, i, MONO_IM) == -1)
285                         {       
286                                 format("Grab tool: file error\n");
287                                 return;
288                         }
289             }
290         }
291 
292 
293 }
294 
295         
296 
297 
298 
299 
300 
301 
302 
303 
304 
305 
306 
307 
308 
309 
310 
311 
312 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.