• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * libiio - Library for interfacing industrial I/O (IIO) devices
3  *
4  * Copyright (C) 2017 Analog Devices, Inc.
5  * Author: Paul Cercueil <paul.cercueil@analog.com>
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  */
17 
18 #include "iio-config.h"
19 #include "iio-private.h"
20 
21 #include <string.h>
22 
iio_get_backends_count(void)23 unsigned int iio_get_backends_count(void)
24 {
25 	unsigned int count = 0;
26 
27 #ifdef WITH_LOCAL_BACKEND
28 	count++;
29 #endif
30 #ifdef WITH_XML_BACKEND
31 	count++;
32 #endif
33 #ifdef WITH_NETWORK_BACKEND
34 	count++;
35 #endif
36 #ifdef WITH_USB_BACKEND
37 	count++;
38 #endif
39 #ifdef WITH_SERIAL_BACKEND
40 	count++;
41 #endif
42 
43 	return count;
44 }
45 
iio_get_backend(unsigned int index)46 const char * iio_get_backend(unsigned int index)
47 {
48 #ifdef WITH_LOCAL_BACKEND
49 	if (index == 0)
50 		return "local";
51 	index--;
52 #endif
53 #ifdef WITH_XML_BACKEND
54 	if (index == 0)
55 		return "xml";
56 	index--;
57 #endif
58 #ifdef WITH_NETWORK_BACKEND
59 	if (index == 0)
60 		return "ip";
61 	index--;
62 #endif
63 #ifdef WITH_USB_BACKEND
64 	if (index == 0)
65 		return "usb";
66 	index--;
67 #endif
68 #ifdef WITH_SERIAL_BACKEND
69 	if (index == 0)
70 		return "serial";
71 #endif
72 	return NULL;
73 }
74 
iio_has_backend(const char * backend)75 bool iio_has_backend(const char *backend)
76 {
77 	unsigned int i;
78 
79 	for (i = 0; i < iio_get_backends_count(); i++)
80 		if (strcmp(backend, iio_get_backend(i)) == 0)
81 			return true;
82 
83 	return false;
84 }
85