source: trunk/src/testing/app/mframes/machinefile_code/file_parsers.cpp @ 4

Revision 4, 16.2 KB checked in by ajaworski, 13 years ago (diff)

Added modified SAGE sources

Line 
1/******************************************************************************
2 * SAGE - Scalable Adaptive Graphics Environment
3 *
4 * Copyright (C) 2004 Electronic Visualization Laboratory,
5 * University of Illinois at Chicago
6 *
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions are met:
11 *
12 *  * Redistributions of source code must retain the above copyright
13 *    notice, this list of conditions and the following disclaimer.
14 *  * Redistributions in binary form must reproduce the above
15 *    copyright notice, this list of conditions and the following disclaimer
16 *    in the documentation and/or other materials provided with the distribution.
17 *  * Neither the name of the University of Illinois at Chicago nor
18 *    the names of its contributors may be used to endorse or promote
19 *    products derived from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 *
33 * Direct questions, comments etc about SAGE to http://www.evl.uic.edu/cavern/forum/
34 *
35 *****************************************************************************/
36
37/*------------------------------------------------------------------------
38-       Author: Arun Rao
39-       Library: Tile Config
40-       Revision Date: 4/22/2004
41-       Module: file_parsers.cpp
42-       Purpose: Contains function implementation for file i/o to load in
43-       and write out tiled display system descriptions
44---------------------------------------------------------------------------*/
45#include <stdio.h>
46#include <stdlib.h>
47#include <string.h>
48#include <iostream>
49using namespace std;
50
51#include "file_parsers.h"
52
53#define UP_MULLION 0
54#define DOWN_MULLION 1
55#define LEFT_MULLION 2
56#define RIGHT_MULLION 3
57
58#ifdef _cplusplus
59extern "C" {
60#endif
61
62//--------------------------------------------------------
63int stdInputFileParser(char* filename,PhysicalDisplay*& pd,DisplayCluster*& dc,VirtualDesktop*& vd)
64{
65        if(filename == NULL)
66                return -1;
67
68        FILE* fin = fopen(filename,"r");
69
70        if(fin == NULL)
71                return -1;
72
73        //create objects
74        cout << "Creating High Level Objects" << endl;
75
76        if(pd == NULL)
77                pd = new PhysicalDisplay();
78        if(dc == NULL)
79                dc = new DisplayCluster();
80        if(vd == NULL)
81                vd = new VirtualDesktop();
82
83        //setup associations
84        cout << "Setting Associations" << endl;
85        dc->VirtualDesktopAssoc(vd);
86        dc->PhysicalDisplayAssoc(pd);
87        vd->PhysicalDisplayAssoc(pd);
88        vd->DisplayClusterAssoc(dc);
89        pd->VirtualDesktopAssoc(vd);
90        pd->DisplayClusterAssoc(dc);
91
92        Virtual_Desktop_Tile** tempVDT = NULL;
93        Physical_Tile** tempPT = NULL;
94        Display_Node** tempDN = NULL;
95        VDTtoPTmapper*** tempMapper = NULL;
96        char buffer1[32];
97
98        cout << "Gathering: Dimensions - ";
99        //First is Dimension Data
100        fscanf(fin,"%s",buffer1);
101        while( !strcmp( buffer1, "#" ))
102        {
103                while(fgetc(fin) != '\n');
104                fscanf(fin,"%s",buffer1);
105        }
106
107        if(strcmp( buffer1, "TileDisplay"))
108        {
109                delete pd;
110                delete dc;
111                delete vd;
112                pd = NULL;
113                dc = NULL;
114                vd = NULL;
115                return -1;
116        }
117
118        fscanf(fin,"%s",buffer1);
119        if(strcmp( buffer1, "Dimensions"))
120        {
121                delete pd;
122                delete dc;
123                delete vd;
124                pd = NULL;
125                dc = NULL;
126                vd = NULL;
127                return -1;
128        }
129        int dimx, dimy;
130        fscanf(fin, "%d %d\n", &dimx, &dimy);
131
132        //Next is the Mullions for every screen
133        cout << "Mullions - ";
134        fscanf(fin,"%s",buffer1);
135        if(strcmp( buffer1, "Mullions"))
136        {
137                delete pd;
138                delete dc;
139                delete vd;
140                pd = NULL;
141                dc = NULL;
142                vd = NULL;
143                return -1;
144        }
145
146        float mullions[4];
147        fscanf( fin, "%f %f %f %f\n", &mullions[UP_MULLION], &mullions[DOWN_MULLION],
148                                        &mullions[LEFT_MULLION], &mullions[RIGHT_MULLION]);
149
150        cout << "Resolution - ";
151        //Next is Resolution of each screen
152        fscanf(fin,"%s",buffer1);
153        if(strcmp( buffer1, "Resolution"))
154        {
155                delete pd;
156                delete dc;
157                delete vd;
158                pd = NULL;
159                dc = NULL;
160                vd = NULL;
161                return -1;
162        }
163
164        float resolution[2];
165        fscanf( fin, "%f %f\n", &resolution[0], &resolution[1]);
166
167        cout << "Pixels Per Inch - ";
168        //Pixels Per Inch Is Next
169        fscanf(fin,"%s",buffer1);
170        if(strcmp( buffer1, "PPI"))
171        {
172                delete pd;
173                delete dc;
174                delete vd;
175                pd = NULL;
176                dc = NULL;
177                vd = NULL;
178                return -1;
179        }
180
181        float pixelsPerInch;
182        fscanf(fin, "%f\n", &pixelsPerInch);
183        pd->PixelsPerInch( pixelsPerInch );
184
185        //Determine Screen Dimensions from Pixels Per Inch & Screen Resolutions
186        float screenWidth, screenHeight;
187        screenWidth = resolution[0] / (float)pixelsPerInch;
188        screenHeight = resolution[1] / (float)pixelsPerInch;
189        cout << "ScreenWidth x ScreenHeight: " << screenWidth << 'x' << screenHeight << endl;
190        //figure out the "total dimensions" of a tile
191        float totalWidth = screenWidth + mullions[LEFT_MULLION] + mullions[RIGHT_MULLION];
192        float totalHeight = screenHeight + mullions[UP_MULLION] + mullions[DOWN_MULLION];
193
194        cout << "Machine Count" << endl;
195        //Number of Machines is Next
196        fscanf(fin,"%s",buffer1);
197        if(strcmp( buffer1, "Machines"))
198        {
199                delete pd;
200                delete dc;
201                delete vd;
202                pd = NULL;
203                dc = NULL;
204                vd = NULL;
205                return -1;
206        }
207
208        int machineCount;
209        fscanf(fin,"%d\n",&machineCount);
210
211
212        //Create the Virtual Desktop Tiles, Physical Tiles & Mappers to connect each one
213        tempVDT = new Virtual_Desktop_Tile*[dimx];
214        tempPT = new Physical_Tile*[dimx];
215//      tempMapper = new VDTtoPTmapper**[dimx];
216        cout << "Generating Tiles & Virtual Tiles" << endl;
217        for(int i = 0; i < dimx; i++)
218        {
219                tempVDT[i] = new Virtual_Desktop_Tile[dimy];
220                tempPT[i] = new Physical_Tile[dimy];
221//              tempMapper[i] = new VDTtoPTMapper*[dimy];
222
223                for(int j = 0; j < dimy; j++)
224                {
225
226                        tempPT[i][j].ScreenHeightDimension( screenHeight );
227                        tempPT[i][j].ScreenWidthDimension( screenWidth );
228                        tempPT[i][j].BottomMullionThickness( mullions[DOWN_MULLION] );
229                        tempPT[i][j].LeftMullionThickness( mullions[LEFT_MULLION] );
230                        tempPT[i][j].RightMullionThickness( mullions[RIGHT_MULLION] );
231                        tempPT[i][j].TopMullionThickness( mullions[UP_MULLION] );
232
233                        tempPT[i][j].LowerLeftX( i * totalWidth );
234                        tempPT[i][j].LowerLeftY( j * totalHeight );
235                        pd->AddPhysicalTile( &(tempPT[i][j]));
236
237                }
238        }
239
240        //Go through and get each machine
241        cout << "Generating Machines & Creating Mappings" << endl;
242        for(int k = 0; k < machineCount; k++)
243        {
244                char ip[16];
245                char name[32];
246                int maps;
247                int tileX, tileY;
248
249                cout << k << ' ';
250                fscanf(fin,"%s",buffer1);
251                if(strcmp( buffer1, "DisplayNode"))
252                {
253                        cout << "Read: " << buffer1 << " instead of \"DisplayNode\"" << endl;
254                        delete pd;
255                        delete dc;
256                        delete vd;
257                        pd = NULL;
258                        dc = NULL;
259                        vd = NULL;
260                        return -1;
261                }
262                //Name
263                cout << "Name ";
264                fscanf(fin,"%s",buffer1);
265                if(strcmp( buffer1, "Name"))
266                {
267                        cout << "Read: " << buffer1 << " instead of \"Name\"" << endl;
268                        delete pd;
269                        delete dc;
270                        delete vd;
271                        pd = NULL;
272                        dc = NULL;
273                        vd = NULL;
274                        return -1;
275                }
276
277                fscanf(fin,"%s",name);
278                cout << name << ' ';
279                //ip
280                cout << "IP: ";
281                fscanf(fin,"%s",buffer1);
282                if(strcmp( buffer1, "IP"))
283                {
284                        cout << "Read: " << buffer1 << " instead of \"IP\"" << endl;
285                        delete pd;
286                        delete dc;
287                        delete vd;
288                        pd = NULL;
289                        dc = NULL;
290                        vd = NULL;
291                        return -1;
292                }
293
294                fscanf(fin,"%s",ip);
295                cout << ip << ' ';
296                //Monitors
297                cout << "Monitors: ";
298                fscanf(fin,"%s",buffer1);
299                if(strcmp( buffer1, "Monitors"))
300                {
301                        cout << "Read: " << buffer1 << " instead of \"Monitors\"" << endl;
302                        delete pd;
303                        delete dc;
304                        delete vd;
305                        pd = NULL;
306                        dc = NULL;
307                        vd = NULL;
308                        return -1;
309                }
310
311                fscanf(fin,"%d", &maps );
312                cout << maps << ' ';;
313                Display_Node* dn;
314                dn = new Display_Node();
315                dn->NumberOfMaps( maps );
316                dn->Name( name );
317                dn->IP( ip );
318
319                dc->AddDisplayNode( dn );
320
321                for( int i = 0; i < maps; i++)
322                {
323                        cout << '.';
324                        fscanf(fin," (%d,%d)", &tileX, &tileY);
325                        cout << '(' <<  tileX << ',' << tileY << ')';
326                        dc->GenerateMapping( &(tempVDT[tileX][tileY]), &(tempPT[tileX][tileY]), dn );
327                        vd->AddTile( &(tempVDT[tileX][tileY]) );
328
329                }
330
331                //fscanf(fin,"%s\n", buffer1);
332                cout << endl;
333
334#ifdef _DEBUG
335
336
337#endif
338
339        }
340
341        cout << endl << "Updating Virutal Desktop" << endl;
342
343        vd->Update();
344
345        fclose(fin);
346
347        return 1;
348}
349
350//--------------------------------------------------------
351void stdOutputFileWriter(char* filename,PhysicalDisplay* pd,DisplayCluster* dc,VirtualDesktop* vd)
352{
353
354}
355
356
357//--------------------------------------------------------
358int corewallInputFileParser(char* filename, PhysicalDisplay*& pd, DisplayCluster*& dc, VirtualDesktop*& vd, int*& startPos)
359{
360
361                if(filename == NULL)
362                return -1;
363
364        FILE* fin = fopen(filename,"r");
365
366        if(fin == NULL)
367                return -1;
368
369        //create objects
370        cout << "Creating High Level Objects" << endl;
371        if(pd == NULL)
372                pd = new PhysicalDisplay();
373        if(dc == NULL)
374                dc = new DisplayCluster();
375        if(vd == NULL)
376                vd = new VirtualDesktop();
377
378        //setup associations
379        cout << "Setting Associations" << endl;
380
381        dc->VirtualDesktopAssoc(vd);
382        dc->PhysicalDisplayAssoc(pd);
383        vd->PhysicalDisplayAssoc(pd);
384        vd->DisplayClusterAssoc(dc);
385        pd->VirtualDesktopAssoc(vd);
386        pd->DisplayClusterAssoc(dc);
387
388        Virtual_Desktop_Tile** tempVDT = NULL;
389        Physical_Tile** tempPT = NULL;
390        Display_Node** tempDN = NULL;
391        VDTtoPTmapper*** tempMapper = NULL;
392        char buffer1[32];
393
394        //cout << "Gathering: Dimensions - ";
395        printf("getting dimensions\n");
396        //First is Dimension Data
397        fscanf(fin,"%s",buffer1);
398        while( !strcmp( buffer1, "#" ))
399        {
400                while(fgetc(fin) != '\n');
401                fscanf(fin,"%s",buffer1);
402        }
403
404        if(strcmp( buffer1, "TileDisplay"))
405        {
406                delete pd;
407                delete dc;
408                delete vd;
409                pd = NULL;
410                dc = NULL;
411                vd = NULL;
412                return -1;
413        }
414
415        fscanf(fin,"%s",buffer1);
416        if(strcmp( buffer1, "Dimensions"))
417        {
418                delete pd;
419                delete dc;
420                delete vd;
421                pd = NULL;
422                dc = NULL;
423                vd = NULL;
424                return -1;
425        }
426        int dimx, dimy;
427        fscanf(fin, "%d %d\n", &dimx, &dimy);
428
429        //Next is the Mullions for every screen
430        cout << "Mullions - ";
431        fscanf(fin,"%s",buffer1);
432        if(strcmp( buffer1, "Mullions"))
433        {
434                delete pd;
435                delete dc;
436                delete vd;
437                pd = NULL;
438                dc = NULL;
439                vd = NULL;
440                return -1;
441        }
442
443        float mullions[4];
444        fscanf( fin, "%f %f %f %f\n", &mullions[UP_MULLION], &mullions[DOWN_MULLION],
445                                        &mullions[LEFT_MULLION], &mullions[RIGHT_MULLION]);
446
447        cout << "Resolution - ";
448        //Next is Resolution of each screen
449        fscanf(fin,"%s",buffer1);
450        if(strcmp( buffer1, "Resolution"))
451        {
452                delete pd;
453                delete dc;
454                delete vd;
455                pd = NULL;
456                dc = NULL;
457                vd = NULL;
458                return -1;
459        }
460
461        float resolution[2];
462        fscanf( fin, "%f %f\n", &resolution[0], &resolution[1]);
463
464        cout << "Pixels Per Inch - ";
465        //Pixels Per Inch Is Next
466        fscanf(fin,"%s",buffer1);
467        if(strcmp( buffer1, "PPI"))
468        {
469                delete pd;
470                delete dc;
471                delete vd;
472                pd = NULL;
473                dc = NULL;
474                vd = NULL;
475                return -1;
476        }
477
478        float pixelsPerInch;
479        fscanf(fin, "%f\n", &pixelsPerInch);
480        pd->PixelsPerInch( pixelsPerInch );
481
482        //Determine Screen Dimensions from Pixels Per Inch & Screen Resolutions
483        float screenWidth, screenHeight;
484        screenWidth = resolution[0] / (float)pixelsPerInch;
485        screenHeight = resolution[1] / (float)pixelsPerInch;
486        cout << "ScreenWidth x ScreenHeight: " << screenWidth << 'x' << screenHeight << endl;
487        //figure out the "total dimensions" of a tile
488        float totalWidth = screenWidth + mullions[LEFT_MULLION] + mullions[RIGHT_MULLION];
489        float totalHeight = screenHeight + mullions[UP_MULLION] + mullions[DOWN_MULLION];
490
491        cout << "Machine Count" << endl;
492        //Number of Machines is Next
493        fscanf(fin,"%s",buffer1);
494        if(strcmp( buffer1, "Machines"))
495        {
496                delete pd;
497                delete dc;
498                delete vd;
499                pd = NULL;
500                dc = NULL;
501                vd = NULL;
502                return -1;
503        }
504
505        int machineCount;
506        fscanf(fin,"%d\n",&machineCount);
507
508        //get the offsets
509        cout << "OffsetX" << endl;
510        //OffsetX is Next
511        fscanf(fin,"%s",buffer1);
512        if(strcmp( buffer1, "OffsetX"))
513        {
514                delete pd;
515                delete dc;
516                delete vd;
517                pd = NULL;
518                dc = NULL;
519                vd = NULL;
520                return -1;
521        }
522
523        fscanf(fin,"%d\n",&(startPos[0]));
524
525
526        cout << "OffsetY" << endl;
527        //OffsetY is Next
528        fscanf(fin,"%s",buffer1);
529        if(strcmp( buffer1, "OffsetY"))
530        {
531                delete pd;
532                delete dc;
533                delete vd;
534                pd = NULL;
535                dc = NULL;
536                vd = NULL;
537                return -1;
538        }
539
540        fscanf(fin,"%d\n",&(startPos[1]));
541
542
543        //Create the Virtual Desktop Tiles, Physical Tiles & Mappers to connect each one
544        tempVDT = new Virtual_Desktop_Tile*[dimx];
545        tempPT = new Physical_Tile*[dimx];
546//      tempMapper = new VDTtoPTmapper**[dimx];
547        cout << "Generating Tiles & Virtual Tiles" << endl;
548        for(int i = 0; i < dimx; i++)
549        {
550                tempVDT[i] = new Virtual_Desktop_Tile[dimy];
551                tempPT[i] = new Physical_Tile[dimy];
552//              tempMapper[i] = new VDTtoPTMapper*[dimy];
553
554                for(int j = 0; j < dimy; j++)
555                {
556
557                        tempPT[i][j].ScreenHeightDimension( screenHeight );
558                        tempPT[i][j].ScreenWidthDimension( screenWidth );
559                        tempPT[i][j].BottomMullionThickness( mullions[DOWN_MULLION] );
560                        tempPT[i][j].LeftMullionThickness( mullions[LEFT_MULLION] );
561                        tempPT[i][j].RightMullionThickness( mullions[RIGHT_MULLION] );
562                        tempPT[i][j].TopMullionThickness( mullions[UP_MULLION] );
563
564                        tempPT[i][j].LowerLeftX( i * totalWidth );
565                        tempPT[i][j].LowerLeftY( j * totalHeight );
566                        pd->AddPhysicalTile( &(tempPT[i][j]));
567
568                }
569        }
570
571        //Get the starting offsets
572        //Go through and get each machine
573        cout << "Generating Machines & Creating Mappings" << endl;
574        for(int k = 0; k < machineCount; k++)
575        {
576                char ip[16];
577                char name[32];
578                int maps;
579                int tileX, tileY;
580
581                cout << k << ' ';
582                fscanf(fin,"%s",buffer1);
583                if(strcmp( buffer1, "DisplayNode"))
584                {
585                        cout << "Read: " << buffer1 << " instead of \"DisplayNode\"" << endl;
586                        delete pd;
587                        delete dc;
588                        delete vd;
589                        pd = NULL;
590                        dc = NULL;
591                        vd = NULL;
592                        return -1;
593                }
594                //Name
595                cout << "Name ";
596                fscanf(fin,"%s",buffer1);
597                if(strcmp( buffer1, "Name"))
598                {
599                        cout << "Read: " << buffer1 << " instead of \"Name\"" << endl;
600                        delete pd;
601                        delete dc;
602                        delete vd;
603                        pd = NULL;
604                        dc = NULL;
605                        vd = NULL;
606                        return -1;
607                }
608
609                fscanf(fin,"%s",name);
610                cout << name << ' ';
611                //ip
612                cout << "IP: ";
613                fscanf(fin,"%s",buffer1);
614                if(strcmp( buffer1, "IP"))
615                {
616                        cout << "Read: " << buffer1 << " instead of \"IP\"" << endl;
617                        delete pd;
618                        delete dc;
619                        delete vd;
620                        pd = NULL;
621                        dc = NULL;
622                        vd = NULL;
623                        return -1;
624                }
625
626                fscanf(fin,"%s",ip);
627                cout << ip << ' ';
628                //Monitors
629                cout << "Monitors: ";
630                fscanf(fin,"%s",buffer1);
631                if(strcmp( buffer1, "Monitors"))
632                {
633                        cout << "Read: " << buffer1 << " instead of \"Monitors\"" << endl;
634                        delete pd;
635                        delete dc;
636                        delete vd;
637                        pd = NULL;
638                        dc = NULL;
639                        vd = NULL;
640                        return -1;
641                }
642
643                fscanf(fin,"%d", &maps );
644                cout << maps << ' ';;
645                Display_Node* dn;
646                dn = new Display_Node();
647                dn->NumberOfMaps( maps );
648                dn->Name( name );
649                dn->IP( ip );
650
651                dc->AddDisplayNode( dn );
652
653                for( int i = 0; i < maps; i++)
654                {
655                        cout << '.';
656                        fscanf(fin," (%d,%d)", &tileX, &tileY);
657//                      cout << '(' <<  tileX << ',' << tileY << ')';
658                        dc->GenerateMapping( &(tempVDT[tileX][tileY]), &(tempPT[tileX][tileY]), dn );
659                        tempVDT[tileX][tileY].NonMullionLLX( resolution[0] * tileX );
660                        tempVDT[tileX][tileY].NonMullionLLY( resolution[1] * tileY );
661                        cout << "NonMullion x,y: " << screenWidth * tileX << ", "
662                                << screenHeight * tileY << endl;
663                        vd->AddTile( &(tempVDT[tileX][tileY]) );
664                }
665
666                //fscanf(fin,"%s\n", buffer1);
667//              cout << endl;
668
669#ifdef _DEBUG
670
671
672#endif
673
674        }
675
676        cout << endl << "Updating Virutal Desktop" << endl;
677
678        vd->Update();
679
680        fclose(fin);
681
682        return 1;
683}
684
685#ifdef _cplusplus
686}
687#endif
Note: See TracBrowser for help on using the repository browser.