Skip to content

Commit

Permalink
iio: split iio_backend_ops into iio-backend.h
Browse files Browse the repository at this point in the history
The iio_backend_ops will be split away from libiio core. So, move the
iio_backend_ops into another header.
This header will be available in the IIO backends, and the rest of the
libiio core internals will be hidden from IIO backends.

Right now, this split isn't doing too much [mostly moving some types
around]. And it's not yet ready to be used on it's own.
It's only being used in 'iio-private.h', in the same manner as before.

Signed-off-by: Alexandru Ardelean <[email protected]>
  • Loading branch information
commodo committed Oct 14, 2020
1 parent 192869c commit 0fcd01c
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 61 deletions.
75 changes: 75 additions & 0 deletions iio-backend.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
/*
* libiio - Library for interfacing industrial I/O (IIO) devices
*
* Copyright (C) 2020 Analog Devices, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* */

#ifndef __IIO_BACKEND_H__
#define __IIO_BACKEND_H__

#include <stdbool.h>

struct iio_device;
struct iio_context;

enum iio_attr_type {
IIO_ATTR_TYPE_DEVICE = 0,
IIO_ATTR_TYPE_DEBUG,
IIO_ATTR_TYPE_BUFFER,
};

struct iio_backend_ops {
struct iio_context * (*clone)(const struct iio_context *ctx);
ssize_t (*read)(const struct iio_device *dev, void *dst, size_t len,
uint32_t *mask, size_t words);
ssize_t (*write)(const struct iio_device *dev,
const void *src, size_t len);
int (*open)(const struct iio_device *dev,
size_t samples_count, bool cyclic);
int (*close)(const struct iio_device *dev);
int (*get_fd)(const struct iio_device *dev);
int (*set_blocking_mode)(const struct iio_device *dev, bool blocking);

void (*cancel)(const struct iio_device *dev);

int (*set_kernel_buffers_count)(const struct iio_device *dev,
unsigned int nb_blocks);
ssize_t (*get_buffer)(const struct iio_device *dev,
void **addr_ptr, size_t bytes_used,
uint32_t *mask, size_t words);

ssize_t (*read_device_attr)(const struct iio_device *dev,
const char *attr, char *dst, size_t len, enum iio_attr_type);
ssize_t (*write_device_attr)(const struct iio_device *dev,
const char *attr, const char *src,
size_t len, enum iio_attr_type);
ssize_t (*read_channel_attr)(const struct iio_channel *chn,
const char *attr, char *dst, size_t len);
ssize_t (*write_channel_attr)(const struct iio_channel *chn,
const char *attr, const char *src, size_t len);

int (*get_trigger)(const struct iio_device *dev,
const struct iio_device **trigger);
int (*set_trigger)(const struct iio_device *dev,
const struct iio_device *trigger);

void (*shutdown)(struct iio_context *ctx);

int (*get_version)(const struct iio_context *ctx, unsigned int *major,
unsigned int *minor, char git_tag[8]);

int (*set_timeout)(struct iio_context *ctx, unsigned int timeout);
};

#endif /* __IIO_BACKEND_H__ */
75 changes: 14 additions & 61 deletions iio-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@
/* Include public interface */
#include "iio.h"

#ifdef _WIN32
# ifdef LIBIIO_EXPORTS
# define __api __declspec(dllexport)
# else
# define __api __declspec(dllimport)
# endif
#elif __GNUC__ >= 4
# define __api __attribute__((visibility ("default")))
#else
# define __api
#endif

#include "iio-backend.h"

#include "iio-config.h"

#include <stdbool.h>
Expand All @@ -35,18 +49,6 @@
#define iio_sscanf sscanf
#endif

#ifdef _WIN32
# ifdef LIBIIO_EXPORTS
# define __api __declspec(dllexport)
# else
# define __api __declspec(dllimport)
# endif
#elif __GNUC__ >= 4
# define __api __attribute__((visibility ("default")))
#else
# define __api
#endif

#define ARRAY_SIZE(x) (sizeof(x) ? sizeof(x) / sizeof((x)[0]) : 0)
#define BIT(x) (1 << (x))
#define BIT_MASK(bit) BIT((bit) % 32)
Expand Down Expand Up @@ -111,55 +113,6 @@ static inline void *zalloc(size_t size)
return calloc(1, size);
}

enum iio_attr_type {
IIO_ATTR_TYPE_DEVICE = 0,
IIO_ATTR_TYPE_DEBUG,
IIO_ATTR_TYPE_BUFFER,
};

struct iio_backend_ops {
struct iio_context * (*clone)(const struct iio_context *ctx);
ssize_t (*read)(const struct iio_device *dev, void *dst, size_t len,
uint32_t *mask, size_t words);
ssize_t (*write)(const struct iio_device *dev,
const void *src, size_t len);
int (*open)(const struct iio_device *dev,
size_t samples_count, bool cyclic);
int (*close)(const struct iio_device *dev);
int (*get_fd)(const struct iio_device *dev);
int (*set_blocking_mode)(const struct iio_device *dev, bool blocking);

void (*cancel)(const struct iio_device *dev);

int (*set_kernel_buffers_count)(const struct iio_device *dev,
unsigned int nb_blocks);
ssize_t (*get_buffer)(const struct iio_device *dev,
void **addr_ptr, size_t bytes_used,
uint32_t *mask, size_t words);

ssize_t (*read_device_attr)(const struct iio_device *dev,
const char *attr, char *dst, size_t len, enum iio_attr_type);
ssize_t (*write_device_attr)(const struct iio_device *dev,
const char *attr, const char *src,
size_t len, enum iio_attr_type);
ssize_t (*read_channel_attr)(const struct iio_channel *chn,
const char *attr, char *dst, size_t len);
ssize_t (*write_channel_attr)(const struct iio_channel *chn,
const char *attr, const char *src, size_t len);

int (*get_trigger)(const struct iio_device *dev,
const struct iio_device **trigger);
int (*set_trigger)(const struct iio_device *dev,
const struct iio_device *trigger);

void (*shutdown)(struct iio_context *ctx);

int (*get_version)(const struct iio_context *ctx, unsigned int *major,
unsigned int *minor, char git_tag[8]);

int (*set_timeout)(struct iio_context *ctx, unsigned int timeout);
};

/*
* If these structures are updated, the qsort functions defined in sort.c
* may need to be updated.
Expand Down

0 comments on commit 0fcd01c

Please sign in to comment.