khronosfws/openmax_al/src/adptcommon/xaframeworkmgr.c
changeset 55 e267340986c9
parent 42 1fa3fb47b1e3
equal deleted inserted replaced
52:4ce423f34688 55:e267340986c9
    16  */
    16  */
    17 
    17 
    18 #include <stdio.h>
    18 #include <stdio.h>
    19 #include <string.h>
    19 #include <string.h>
    20 #include "xaframeworkmgr.h"
    20 #include "xaframeworkmgr.h"
       
    21 #include "xadebug.h"
    21 
    22 
    22 /* Default line width permitted in the cfg file + 2 to hold "\r\n"*/
    23 /* Default line width permitted in the cfg file + 2 to hold "\r\n"*/
    23 #define LINEWIDTH 82
    24 #define LINEWIDTH 82
    24 
    25 
    25 typedef enum
    26 typedef enum
    77     FWMgrFwType currentFrameworkType = FWMgrFWUknown;
    78     FWMgrFwType currentFrameworkType = FWMgrFWUknown;
    78     FWMgrTagType currentTagType = FWMgrTagNone;
    79     FWMgrTagType currentTagType = FWMgrTagNone;
    79     FrameworkMap *curNode = NULL;
    80     FrameworkMap *curNode = NULL;
    80     FWMgrBool newNode;
    81     FWMgrBool newNode;
    81     FrameworkMap *frameworkMap = NULL;
    82     FrameworkMap *frameworkMap = NULL;
    82 
    83     FILE* fp = NULL;
    83     FILE* fp = fopen(configFileLocationC, "r");
    84 
       
    85     DEBUG_API("->XAFrameworkMgr_CreateFrameworkMap");
       
    86     /* Open file on C drive */
       
    87     DEBUG_INFO("Opening configuration file from C drive...");
       
    88     fp = fopen(configFileLocationC, "r");
    84     if (fp == NULL)
    89     if (fp == NULL)
    85         {
    90         {
       
    91         DEBUG_INFO("Opening configuration file from Z drive...");
    86         fp = fopen(configFileLocationZ, "r");
    92         fp = fopen(configFileLocationZ, "r");
    87         }
    93         }
    88 
    94 
    89     if (fp != NULL)
    95     if (fp == NULL)
    90         {
    96         {
    91         while ((fgets(buffer, LINEWIDTH, fp) != NULL) && processedEntry)
    97         DEBUG_ERR("ERROR: Unable to open configuration file!");
    92             {
    98         DEBUG_API("<-XAFrameworkMgr_CreateFrameworkMap");
    93             /* keep looping until NULL pointer OR error... */
    99         return NULL;
    94             lineNumber++;
   100         }
    95             readSize = strlen(buffer);
   101     while ((fgets(buffer, LINEWIDTH, fp) != NULL) && processedEntry)
    96             /* Ignore comments line */
   102         {
    97             if (buffer[0] == '#')
   103         /* keep looping until NULL pointer OR error... */
    98                 continue;
   104         lineNumber++;
    99 
   105         readSize = strlen(buffer);
   100             /* Ignore replace "\r\n" with '\0' */
   106         /* Ignore comments line */
   101             if ((readSize >= 2) && (buffer[readSize - 2] == '\r')
   107         if (buffer[0] == '#')
   102                     && (buffer[readSize - 1] == '\n'))
   108             continue;
   103                 buffer[readSize - 2] = '\0';
   109 
   104 
   110         /* Ignore replace "\r\n" with '\0' */
   105             /* Ignore new line... */
   111         if ((readSize >= 2) && (buffer[readSize - 2] == '\r')
   106             if (readSize == 2)
   112                 && (buffer[readSize - 1] == '\n'))
   107                 continue;
   113             buffer[readSize - 2] = '\0';
   108 
   114 
   109             processedEntry = processConfigEntry(buffer, &currentMediaType,
   115         /* Ignore new line... */
   110                     &currentFrameworkType, &currentTagType, &newNode,
   116         if (readSize == 2)
   111                     &curNode);
   117             continue;
   112             if (newNode)
   118 
   113                 {
   119         processedEntry = processConfigEntry(buffer, &currentMediaType,
   114                 /*Just link to the last element in the chain*/
   120                 &currentFrameworkType, &currentTagType, &newNode,
   115                 if (!frameworkMap)
   121                 &curNode);
       
   122         if (newNode)
       
   123             {
       
   124             /*Just link to the last element in the chain*/
       
   125             if (!frameworkMap)
       
   126                 {
       
   127                 frameworkMap = curNode;
       
   128                 }
       
   129             else
       
   130                 {
       
   131                 FrameworkMap *lastNode = frameworkMap;
       
   132                 while (lastNode->next)
   116                     {
   133                     {
   117                     frameworkMap = curNode;
   134                     lastNode = lastNode->next;
   118                     }
   135                     }
   119                 else
   136                 lastNode->next = curNode;
   120                     {
   137                 }
   121                     FrameworkMap *lastNode = frameworkMap;
   138             }
   122                     while (lastNode->next)
   139         }
   123                         {
   140     fclose(fp);
   124                         lastNode = lastNode->next;
   141     DEBUG_API("<-XAFrameworkMgr_CreateFrameworkMap");
   125                         }
       
   126                     lastNode->next = curNode;
       
   127                     }
       
   128                 }
       
   129             }
       
   130         fclose(fp);
       
   131         }
       
   132     else
       
   133         {
       
   134         printf("unable to open config file!\n");
       
   135         }
       
   136     return frameworkMap;
   142     return frameworkMap;
   137     }
   143     }
   138 
   144 
   139 #ifdef _DEBUG
   145 #ifdef _DEBUG
   140 /* void XAFrameworkMgr_DumpFrameworkMap
   146 /* void XAFrameworkMgr_DumpFrameworkMap
   143 void XAFrameworkMgr_DumpFrameworkMap(FrameworkMap *map)
   149 void XAFrameworkMgr_DumpFrameworkMap(FrameworkMap *map)
   144     {
   150     {
   145     FrameworkMap *node = map;
   151     FrameworkMap *node = map;
   146     int i;
   152     int i;
   147     int loopIndex = 0;
   153     int loopIndex = 0;
       
   154 
       
   155     DEBUG_API("->XAFrameworkMgr_DumpFrameworkMap");
   148     while (node)
   156     while (node)
   149         {
   157         {
   150         loopIndex++;
   158         loopIndex++;
   151         printf("%d>", loopIndex);
   159         DEBUG_INFO_A1("%d>", loopIndex);
   152         if (node->moType == FWMgrMOPlayer)
   160         if (node->moType == FWMgrMOPlayer)
   153             printf("MediaPlayer-");
   161             {
       
   162             DEBUG_INFO("MediaPlayer-");
       
   163             }
   154         else if (node->moType == FWMgrMORecorder)
   164         else if (node->moType == FWMgrMORecorder)
   155             printf("MediaRecrdr-");
   165             {
       
   166             DEBUG_INFO("MediaRecrdr-");
       
   167             }
   156         else
   168         else
   157             printf("UKNOWN-");
   169             {
       
   170             DEBUG_INFO("UKNOWN-");
       
   171             }
   158         if (node->fwType == FWMgrFWMMF)
   172         if (node->fwType == FWMgrFWMMF)
   159             printf("MMF-");
   173             {
       
   174             DEBUG_INFO("MMF-");
       
   175             }
   160         else if (node->fwType == FWMgrFWGST)
   176         else if (node->fwType == FWMgrFWGST)
   161             printf("GST-");
   177             {
       
   178             DEBUG_INFO("GST-");
       
   179             }
   162         else
   180         else
   163             printf("UKNOWN-");
   181             {
   164         printf("Scheme[");
   182             DEBUG_INFO("UKNOWN-");
       
   183             }
       
   184         DEBUG_INFO("Scheme[");
   165         for (i = 0; i < node->uriSchemeCount; i++)
   185         for (i = 0; i < node->uriSchemeCount; i++)
   166             printf(" %s", node->uriSchemes[i]);
   186             {
       
   187             DEBUG_INFO_A1_STR(" %s", node->uriSchemes[i]);
       
   188             }
   167         printf("]FileExt[");
   189         printf("]FileExt[");
   168         for (i = 0; i < node->fileExtCount; i++)
   190         for (i = 0; i < node->fileExtCount; i++)
   169             printf(" %s", node->fileExts[i]);
   191             {
   170         printf("]\n");
   192             DEBUG_INFO_A1_STR(" %s", node->fileExts[i]);
       
   193             }
       
   194         DEBUG_INFO("]\n");
   171         node = node->next;
   195         node = node->next;
   172         }
   196         }
       
   197     DEBUG_API("<-XAFrameworkMgr_DumpFrameworkMap");
   173     }
   198     }
   174 #endif
   199 #endif
   175 
   200 
   176 /* void XAFrameworkMgr_DeleteFrameworkMap
   201 /* void XAFrameworkMgr_DeleteFrameworkMap
   177  * Description: Deletes the list of framework and use-case map.
   202  * Description: Deletes the list of framework and use-case map.
   179 void XAFrameworkMgr_DeleteFrameworkMap(FrameworkMap **map)
   204 void XAFrameworkMgr_DeleteFrameworkMap(FrameworkMap **map)
   180     {
   205     {
   181     FrameworkMap *node = *map;
   206     FrameworkMap *node = *map;
   182     FrameworkMap *nextNode = NULL;
   207     FrameworkMap *nextNode = NULL;
   183     int i;
   208     int i;
       
   209     DEBUG_API("->XAFrameworkMgr_DeleteFrameworkMap");
   184     while (node)
   210     while (node)
   185         {
   211         {
   186         for (i = 0; i < node->uriSchemeCount; i++)
   212         for (i = 0; i < node->uriSchemeCount; i++)
   187             free(node->uriSchemes[i]);
   213             free(node->uriSchemes[i]);
   188         free(node->uriSchemes);
   214         free(node->uriSchemes);
   194         nextNode = node->next;
   220         nextNode = node->next;
   195         free(node);
   221         free(node);
   196         node = nextNode;
   222         node = nextNode;
   197         }
   223         }
   198     *map = NULL;
   224     *map = NULL;
       
   225     DEBUG_API("<-XAFrameworkMgr_DeleteFrameworkMap");
   199     }
   226     }
   200 
   227 
   201 /* FWMgrFwType XAFrameworkMgr_GetFramework
   228 /* FWMgrFwType XAFrameworkMgr_GetFramework
   202  * Description: Returns the framework enum that handles uri.
   229  * Description: Returns the framework enum that handles uri.
   203  */
   230  */
   212     FWMgrBool uriMatchFound = FWMgrFalse;
   239     FWMgrBool uriMatchFound = FWMgrFalse;
   213     FWMgrBool fileExtMatchFound = FWMgrFalse;
   240     FWMgrBool fileExtMatchFound = FWMgrFalse;
   214     int i = 0;
   241     int i = 0;
   215     int copyLen = 0;
   242     int copyLen = 0;
   216 
   243 
       
   244     DEBUG_API("->XAFrameworkMgr_GetFramework");
   217     if (!map || !uri)
   245     if (!map || !uri)
   218         {
   246         {
   219         /* TODO Log invalid uri */
   247         DEBUG_ERR("NULL map/uri");
       
   248         DEBUG_API("<-XAFrameworkMgr_GetFramework");
   220         return retVal;
   249         return retVal;
   221         }
   250         }
   222 
   251 
       
   252     DEBUG_INFO_A1_STR("uri[%s]", uri);
   223     /* Get uri scheme */
   253     /* Get uri scheme */
   224     uriScheme = strchr(uri, ':');
   254     uriScheme = strchr(uri, ':');
   225     if (uriScheme == NULL)
   255     if (uriScheme == NULL)
   226         {
   256         {
   227         /* TODO Log invalid uri */
   257         DEBUG_ERR("malformed URI. Could not find [:]");
       
   258         DEBUG_API("<-XAFrameworkMgr_GetFramework");
   228         return retVal;
   259         return retVal;
   229         }
   260         }
   230 
   261 
   231     copyLen = (uriScheme - uri);
   262     copyLen = (uriScheme - uri);
   232     uriScheme = (char*) calloc(copyLen + 1, sizeof(char));
   263     uriScheme = (char*) calloc(copyLen + 1, sizeof(char));
   237         {
   268         {
   238         /* Get uri extension */
   269         /* Get uri extension */
   239         char* dotLoc = strrchr(uri, '.');
   270         char* dotLoc = strrchr(uri, '.');
   240         if (dotLoc == NULL)
   271         if (dotLoc == NULL)
   241             {
   272             {
   242             /* TODO Log invalid uri */
   273             DEBUG_ERR("malformed URI. Could not find extension char[.]");
       
   274             DEBUG_API("<-XAFrameworkMgr_GetFramework");
   243             free(uriScheme);
   275             free(uriScheme);
   244             return retVal;
   276             return retVal;
   245             }
   277             }
   246         /* We need to add 1 to exclude '.'*/
   278         /* We need to add 1 to exclude '.'*/
   247         copyLen = strlen(uri) - (dotLoc + 1 - uri);
   279         copyLen = strlen(uri) - (dotLoc + 1 - uri);
   258             fileExtMatchFound = FWMgrFalse;
   290             fileExtMatchFound = FWMgrFalse;
   259             /* Match for uri*/
   291             /* Match for uri*/
   260             for (i = 0; i < node->uriSchemeCount; i++)
   292             for (i = 0; i < node->uriSchemeCount; i++)
   261                 {
   293                 {
   262                 if (strcasecmp(uriScheme, node->uriSchemes[i]) == 0)
   294                 if (strcasecmp(uriScheme, node->uriSchemes[i]) == 0)
   263                     {
   295                     {                    
   264                     uriMatchFound = FWMgrTrue;
   296                     uriMatchFound = FWMgrTrue;
       
   297                     DEBUG_INFO_A1_STR("Found macthing framework for scheme[%s]", uriScheme);
   265                     break;
   298                     break;
   266                     }
   299                     }
   267                 }
   300                 }
   268             /* if uri scheme is not file, we only need to check for uri */
   301             /* if uri scheme is not file, we only need to check for uri */
   269             if (!fileExt)
   302             if (!fileExt)
   275                 for (i = 0; i < node->fileExtCount; i++)
   308                 for (i = 0; i < node->fileExtCount; i++)
   276                     {
   309                     {
   277                     if (strcasecmp(fileExt, node->fileExts[i]) == 0)
   310                     if (strcasecmp(fileExt, node->fileExts[i]) == 0)
   278                         {
   311                         {
   279                         fileExtMatchFound = FWMgrTrue;
   312                         fileExtMatchFound = FWMgrTrue;
       
   313                         DEBUG_INFO_A1_STR("Found macthing framework for fileext[%s]", fileExt);
   280                         break;
   314                         break;
   281                         }
   315                         }
   282                     }
   316                     }
   283                 }
   317                 }
   284 
   318 
   285             if ((uriMatchFound == FWMgrTrue) && (fileExtMatchFound
   319             if ((uriMatchFound == FWMgrTrue) &&
   286                     == FWMgrTrue))
   320                     (fileExtMatchFound == FWMgrTrue))
   287                 {
   321                 {
   288                 retVal = node->fwType;
   322                 retVal = node->fwType;
       
   323                 DEBUG_INFO_A1("Framework is[%d]", (int)retVal);
   289                 break;
   324                 break;
   290                 }
   325                 }
   291             }
   326             }
   292         node = node->next;
   327         node = node->next;
   293         }
   328         }
   294     free(uriScheme);
   329     free(uriScheme);
   295     free(fileExt);
   330     free(fileExt);
       
   331     DEBUG_API("<-XAFrameworkMgr_GetFramework");
   296     return retVal;
   332     return retVal;
   297     }
   333     }
   298 
   334 
   299 /* Local functions */
   335 /* Local functions */
   300 
   336