khronosfws/openmax_al/src/adptcommon/xaframeworkmgr.c
changeset 31 8dfd592727cb
parent 22 128eb6a32b84
child 42 1fa3fb47b1e3
equal deleted inserted replaced
22:128eb6a32b84 31:8dfd592727cb
     1 /*
     1 /*
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3  * All rights reserved.
     4 * This component and the accompanying materials are made available
     4  * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5  * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6  * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     8 *
     8  *
     9 * Initial Contributors:
     9  * Initial Contributors:
    10 * Nokia Corporation - initial contribution.
    10  * Nokia Corporation - initial contribution.
    11 *
    11  *
    12 * Contributors:
    12  * Contributors:
    13 *
    13  *
    14 * Description:
    14  * Description: Framework Manager. Parses the CFG file
    15 *
    15  *
    16 */
    16  */
    17 
    17 
    18 #include "xaframeworkmgr.h"
       
    19 #include <stdio.h>
    18 #include <stdio.h>
    20 #include <string.h>
    19 #include <string.h>
       
    20 #include "xaframeworkmgr.h"
    21 
    21 
    22 /* Default line width permitted in the cfg file + 2 to hold "\r\n"*/
    22 /* Default line width permitted in the cfg file + 2 to hold "\r\n"*/
    23 #define LINEWIDTH 82
    23 #define LINEWIDTH 82
    24 
    24 
    25 typedef enum
    25 typedef enum
    26 {
    26     {
    27     FWMgrTagNone,
    27     FWMgrTagNone,
    28     FWMgrTagURIScheme,
    28     FWMgrTagURIScheme,
    29     FWMgrTagFileExt
    29     FWMgrTagFileExt
    30 } FWMgrTagType;
    30     } FWMgrTagType;
    31 
       
    32 
    31 
    33 /* Config file location */
    32 /* Config file location */
    34 const char configFileLocation[] = "z:/openmaxal/openmaxal.cfg";
    33 const char configFileLocationZ[] = "z:/openmaxal/openmaxal.cfg";
       
    34 const char configFileLocationC[] = "c:/openmaxal/openmaxal.cfg";
    35 
    35 
    36 /* Tags used for parsing */
    36 /* Tags used for parsing */
    37 const char mediaPlayerBeginTag[] = "<mediaplayer>";
    37 const char mediaPlayerBeginTag[] = "<mediaplayer>";
    38 const char mediaPlayerEndTag[] = "</mediaplayer>";
    38 const char mediaPlayerEndTag[] = "</mediaplayer>";
    39 const char mediaRecorderBeginTag[] = "<mediarecorder>";
    39 const char mediaRecorderBeginTag[] = "<mediarecorder>";
    47 const char fileExtBeginTag[] = "<fileext>";
    47 const char fileExtBeginTag[] = "<fileext>";
    48 const char fileExtEndTag[] = "</fileext>";
    48 const char fileExtEndTag[] = "</fileext>";
    49 
    49 
    50 /* Local function definitions */
    50 /* Local function definitions */
    51 /* returns FWMgrTrue if processed successfully */
    51 /* returns FWMgrTrue if processed successfully */
    52 static FWMgrBool processConfigEntry(
    52 static FWMgrBool processConfigEntry(const char* buffer,
    53         const char* buffer,
    53         FWMgrMOType *mediaType, FWMgrFwType *frameworkType,
    54         FWMgrMOType *mediaType,
    54         FWMgrTagType *tagType, FWMgrBool *newNode, FrameworkMap **node);
    55         FWMgrFwType *frameworkType,
    55 
    56         FWMgrTagType *tagType,
    56 /* returns FWMgrTrue if processed successfully */
    57         FWMgrBool *newNode,
    57 static FWMgrBool processTagType(const char* buffer,
       
    58         FWMgrFwType *frameworkType, FWMgrTagType *tagType,
    58         FrameworkMap **node);
    59         FrameworkMap **node);
    59 
    60 
    60 /* returns FWMgrTrue if processed successfully */
    61 /* returns FWMgrTrue if processed successfully */
    61 static FWMgrBool processTagType(
    62 static FWMgrBool tokenizeTag(FWMgrTagType tagType, const char* buffer,
    62         const char* buffer,
       
    63         FWMgrFwType *frameworkType,
       
    64         FWMgrTagType *tagType,
       
    65         FrameworkMap **node);
    63         FrameworkMap **node);
    66 
       
    67 /* returns FWMgrTrue if processed successfully */
       
    68 static FWMgrBool tokenizeTag(FWMgrTagType tagType, const char* buffer, FrameworkMap **node);
       
    69 
    64 
    70 /* Crates a default rules config file */
    65 /* Crates a default rules config file */
    71 static int createDefaultRules(const char * filename);
    66 static int createDefaultRules(const char * filename);
    72 
    67 
    73 /* Global functions from header file */
    68 /* Global functions from header file */
    74 
    69 
    75 /* FrameworkMap* XAFrameworkMgr_CreateFrameworkMap
    70 /* FrameworkMap* XAFrameworkMgr_CreateFrameworkMap
    76  * Description: Creates a list of framework and use-case map.
    71  * Description: Creates a list of framework and use-case map.
    77  */
    72  */
    78 FrameworkMap* XAFrameworkMgr_CreateFrameworkMap()
    73 FrameworkMap* XAFrameworkMgr_CreateFrameworkMap()
    79 {
    74     {
    80     char buffer[LINEWIDTH];
    75     char buffer[LINEWIDTH];
    81     int readSize;
    76     int readSize;
    82     int lineNumber = 0;
    77     int lineNumber = 0;
    83     FWMgrBool processedEntry = FWMgrTrue;
    78     FWMgrBool processedEntry = FWMgrTrue;
    84     FWMgrMOType currentMediaType = FWMgrMOUnknown;
    79     FWMgrMOType currentMediaType = FWMgrMOUnknown;
    85     FWMgrFwType currentFrameworkType = FWMgrFWUknown;
    80     FWMgrFwType currentFrameworkType = FWMgrFWUknown;
    86     FWMgrTagType currentTagType = FWMgrTagNone;
    81     FWMgrTagType currentTagType = FWMgrTagNone;
    87     FrameworkMap *curNode = NULL;
    82     FrameworkMap *curNode = NULL;
    88     FWMgrBool newNode;
    83     FWMgrBool newNode;
    89     FrameworkMap *frameworkMap = NULL;
    84     FrameworkMap *frameworkMap = NULL;
    90     FILE* fp = fopen(configFileLocation, "r");
    85     FILE* fp = fopen(configFileLocationZ, "r");
    91     
    86 
    92     if (fp == NULL)
    87     if (fp == NULL)
    93         {
    88         {
    94         createDefaultRules(configFileLocation);
    89         createDefaultRules(configFileLocationC);
    95 
    90 
    96         fp = fopen(configFileLocation, "r");
    91         fp = fopen(configFileLocationC, "r");
    97         }
    92         }
    98 
    93 
    99     if (fp != NULL)
    94     if (fp != NULL)
   100     {
    95         {
   101         while((fgets(buffer, LINEWIDTH, fp) != NULL) && processedEntry)
    96         while ((fgets(buffer, LINEWIDTH, fp) != NULL) && processedEntry)
   102         {
    97             {
   103             /* keep looping until NULL pointer OR error... */
    98             /* keep looping until NULL pointer OR error... */
   104             lineNumber++;
    99             lineNumber++;
   105             readSize = strlen(buffer);
   100             readSize = strlen(buffer);
   106             /* Ignore comments line */
   101             /* Ignore comments line */
   107             if (buffer[0] == '#')
   102             if (buffer[0] == '#')
   108                 continue;
   103                 continue;
   109 
   104 
   110             /* Ignore replace "\r\n" with '\0' */
   105             /* Ignore replace "\r\n" with '\0' */
   111             if ((readSize >= 2) && (buffer[readSize-2]=='\r') && (buffer[readSize-1]=='\n'))
   106             if ((readSize >= 2) && (buffer[readSize - 2] == '\r')
   112                 buffer[readSize-2]='\0';
   107                     && (buffer[readSize - 1] == '\n'))
       
   108                 buffer[readSize - 2] = '\0';
   113 
   109 
   114             /* Ignore new line... */
   110             /* Ignore new line... */
   115             if (readSize == 2)
   111             if (readSize == 2)
   116                 continue;
   112                 continue;
   117 
   113 
   118             processedEntry = processConfigEntry(
   114             processedEntry = processConfigEntry(buffer, &currentMediaType,
   119                                 buffer,
   115                     &currentFrameworkType, &currentTagType, &newNode,
   120                                 &currentMediaType,
   116                     &curNode);
   121                                 &currentFrameworkType,
       
   122                                 &currentTagType,
       
   123                                 &newNode,
       
   124                                 &curNode);
       
   125             if (newNode)
   117             if (newNode)
   126             {
   118                 {
   127                 /*Just link to the last element in the chain*/
   119                 /*Just link to the last element in the chain*/
   128                 if (!frameworkMap)
   120                 if (!frameworkMap)
   129                 {
   121                     {
   130                     frameworkMap = curNode;
   122                     frameworkMap = curNode;
   131                 }
   123                     }
   132                 else
   124                 else
   133                 {
   125                     {
   134                     FrameworkMap *lastNode = frameworkMap;
   126                     FrameworkMap *lastNode = frameworkMap;
   135                     while (lastNode->next)
   127                     while (lastNode->next)
   136                     {
   128                         {
   137                         lastNode = lastNode->next;
   129                         lastNode = lastNode->next;
       
   130                         }
       
   131                     lastNode->next = curNode;
   138                     }
   132                     }
   139                     lastNode->next = curNode;
   133                 }
   140                 }
   134             }
   141             }
       
   142         }
       
   143         fclose(fp);
   135         fclose(fp);
   144     }
   136         }
   145     else
   137     else
   146     {
   138         {
   147         printf("unable to open config file!\n");
   139         printf("unable to open config file!\n");
   148     }
   140         }
   149     return frameworkMap;
   141     return frameworkMap;
   150 }
   142     }
   151 
   143 
   152 #ifdef _DEBUG
   144 #ifdef _DEBUG
   153 /* void XAFrameworkMgr_DumpFrameworkMap
   145 /* void XAFrameworkMgr_DumpFrameworkMap
   154  * Description: Prints map to std console.
   146  * Description: Prints map to std console.
   155  */
   147  */
   156 void XAFrameworkMgr_DumpFrameworkMap(FrameworkMap *map)
   148 void XAFrameworkMgr_DumpFrameworkMap(FrameworkMap *map)
   157 {
   149     {
   158     FrameworkMap *node = map;
   150     FrameworkMap *node = map;
   159     int i;
   151     int i;
   160     int loopIndex = 0;
   152     int loopIndex = 0;
   161     while (node)
   153     while (node)
   162     {
   154         {
   163         loopIndex++;
   155         loopIndex++;
   164         printf("%d>", loopIndex);
   156         printf("%d>", loopIndex);
   165         if (node->moType == FWMgrMOPlayer)
   157         if (node->moType == FWMgrMOPlayer)
   166             printf("MediaPlayer-");
   158             printf("MediaPlayer-");
   167         else if (node->moType == FWMgrMORecorder)
   159         else if (node->moType == FWMgrMORecorder)
   173         else if (node->fwType == FWMgrFWGST)
   165         else if (node->fwType == FWMgrFWGST)
   174             printf("GST-");
   166             printf("GST-");
   175         else
   167         else
   176             printf("UKNOWN-");
   168             printf("UKNOWN-");
   177         printf("Scheme[");
   169         printf("Scheme[");
   178         for(i=0;i<node->uriSchemeCount;i++)
   170         for (i = 0; i < node->uriSchemeCount; i++)
   179             printf(" %s", node->uriSchemes[i]);
   171             printf(" %s", node->uriSchemes[i]);
   180         printf("]FileExt[");
   172         printf("]FileExt[");
   181         for(i=0;i<node->fileExtCount;i++)
   173         for (i = 0; i < node->fileExtCount; i++)
   182             printf(" %s", node->fileExts[i]);
   174             printf(" %s", node->fileExts[i]);
   183         printf("]\n");
   175         printf("]\n");
   184         node = node->next;
   176         node = node->next;
   185     }
   177         }
   186 }
   178     }
   187 #endif
   179 #endif
   188 
   180 
   189 /* void XAFrameworkMgr_DeleteFrameworkMap
   181 /* void XAFrameworkMgr_DeleteFrameworkMap
   190  * Description: Deletes the list of framework and use-case map.
   182  * Description: Deletes the list of framework and use-case map.
   191  */
   183  */
   192 void XAFrameworkMgr_DeleteFrameworkMap(FrameworkMap **map)
   184 void XAFrameworkMgr_DeleteFrameworkMap(FrameworkMap **map)
   193 {
   185     {
   194     FrameworkMap *node = *map;
   186     FrameworkMap *node = *map;
   195     FrameworkMap *nextNode = NULL;
   187     FrameworkMap *nextNode = NULL;
   196     int i;
   188     int i;
   197     while (node)
   189     while (node)
   198     {
   190         {
   199         for(i=0;i<node->uriSchemeCount;i++)
   191         for (i = 0; i < node->uriSchemeCount; i++)
   200             free (node->uriSchemes[i]);
   192             free(node->uriSchemes[i]);
   201         free (node->uriSchemes);
   193         free(node->uriSchemes);
   202 
   194 
   203         for(i=0;i<node->fileExtCount;i++)
   195         for (i = 0; i < node->fileExtCount; i++)
   204             free (node->fileExts[i]);
   196             free(node->fileExts[i]);
   205         free (node->fileExts);
   197         free(node->fileExts);
   206 
   198 
   207         nextNode = node->next;
   199         nextNode = node->next;
   208         free (node);
   200         free(node);
   209         node = nextNode;
   201         node = nextNode;
   210     }
   202         }
   211     *map = NULL;
   203     *map = NULL;
   212 }
   204     }
   213 
   205 
   214 /* FWMgrFwType XAFrameworkMgr_GetFramework
   206 /* FWMgrFwType XAFrameworkMgr_GetFramework
   215  * Description: Returns the framework enum that handles uri.
   207  * Description: Returns the framework enum that handles uri.
   216  */
   208  */
   217 FWMgrFwType XAFrameworkMgr_GetFramework(
   209 FWMgrFwType XAFrameworkMgr_GetFramework(FrameworkMap *map, const char *uri,
   218                     FrameworkMap *map,
   210         FWMgrMOType mediaObject)
   219                     const char *uri,
   211     {
   220                     FWMgrMOType mediaObject)
       
   221 {
       
   222     FWMgrFwType retVal = FWMgrFWUknown;
   212     FWMgrFwType retVal = FWMgrFWUknown;
   223     char fileScheme[] = "file";
   213     char fileScheme[] = "file";
   224     char *uriScheme = NULL;
   214     char *uriScheme = NULL;
   225     char *fileExt = NULL;
   215     char *fileExt = NULL;
   226     FrameworkMap *node = map;
   216     FrameworkMap *node = map;
   228     FWMgrBool fileExtMatchFound = FWMgrFalse;
   218     FWMgrBool fileExtMatchFound = FWMgrFalse;
   229     int i = 0;
   219     int i = 0;
   230     int copyLen = 0;
   220     int copyLen = 0;
   231 
   221 
   232     if (!map || !uri)
   222     if (!map || !uri)
   233     {
   223         {
   234         /* TODO Log invalid uri */
   224         /* TODO Log invalid uri */
   235         return retVal;
   225         return retVal;
   236     }
   226         }
   237 
   227 
   238     /* Get uri scheme */
   228     /* Get uri scheme */
   239     uriScheme = strchr(uri, ':');
   229     uriScheme = strchr(uri, ':');
   240     if ( uriScheme == NULL)
   230     if (uriScheme == NULL)
   241     {
   231         {
   242         /* TODO Log invalid uri */
   232         /* TODO Log invalid uri */
   243         return retVal;
   233         return retVal;
   244     }
   234         }
   245 
   235 
   246     copyLen = (uriScheme - uri);
   236     copyLen = (uriScheme - uri);
   247     uriScheme = (char*)calloc(copyLen + 1, sizeof(char));
   237     uriScheme = (char*) calloc(copyLen + 1, sizeof(char));
   248     strncpy(uriScheme, uri, copyLen);
   238     strncpy(uriScheme, uri, copyLen);
   249     uriScheme[copyLen] = '\0'; /*Null terminate it*/
   239     uriScheme[copyLen] = '\0'; /*Null terminate it*/
   250 
   240 
   251     if (strcasecmp(uriScheme, fileScheme) == 0)
   241     if (strcasecmp(uriScheme, fileScheme) == 0)
   252     {
   242         {
   253         /* Get uri extension */
   243         /* Get uri extension */
   254         char* dotLoc = strrchr(uri, '.');
   244         char* dotLoc = strrchr(uri, '.');
   255         if ( dotLoc == NULL)
   245         if (dotLoc == NULL)
   256         {
   246             {
   257             /* TODO Log invalid uri */
   247             /* TODO Log invalid uri */
   258             free(uriScheme);
   248             free(uriScheme);
   259             return retVal;
   249             return retVal;
   260         }
   250             }
   261         /* We need to add 1 to exclude '.'*/
   251         /* We need to add 1 to exclude '.'*/
   262         copyLen = strlen(uri) - (dotLoc + 1 - uri);
   252         copyLen = strlen(uri) - (dotLoc + 1 - uri);
   263         fileExt = (char*)calloc(copyLen + 1, sizeof(char));
   253         fileExt = (char*) calloc(copyLen + 1, sizeof(char));
   264         strncpy(fileExt, dotLoc + 1, copyLen);
   254         strncpy(fileExt, dotLoc + 1, copyLen);
   265         fileExt[copyLen] = '\0'; /*Null terminate it*/
   255         fileExt[copyLen] = '\0'; /*Null terminate it*/
   266     }
   256         }
   267 
   257 
   268     while (node)
   258     while (node)
   269     {
   259         {
   270         if (mediaObject == node->moType)
   260         if (mediaObject == node->moType)
   271             {
   261             {
   272             uriMatchFound = FWMgrFalse;
   262             uriMatchFound = FWMgrFalse;
   273             fileExtMatchFound = FWMgrFalse;
   263             fileExtMatchFound = FWMgrFalse;
   274             /* Match for uri*/
   264             /* Match for uri*/
   275             for(i = 0; i < node->uriSchemeCount; i++)
   265             for (i = 0; i < node->uriSchemeCount; i++)
   276             {
   266                 {
   277                 if (strcasecmp(uriScheme, node->uriSchemes[i]) == 0)
   267                 if (strcasecmp(uriScheme, node->uriSchemes[i]) == 0)
   278                     {
   268                     {
   279                         uriMatchFound = FWMgrTrue;
   269                     uriMatchFound = FWMgrTrue;
   280                         break;
   270                     break;
   281                     }
   271                     }
   282             }
   272                 }
   283             /* if uri scheme is not file, we only need to check for uri */
   273             /* if uri scheme is not file, we only need to check for uri */
   284             if (!fileExt)
   274             if (!fileExt)
   285             {
   275                 {
   286                 fileExtMatchFound = FWMgrTrue;
   276                 fileExtMatchFound = FWMgrTrue;
   287             }
   277                 }
   288             else
   278             else
   289             {
   279                 {
   290                 for(i = 0; i < node->fileExtCount; i++)
   280                 for (i = 0; i < node->fileExtCount; i++)
   291                 {
   281                     {
   292                     if (strcasecmp(fileExt, node->fileExts[i]) == 0)
   282                     if (strcasecmp(fileExt, node->fileExts[i]) == 0)
   293                     {
   283                         {
   294                         fileExtMatchFound = FWMgrTrue;
   284                         fileExtMatchFound = FWMgrTrue;
   295                         break;
   285                         break;
       
   286                         }
   296                     }
   287                     }
   297                 }
   288                 }
   298             }
   289 
   299 
   290             if ((uriMatchFound == FWMgrTrue) && (fileExtMatchFound
   300             if ((uriMatchFound == FWMgrTrue) &&
   291                     == FWMgrTrue))
   301                 (fileExtMatchFound == FWMgrTrue))
   292                 {
   302                 {
   293                 retVal = node->fwType;
   303                     retVal = node->fwType;
   294                 break;
   304                     break;
       
   305                 }
   295                 }
   306             }
   296             }
   307         node = node->next;
   297         node = node->next;
   308     }
   298         }
   309     free(uriScheme);
   299     free(uriScheme);
   310     free(fileExt);
   300     free(fileExt);
   311     return retVal;
   301     return retVal;
   312 }
   302     }
   313 
   303 
   314 /* Local functions */
   304 /* Local functions */
   315 
   305 
   316 /* FWMgrBool processConfigEntry
   306 /* FWMgrBool processConfigEntry
   317  * Description: Processes a single line entry from the config file.
   307  * Description: Processes a single line entry from the config file.
   318  */
   308  */
   319 FWMgrBool processConfigEntry(
   309 FWMgrBool processConfigEntry(const char* buffer, FWMgrMOType *mediaType,
   320         const char* buffer,
   310         FWMgrFwType *frameworkType, FWMgrTagType *tagType,
   321         FWMgrMOType *mediaType,
   311         FWMgrBool *newNode, FrameworkMap **node)
   322         FWMgrFwType *frameworkType,
   312     {
   323         FWMgrTagType *tagType,
       
   324         FWMgrBool *newNode,
       
   325         FrameworkMap **node)
       
   326 {
       
   327     FWMgrBool processedSuccessfully = FWMgrTrue;
   313     FWMgrBool processedSuccessfully = FWMgrTrue;
   328     *newNode = FWMgrFalse;
   314 
       
   315     if (!buffer || !mediaType || !frameworkType || !tagType || !newNode)
       
   316         {
       
   317         processedSuccessfully = FWMgrFalse;
       
   318         return processedSuccessfully;
       
   319         }
       
   320 
       
   321 	*newNode = FWMgrFalse;
   329     switch (*mediaType)
   322     switch (*mediaType)
   330     {
   323         {
   331         case FWMgrMOUnknown:
   324         case FWMgrMOUnknown:
   332         {
   325             {
   333             if (strcmp(buffer, mediaPlayerBeginTag) == 0)
   326             if (strcmp(buffer, mediaPlayerBeginTag) == 0)
   334             {
   327                 {
   335                 *mediaType = FWMgrMOPlayer;
   328                 *mediaType = FWMgrMOPlayer;
   336                 *frameworkType = FWMgrFWUknown;
   329                 *frameworkType = FWMgrFWUknown;
   337                 *tagType = FWMgrTagNone;
   330                 *tagType = FWMgrTagNone;
   338                 *node = NULL;
   331                 *node = NULL;
   339             }
   332                 }
   340             else if (strcmp(buffer, mediaRecorderBeginTag) == 0)
   333             else if (strcmp(buffer, mediaRecorderBeginTag) == 0)
   341             {
   334                 {
   342                 *mediaType = FWMgrMORecorder;
   335                 *mediaType = FWMgrMORecorder;
   343                 *frameworkType = FWMgrFWUknown;
   336                 *frameworkType = FWMgrFWUknown;
   344                 *tagType = FWMgrTagNone;
   337                 *tagType = FWMgrTagNone;
   345                 *node = NULL;
   338                 *node = NULL;
   346             }
   339                 }
   347         }
   340             }
   348             break;
   341             break;
   349         case FWMgrMOPlayer:
   342         case FWMgrMOPlayer:
   350         case FWMgrMORecorder:
   343         case FWMgrMORecorder:
   351         {
   344             {
   352             switch (*frameworkType)
   345             switch (*frameworkType)
   353             {
   346                 {
   354                 case FWMgrFWUknown:
   347                 case FWMgrFWUknown:
   355                 {
   348                     {
   356                     if ((*mediaType == FWMgrMOPlayer) && (strcmp(buffer, mediaPlayerEndTag) == 0))
   349                     if ((*mediaType == FWMgrMOPlayer) && (strcmp(buffer,
       
   350                             mediaPlayerEndTag) == 0))
   357                         *mediaType = FWMgrMOUnknown;
   351                         *mediaType = FWMgrMOUnknown;
   358                     else if ((*mediaType == FWMgrMORecorder) && (strcmp(buffer, mediaRecorderEndTag) == 0))
   352                     else if ((*mediaType == FWMgrMORecorder) && (strcmp(
       
   353                             buffer, mediaRecorderEndTag) == 0))
   359                         *mediaType = FWMgrMOUnknown;
   354                         *mediaType = FWMgrMOUnknown;
   360                     else if ( (strcmp(buffer, mediaFrameworkMmfBeginTag) == 0) ||
   355                     else if ((strcmp(buffer, mediaFrameworkMmfBeginTag) == 0)
   361                               (strcmp(buffer, mediaFrameworkGstBeginTag) == 0) )
   356                             || (strcmp(buffer, mediaFrameworkGstBeginTag)
   362                     {
   357                                     == 0))
       
   358                         {
       
   359 
   363                         *frameworkType = FWMgrFWMMF;
   360                         *frameworkType = FWMgrFWMMF;
   364                         if (strcmp(buffer, mediaFrameworkGstBeginTag) == 0)
   361                         if (strcmp(buffer, mediaFrameworkGstBeginTag) == 0)
   365                             *frameworkType = FWMgrFWGST;
   362                             *frameworkType = FWMgrFWGST;
   366                         if (*node)
   363                         if (*node)
   367                         {
   364                             {
   368                             printf("Fatal error error. Entry already exists and creating another one!!!");
   365                             printf(
   369                             return FWMgrFalse;
   366                                     "Fatal error error. Entry already exists and creating another one!!!");
       
   367                             processedSuccessfully = FWMgrFalse;
       
   368                             }
       
   369                         else
       
   370                             {
       
   371                             *node = (FrameworkMap*) calloc(1,
       
   372                                     sizeof(FrameworkMap));
       
   373                             if (!(*node))
       
   374                                 {
       
   375                                 printf(
       
   376                                         "Fatal error. No memory to create an Entry!!!");
       
   377                                 processedSuccessfully = FWMgrFalse;
       
   378                                 }
       
   379                             else
       
   380                                 {
       
   381                                 *newNode = FWMgrTrue;
       
   382                                 (*node)->moType = *mediaType;
       
   383                                 (*node)->fwType = *frameworkType;
       
   384                                 }
       
   385                             }
   370                         }
   386                         }
   371                         *node = (FrameworkMap*)calloc(1, sizeof(FrameworkMap));
       
   372                         if (!(*node))
       
   373                         {
       
   374                             printf("Fatal error. No memory to create an Entry!!!");
       
   375                             return FWMgrFalse;
       
   376                         }
       
   377                         *newNode = FWMgrTrue;
       
   378                         (*node)->moType = *mediaType;
       
   379                         (*node)->fwType = *frameworkType;
       
   380                     }
   387                     }
   381                 }
       
   382                     break;
   388                     break;
   383                 case FWMgrFWMMF:
   389                 case FWMgrFWMMF:
   384                 {
   390                     {
   385                     processedSuccessfully = processTagType(
   391                     processedSuccessfully = processTagType(buffer,
   386                                                 buffer,
   392                             frameworkType, tagType, node);
   387                                                 frameworkType,
   393                     }
   388                                                 tagType,
       
   389                                                 node);
       
   390                 }
       
   391                     break;
   394                     break;
   392                 case FWMgrFWGST:
   395                 case FWMgrFWGST:
   393                 {
   396                     {
   394                     processedSuccessfully = processTagType(
   397                     processedSuccessfully = processTagType(buffer,
   395                                                 buffer,
   398                             frameworkType, tagType, node);
   396                                                 frameworkType,
   399                     }
   397                                                 tagType,
       
   398                                                 node);
       
   399                 }
       
   400                     break;
   400                     break;
   401                 default:
   401                 default:
   402                     processedSuccessfully = FWMgrFalse;
   402                     processedSuccessfully = FWMgrFalse;
   403                     break;
   403                     break;
   404             };
   404                 };
   405         }
   405             }
   406             break;
   406             break;
   407         default:
   407         default:
   408             processedSuccessfully = FWMgrFalse;
   408             processedSuccessfully = FWMgrFalse;
   409             break;
   409             break;
   410     };
   410         };
   411     return processedSuccessfully;
   411     return processedSuccessfully;
   412 }
   412     }
   413 
   413 
   414 /* FWMgrBool processTagType
   414 /* FWMgrBool processTagType
   415  * Description: Processes a framework type, uri, file tags entry from the config file.
   415  * Description: Processes a framework type, uri, file tags entry from 
   416  */
   416  * the config file.
   417 FWMgrBool processTagType(const char* buffer,
   417  */
   418         FWMgrFwType *frameworkType,
   418 FWMgrBool processTagType(const char* buffer, FWMgrFwType *frameworkType,
   419         FWMgrTagType *tagType,
   419         FWMgrTagType *tagType, FrameworkMap **node)
   420         FrameworkMap **node)
   420     {
   421 {
       
   422     FWMgrBool processedSuccessfully = FWMgrTrue;
   421     FWMgrBool processedSuccessfully = FWMgrTrue;
       
   422 
       
   423     if (!buffer || !frameworkType || !tagType || (*node == NULL))
       
   424         {
       
   425         processedSuccessfully = FWMgrFalse;
       
   426         return processedSuccessfully;
       
   427         }
       
   428 
   423     switch (*tagType)
   429     switch (*tagType)
   424     {
   430         {
   425         case FWMgrTagNone:
   431         case FWMgrTagNone:
   426         {
   432             {
   427             if (((*frameworkType == FWMgrFWMMF) && (strcmp(buffer, mediaFrameworkMmfEndTag) == 0)) ||
   433             if (((*frameworkType == FWMgrFWMMF) && (strcmp(buffer,
   428                 ((*frameworkType == FWMgrFWGST) && (strcmp(buffer, mediaFrameworkGstEndTag) == 0)))
   434                     mediaFrameworkMmfEndTag) == 0)) || ((*frameworkType
   429             {
   435                     == FWMgrFWGST)
       
   436                     && (strcmp(buffer, mediaFrameworkGstEndTag) == 0)))
       
   437                 {
   430                 *node = NULL;
   438                 *node = NULL;
   431                 *frameworkType = FWMgrFWUknown;
   439                 *frameworkType = FWMgrFWUknown;
   432             }
   440                 }
   433             else if (strcmp(buffer, uriSchemeBeginTag) == 0)
   441             else if (strcmp(buffer, uriSchemeBeginTag) == 0)
   434                 *tagType = FWMgrTagURIScheme;
   442                 *tagType = FWMgrTagURIScheme;
   435             else if (strcmp(buffer, fileExtBeginTag) == 0)
   443             else if (strcmp(buffer, fileExtBeginTag) == 0)
   436                 *tagType = FWMgrTagFileExt;
   444                 *tagType = FWMgrTagFileExt;
   437         }
   445             }
   438             break;
   446             break;
   439         case FWMgrTagURIScheme:
   447         case FWMgrTagURIScheme:
   440         {
   448             {
   441             if (strcmp(buffer, uriSchemeEndTag) == 0)
   449             if (strcmp(buffer, uriSchemeEndTag) == 0)
   442                 *tagType = FWMgrTagNone;
   450                 *tagType = FWMgrTagNone;
   443             else
   451             else
   444             {
   452                 {
   445                 processedSuccessfully = FWMgrFalse;
   453                 processedSuccessfully = FWMgrFalse;
   446                 if (*node)
   454                 if (*node)
   447                     processedSuccessfully = tokenizeTag(FWMgrTagURIScheme, buffer, node);
   455                     processedSuccessfully = tokenizeTag(FWMgrTagURIScheme,
   448             }
   456                             buffer, node);
   449         }
   457                 }
       
   458             }
   450             break;
   459             break;
   451         case FWMgrTagFileExt:
   460         case FWMgrTagFileExt:
   452         {
   461             {
   453             if (strcmp(buffer, fileExtEndTag) == 0)
   462             if (strcmp(buffer, fileExtEndTag) == 0)
   454                 *tagType = FWMgrTagNone;
   463                 *tagType = FWMgrTagNone;
   455             else
   464             else
   456             {
   465                 {
   457                 processedSuccessfully = FWMgrFalse;
   466                 processedSuccessfully = FWMgrFalse;
   458                 if (*node)
   467                 if (*node)
   459                     processedSuccessfully = tokenizeTag(FWMgrTagFileExt, buffer, node);
   468                     processedSuccessfully = tokenizeTag(FWMgrTagFileExt,
   460             }
   469                             buffer, node);
   461         }
   470                 }
       
   471             }
   462             break;
   472             break;
   463         default:
   473         default:
       
   474             processedSuccessfully = FWMgrFalse;
   464             break;
   475             break;
   465     };
   476         };
   466     return processedSuccessfully;
   477     return processedSuccessfully;
   467 }
   478     }
   468 
   479 
   469 /* FWMgrBool processTagType
   480 /* FWMgrBool processTagType
   470  * Description: Processes a framework type, uri, file tags entry from the config file.
   481  * Description: Processes a framework type, uri, file tags entry from 
   471  */
   482  * the config file.
   472 FWMgrBool tokenizeTag(FWMgrTagType tagType, const char* buffer, FrameworkMap **node)
   483  */
   473 {
   484 FWMgrBool tokenizeTag(FWMgrTagType tagType, const char* buffer,
   474     char* tempStartPtr = /*const_cast<char*>*/(char*)(buffer);
   485         FrameworkMap **node)
   475     char* tempEndPtr = /*const_cast<char*>*/(char*)(buffer);
   486     {
       
   487     char* tempStartPtr;
       
   488     char* tempEndPtr;
   476     int index = 0;
   489     int index = 0;
   477     int strLen = 0;
   490     int strLen = 0;
   478 
   491 
       
   492     if (!buffer || (*node == NULL))
       
   493         {
       
   494         return FWMgrFalse;
       
   495         }
       
   496 
       
   497     tempStartPtr = /*const_cast<char*>*/(char*) (buffer);
       
   498     tempEndPtr = /*const_cast<char*>*/(char*) (buffer);
       
   499 
   479     if (tagType == FWMgrTagURIScheme)
   500     if (tagType == FWMgrTagURIScheme)
   480     {
   501         {
   481         (*node)->uriSchemeCount = atoi(buffer);
   502         (*node)->uriSchemeCount = atoi(buffer);
   482         (*node)->uriSchemes =  (char**)calloc((*node)->uriSchemeCount,  sizeof (*((*node)->uriSchemes)));
   503         (*node)->uriSchemes = (char**) calloc((*node)->uriSchemeCount,
       
   504                 sizeof(*((*node)->uriSchemes)));
   483         if (!(*node)->uriSchemes)
   505         if (!(*node)->uriSchemes)
   484         {
   506             {
   485             printf("Fatal error. No memory to create an Entry!!!");
   507             printf("Fatal error. No memory to create an Entry!!!");
   486             return FWMgrFalse;
   508             return FWMgrFalse;
   487         }
   509             }
   488     }
   510         }
   489     else if (tagType == FWMgrTagFileExt)
   511     else if (tagType == FWMgrTagFileExt)
   490     {
   512         {
   491         (*node)->fileExtCount = atoi(buffer);
   513         (*node)->fileExtCount = atoi(buffer);
   492         (*node)->fileExts =  (char**)calloc((*node)->fileExtCount,  sizeof (*((*node)->fileExts)));
   514         (*node)->fileExts = (char**) calloc((*node)->fileExtCount,
       
   515                 sizeof(*((*node)->fileExts)));
   493         if (!(*node)->fileExts)
   516         if (!(*node)->fileExts)
   494         {
   517             {
   495             printf("Fatal error. No memory to create an Entry!!!");
   518             printf("Fatal error. No memory to create an Entry!!!");
   496             return FWMgrFalse;
   519             return FWMgrFalse;
   497         }
   520             }
   498     }
   521         }
   499     else
   522     else
   500         return FWMgrFalse;
   523         return FWMgrFalse;
   501 
   524 
   502     /*Find the index of :*/
   525     /*Find the index of :*/
   503     tempStartPtr = strchr(tempStartPtr, ',');
   526     tempStartPtr = strchr(tempStartPtr, ',');
   504     index = 0;
   527     index = 0;
   505     while (tempStartPtr && (strlen(tempStartPtr) > 1))
   528     while (tempStartPtr && (strlen(tempStartPtr) > 1))
   506     {
   529         {
   507         tempStartPtr++; /* Ignore separator ','*/
   530         tempStartPtr++; /* Ignore separator ','*/
   508         tempEndPtr = strchr(tempStartPtr, ',');
   531         tempEndPtr = strchr(tempStartPtr, ',');
   509         strLen = (tempEndPtr - tempStartPtr) + 1; /* To hold null terminator */
   532         strLen = (tempEndPtr - tempStartPtr) + 1; /* To hold null terminator */
   510         if (strLen > 0)
   533         if (strLen > 0)
   511         {
   534             {
   512             if (tagType == FWMgrTagURIScheme)
   535             if (tagType == FWMgrTagURIScheme)
   513             {
   536                 {
   514                 (*node)->uriSchemes[index] = (char*)calloc(strLen, sizeof(char));
   537                 (*node)->uriSchemes[index] = (char*) calloc(strLen,
       
   538                         sizeof(char));
   515                 strncpy((*node)->uriSchemes[index], tempStartPtr, strLen);
   539                 strncpy((*node)->uriSchemes[index], tempStartPtr, strLen);
   516                 (*node)->uriSchemes[index][strLen-1] = '\0'; /*Null terminate it*/
   540                 (*node)->uriSchemes[index][strLen - 1] = '\0'; /*Null terminate it*/
   517                 index++;
   541                 index++;
   518             }
   542                 }
   519             else if (tagType == FWMgrTagFileExt)
   543             else if (tagType == FWMgrTagFileExt)
   520             {
   544                 {
   521                 (*node)->fileExts[index] = (char*)calloc(strLen, sizeof(char));
   545                 (*node)->fileExts[index] = (char*) calloc(strLen,
       
   546                         sizeof(char));
   522                 strncpy((*node)->fileExts[index], tempStartPtr, strLen);
   547                 strncpy((*node)->fileExts[index], tempStartPtr, strLen);
   523                 (*node)->fileExts[index][strLen-1] = '\0'; /*Null terminate it*/
   548                 (*node)->fileExts[index][strLen - 1] = '\0'; /*Null terminate it*/
   524                 index++;
   549                 index++;
   525             }
   550                 }
   526         }
   551             }
   527         tempStartPtr = tempEndPtr;
   552         tempStartPtr = tempEndPtr;
   528     }
   553         }
   529     return FWMgrTrue;
   554     return FWMgrTrue;
   530 }
   555     }
   531 
   556 
   532 int createDefaultRules(const char * filename)
   557 int createDefaultRules(const char * filename)
   533 {
   558     {
   534     FILE* fp = fopen(filename, "w");
   559     FILE* fp = fopen(filename, "w");
   535     if (fp == NULL)
   560     if (fp == NULL)
   536         return /*KErrAccessDenied*/-21;
   561         return /*KErrAccessDenied*/-21;
   537     fputs("#/*\r\n", fp);
   562     fputs("#/*\r\n", fp);
   538     fputs("#* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).\r\n", fp);
   563     fputs(
       
   564             "#* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).\r\n",
       
   565             fp);
   539     fputs("#* All rights reserved.\r\n", fp);
   566     fputs("#* All rights reserved.\r\n", fp);
   540     fputs("#* This component and the accompanying materials are made available\r\n", fp);
   567     fputs(
       
   568             "#* This component and the accompanying materials are made available\r\n",
       
   569             fp);
   541     fputs("#* under the terms of \"Eclipse Public License v1.0\"\r\n", fp);
   570     fputs("#* under the terms of \"Eclipse Public License v1.0\"\r\n", fp);
   542     fputs("#* which accompanies this distribution, and is available\r\n", fp);
   571     fputs("#* which accompanies this distribution, and is available\r\n", fp);
   543     fputs("#* at the URL \"http://www.eclipse.org/legal/epl-v10.html\".\r\n", fp);
   572     fputs("#* at the URL \"http://www.eclipse.org/legal/epl-v10.html\".\r\n",
       
   573             fp);
   544     fputs("#*\r\n", fp);
   574     fputs("#*\r\n", fp);
   545     fputs("#* Initial Contributors:\r\n", fp);
   575     fputs("#* Initial Contributors:\r\n", fp);
   546     fputs("#* Nokia Corporation - initial contribution.\r\n", fp);
   576     fputs("#* Nokia Corporation - initial contribution.\r\n", fp);
   547     fputs("#*\r\n", fp);
   577     fputs("#*\r\n", fp);
   548     fputs("#* Contributors:\r\n", fp);
   578     fputs("#* Contributors:\r\n", fp);
   549     fputs("#*\r\n", fp);
   579     fputs("#*\r\n", fp);
   550     fputs("#* Description:\r\n", fp); 
   580     fputs("#* Description:\r\n", fp);
   551     fputs("#*\r\n", fp);
   581     fputs("#*\r\n", fp);
   552     fputs("#*/\r\n", fp);
   582     fputs("#*/\r\n", fp);
   553     fputs("#============================================================================>|\r\n", fp);
   583     fputs(
   554     fputs("# Must not exceed 80 chars each line=========================================>|\r\n", fp);
   584             "#============================================================================>|\r\n",
   555     fputs("#============================================================================>|\r\n", fp);
   585             fp);
       
   586     fputs(
       
   587             "# Must not exceed 80 chars each line=========================================>|\r\n",
       
   588             fp);
       
   589     fputs(
       
   590             "#============================================================================>|\r\n",
       
   591             fp);
   556     fputs("<mediaplayer>\r\n", fp);
   592     fputs("<mediaplayer>\r\n", fp);
   557     fputs("<mmf>\r\n", fp);
   593     fputs("<mmf>\r\n", fp);
   558     fputs("<urischeme>\r\n", fp);
   594     fputs("<urischeme>\r\n", fp);
   559     fputs("# Num of entries followed by actual entries all ending with a comma\r\n", fp);
   595     fputs(
   560     fputs("3,file,http,rtsp,\r\n", fp);
   596             "# Num of entries followed by actual entries all ending with a comma\r\n",
       
   597             fp);
       
   598     fputs("6,file,http,rtsp,rtspu,rtspt,mms,\r\n", fp);
   561     fputs("</urischeme>\r\n", fp);
   599     fputs("</urischeme>\r\n", fp);
   562     fputs("<fileext>\r\n", fp);
   600     fputs("<fileext>\r\n", fp);
   563     fputs("15,3gp,wma,wmv,wav,amr,mp3,mp4,rm,ra,avi,mkv,aac,mid,awb,3g2,\r\n", fp);
   601     fputs(
       
   602             "15,3gp,wma,wmv,wav,amr,mp3,mp4,rm,ra,avi,mkv,aac,mid,awb,3g2,\r\n",
       
   603             fp);
   564     fputs("</fileext>\r\n", fp);
   604     fputs("</fileext>\r\n", fp);
   565     fputs("</mmf>\r\n", fp);
   605     fputs("</mmf>\r\n", fp);
   566     fputs("</mediaplayer>\r\n", fp);
   606     fputs("</mediaplayer>\r\n", fp);
   567     fputs("<mediarecorder>\r\n", fp);
   607     fputs("<mediarecorder>\r\n", fp);
   568     fputs("<gst>\r\n", fp);
   608     fputs("<gst>\r\n", fp);
   569     fputs("<urischeme>\r\n", fp);
   609     fputs("<urischeme>\r\n", fp);
   570     fputs("# Num of entries followed by actual entries all ending with a comma\r\n", fp);
   610     fputs(
       
   611             "# Num of entries followed by actual entries all ending with a comma\r\n",
       
   612             fp);
   571     fputs("1,file,\r\n", fp);
   613     fputs("1,file,\r\n", fp);
   572     fputs("</urischeme>\r\n", fp);
   614     fputs("</urischeme>\r\n", fp);
   573     fputs("<fileext>\r\n", fp);
   615     fputs("<fileext>\r\n", fp);
   574     fputs("3,wav,amr,mp4,\r\n", fp);
   616     fputs("3,wav,amr,mp4,\r\n", fp);
   575     fputs("</fileext>\r\n", fp);
   617     fputs("</fileext>\r\n", fp);
   576     fputs("</gst>\r\n", fp);
   618     fputs("</gst>\r\n", fp);
   577     fputs("</mediarecorder>\r\n", fp);
   619     fputs("</mediarecorder>\r\n", fp);
   578     fclose(fp);
   620     fclose(fp);
   579     return 0;
   621     return 0;
   580 }
   622     }