Layout.c

Go to the documentation of this file.
00001 #include <unistd.h>
00002 #include "Layout.h"
00003 #include "FilterSpec.h"
00004 #include "StreamSpec.h"
00005 #include "Hosts.h"
00006 
00007 /*
00008  * 02/07/2004 Coutinho: Implementei getFilterByName
00009  * 05/07/2004 Coutinho: createFilter2() agora chama initFilterSpec().
00010  * 14/09/2004 Matheus: changed the struct completly
00011  */
00012 
00013 /* Constructor and destroyer ************************************************/ 
00014 Layout *createLayout() {
00015         Layout *l = (Layout *) malloc(sizeof(Layout));
00016         
00017         //hosts
00018         l->hostsStruct = hostsCreate();
00019         //filterspec
00020         l->numFilters = 0;
00021         //streamspec
00022         l->numStreams = 0;
00023 
00024         //xName, cwd and command
00025         if (getcwd(l->cwd, MAX_CWD_LENGTH) == NULL){
00026                 fprintf(stderr, "Layout.c: directory name is too big\n");
00027                 return NULL;
00028         }
00029         sprintf(l->xName, "initScript");
00030         sprintf(l->command, "%s/%s", l->cwd, l->xName);
00031 
00032         //manager state
00033         l->managerState.numWorksSent = 0;
00034         l->managerState.oldestWork = 0;
00035 
00036         return l;
00037 }
00038 void destroyLayout(Layout *l){
00039         int i;
00040         
00041         hostsDestroy(l->hostsStruct);
00042         for (i=0;i<l->numFilters;i++)
00043                 destroyFilterSpec(l->filters[i]);
00044         for (i=0;i<l->numStreams;i++)
00045                 destroyStreamSpec(l->streams[i]);
00046         free(l);
00047 
00048 }
00049 /***************************************************************************/
00050 
00051 /* Filter stuff ************************************************************/
00052 // adds a filter to the layout
00053 int addFilterSpec(Layout *l, FilterSpec *f) {
00054         if (l->numFilters == MAXFILTERS)
00055                 return 0;
00056         else {
00057                 l->filters[l->numFilters++] = f;
00058                 return 1;
00059         }
00060 }
00061 //returns the pointer to the Filter, NULL if not found
00062 FilterSpec *getFilterSpecByName(Layout *l, char *name){
00063         int i;
00064         for (i=0; i<l->numFilters; i++) {
00065                 if (strcmp(name, l->filters[i]->name) == 0) {
00066                         return (l->filters[i]);
00067                 }
00068         }
00069         return NULL;
00070 }
00071 
00072 void getFilterByTid(Layout *layout, int tid, FilterSpec **pFilterAddress, int *instanceAddress){
00073         int z, w;
00074         FilterSpec *pFilter = NULL;
00075         instanceAddress[0] = -1;
00076         //find who sent the EOW
00077         for (z=0; z < layout->numFilters; z++){
00078                 pFilter = layout->filters[z];
00079                 for (w=0; w < pFilter->filterPlacement.numInstances; w++){
00080                         if (pFilter->filterPlacement.tids[w] == tid){
00081                                 instanceAddress[0] = w;
00082                                 pFilterAddress[0] = pFilter;
00083                                 return;
00084                         }
00085                 }
00086         }
00087 }
00088 
00089 /**************************************************************************/
00090 
00091 /* StreamSpec *************************************************************/
00092 //adds a stream to the layout, returns 1 on success, 0 otherwise
00093 int addStreamSpec(Layout *l, StreamSpec *s){
00094         if (l->numStreams == MAXSTREAMS)
00095                 return 0;
00096         else {
00097                 l->streams[l->numStreams++] = s;
00098                 return 1;
00099         }
00100 }
00101 //returns the pointer to the stream on success, NULL if not found
00102 StreamSpec *getStreamSpecByName(Layout *l, char *name){
00103         int i;
00104         for (i=0; i<l->numStreams; i++) {
00105                 if (strcmp(name, l->streams[i]->name) == 0) {
00106                         return (l->streams[i]);
00107                 }
00108         }
00109         return NULL;
00110 }

Generated on Tue Jan 17 19:18:38 2006 for Void by  doxygen 1.4.6