MACSio  0.9
Multi-purpose, Application-Centric, Scalable I/O Proxy App
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
macsio_iface.c
Go to the documentation of this file.
1 /*
2 Copyright (c) 2015, Lawrence Livermore National Security, LLC.
3 Produced at the Lawrence Livermore National Laboratory.
4 Written by Mark C. Miller
5 
6 LLNL-CODE-676051. All rights reserved.
7 
8 This file is part of MACSio
9 
10 Please also read the LICENSE file at the top of the source code directory or
11 folder hierarchy.
12 
13 This program is free software; you can redistribute it and/or modify it under
14 the terms of the GNU General Public License (as published by the Free Software
15 Foundation) version 2, dated June 1991.
16 
17 This program is distributed in the hope that it will be useful, but WITHOUT
18 ANY WARRANTY; without even the IMPLIED WARRANTY OF MERCHANTABILITY or FITNESS
19 FOR A PARTICULAR PURPOSE. See the terms and conditions of the GNU General
20 Public License for more details.
21 
22 You should have received a copy of the GNU General Public License along with
23 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
24 Place, Suite 330, Boston, MA 02111-1307 USA
25 */
26 
27 #include <string.h>
28 
29 #include <macsio_iface.h>
30 #include <macsio_utils.h>
31 
32 /* We assume the mem for this static object is zerod */
34 
36 {
37  int i;
38  for (i = 0; i < MACSIO_IFACE_MAX_COUNT; i++)
39  {
40  if (iface_table[i].slotUsed) continue;
41  iface_table[i] = *iface;
42  iface_table[i].slotUsed = 1;
43  return 1;
44  }
45  return 0;
46 }
47 
48 int MACSIO_IFACE_GetId(char const *name)
49 {
50  int i;
51  for (i = 0; i < MACSIO_IFACE_MAX_COUNT; i++)
52  {
53  if (!iface_table[i].slotUsed) continue;
54  if (!strcmp(iface_table[i].name, name))
55  return i;
56  }
57  return -1;
58 }
59 
60 char const *MACSIO_IFACE_GetName(int i)
61 {
62  if (i < 0 || i >= MACSIO_IFACE_MAX_COUNT || !iface_table[i].slotUsed)
63  return "unknown";
64  return iface_table[i].name;
65 }
66 
67 void MACSIO_IFACE_GetIdsMatchingFileExtension(int *cnt, int **ids, char const *ext)
68 {
69  int i, n, pass;
70  for (pass = 0; pass < (ids?2:1); pass++)
71  {
72  n = 0;
73  for (i = 0; i < MACSIO_IFACE_MAX_COUNT; i++)
74  {
75  if (iface_table[i].slotUsed && (!ext || !strcmp(iface_table[i].ext, ext)))
76  {
77  if (pass == 1)
78  (*ids)[n] = i;
79  n++;
80  }
81  }
82  if (ids && *ids == 0)
83  *ids = (int *) malloc(n * sizeof(int));
84  }
85  *cnt = n;
86 }
87 
88 void MACSIO_IFACE_GetIds(int *cnt, int **ids)
89 {
90  return MACSIO_IFACE_GetIdsMatchingFileExtension(cnt, ids, 0);
91 }
92 
94 {
95  if (i < 0 || i >= MACSIO_IFACE_MAX_COUNT || !iface_table[i].slotUsed)
96  return 0;
97  return &iface_table[i];
98 }
99 
101 {
102  int id = MACSIO_IFACE_GetId(name);
103  if (id < 0) return 0;
104  return MACSIO_IFACE_GetById(id);
105 }
int MACSIO_IFACE_GetId(char const *name)
Definition: macsio_iface.c:48
void MACSIO_IFACE_GetIdsMatchingFileExtension(int *cnt, int **ids, char const *ext)
Definition: macsio_iface.c:67
static MACSIO_IFACE_Handle_t iface_table[MACSIO_IFACE_MAX_COUNT]
Definition: macsio_iface.c:33
int MACSIO_IFACE_Register(MACSIO_IFACE_Handle_t const *iface)
Definition: macsio_iface.c:35
void MACSIO_IFACE_GetIds(int *cnt, int **ids)
Definition: macsio_iface.c:88
MACSIO_IFACE_Handle_t const * MACSIO_IFACE_GetByName(char const *name)
Definition: macsio_iface.c:100
#define MACSIO_IFACE_MAX_COUNT
Definition: macsio_iface.h:32
MACSIO_IFACE_Handle_t const * MACSIO_IFACE_GetById(int i)
Definition: macsio_iface.c:93
char name[MACSIO_IFACE_MAX_NAME]
Definition: macsio_iface.h:54
char const * MACSIO_IFACE_GetName(int i)
Definition: macsio_iface.c:60