agileRTOS (zrtos)  Version 0.8.0 (ghostbuster)
vfs_notify.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2024 ykat UG (haftungsbeschraenkt) - All Rights Reserved
3  *
4  * Permission for non-commercial use is hereby granted,
5  * free of charge, without warranty of any kind.
6  */
7 #ifndef ZRTOS_VFS_NOTIFY_H
8 #define ZRTOS_VFS_NOTIFY_H
9 #ifdef __cplusplus
10 extern "C" {
11 #endif
12 
13 
14 #include <zrtos/bitfield.h>
15 #include <zrtos/vfs_fd.h>
16 
17 struct _zrtos_vfs_notify_t;
18 
19 typedef enum{
23 
25  struct _zrtos_vfs_notify_t *thiz
26  ,zrtos_vfs_fd_t fd
27  ,zrtos_vfs_notify_event_type_t event_type
28 );
29 
33 
34 typedef struct _zrtos_vfs_notify_t{
39 
43  &thiz->data
45  );
47 
48  return true;
49 }
50 
52  zrtos_vfs_notify_t *thiz
53  ,zrtos_vfs_fd_t fd
55 ){
56  zrtos_vfs_fd_set__set(&thiz->fdset,fd);
57  zrtos_vfs_notify_entry_t *entry = &thiz->data[fd.fd];
58  entry->callback = callback;
59 }
60 
62  zrtos_vfs_notify_t *thiz
63  ,zrtos_vfs_fd_t fd
64 ){
65  zrtos_vfs_fd_set__clear(&thiz->fdset,fd);
66  zrtos_vfs_notify_entry_t *entry = &thiz->data[fd.fd];
67  entry->callback = 0;
68 }
69 
71  zrtos_vfs_notify_t *thiz
72 ){
73  zrtos_vfs_fd_set_t fdset_can_read;
74  zrtos_vfs_fd_set_t fdset_can_write;
75 
76  while(zrtos_error__is_success(thiz->error)){
77  zrtos_vfs_fd_set__copy(&fdset_can_read,&thiz->fdset);
78  zrtos_vfs_fd_set__copy(&fdset_can_write,&thiz->fdset);
79  if(zrtos_vfs_fd__select(&fdset_can_read,&fdset_can_write)>0){
80  ZRTOS_VFS_FD_SET__EACH_BEGIN(&fdset_can_read,fd){
81  if(thiz->data[fd.fd].callback){
82  thiz->data[fd.fd].callback(
83  thiz
84  ,fd
86  );
87  }
89 
90  ZRTOS_VFS_FD_SET__EACH_BEGIN(&fdset_can_write,fd){
91  if(thiz->data[fd.fd].callback){
92  thiz->data[fd.fd].callback(
93  thiz
94  ,fd
96  );
97  }
99  }
100  }
101 }
102 
104  zrtos_vfs_notify_t *thiz
105 ){
106  thiz->error = ZRTOS_ERROR__INTR;
107 }
108 
109 #ifdef __cplusplus
110 }
111 #endif
112 #endif
void zrtos_vfs_fd_set__set(zrtos_vfs_fd_set_t *thiz, zrtos_vfs_fd_t fd)
Definition: vfs_fd.h:42
size_t zrtos_vfs_fd__select(zrtos_vfs_fd_set_t *readfds, zrtos_vfs_fd_set_t *writefds)
Definition: vfs_fd.h:308
#define ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX
Definition: cfg.h:26
zrtos_vfs_fd_set_t fdset
Definition: vfs_notify.h:35
void zrtos_mem__zero(void *dest, size_t len)
Definition: mem.h:144
void zrtos_vfs_notify__remove(zrtos_vfs_notify_t *thiz, zrtos_vfs_fd_t fd)
Definition: vfs_notify.h:61
void zrtos_vfs_notify__start(zrtos_vfs_notify_t *thiz)
Definition: vfs_notify.h:70
zrtos_vfs_notify_event_type_t
Definition: vfs_notify.h:19
void zrtos_vfs_fd_set__copy(zrtos_vfs_fd_set_t *thiz, zrtos_vfs_fd_set_t *src)
Definition: vfs_fd.h:57
size_t fd
Definition: vfs_fd.h:18
struct _zrtos_vfs_notify_entry_t zrtos_vfs_notify_entry_t
#define ZRTOS_VFS_FD_SET__EACH_BEGIN(thiz, fd_)
Definition: vfs_fd.h:341
void zrtos_vfs_notify__add(zrtos_vfs_notify_t *thiz, zrtos_vfs_fd_t fd, zrtos_vfs_notify_callback_t callback)
Definition: vfs_notify.h:51
Interrupted system call.
Definition: error.h:28
bool zrtos_error__is_success(zrtos_error_t thiz)
Definition: error.h:152
Successful program execution status.
Definition: error.h:22
void(* zrtos_vfs_notify_callback_t)(struct _zrtos_vfs_notify_t *thiz, zrtos_vfs_fd_t fd, zrtos_vfs_notify_event_type_t event_type)
Definition: vfs_notify.h:24
zrtos_vfs_notify_callback_t callback
Definition: vfs_notify.h:31
#define ZRTOS_VFS_FD_SET__EACH_END
Definition: vfs_fd.h:349
bool zrtos_vfs_notify__init(zrtos_vfs_notify_t *thiz)
Definition: vfs_notify.h:40
void zrtos_vfs_notify__stop(zrtos_vfs_notify_t *thiz)
Definition: vfs_notify.h:103
zrtos_vfs_notify_entry_t data[ZRTOS_VFS_FILE_DESCRIPTOR__CFG_MAX]
Definition: vfs_notify.h:36
struct _zrtos_vfs_notify_t zrtos_vfs_notify_t
zrtos_error_t error
Definition: vfs_notify.h:37
Definition: vfs_notify.h:30
bool zrtos_vfs_fd_set__init(zrtos_vfs_fd_set_t *thiz)
Definition: vfs_fd.h:65
zrtos_error_t
Definition: error.h:20
void zrtos_vfs_fd_set__clear(zrtos_vfs_fd_set_t *thiz, zrtos_vfs_fd_t fd)
Definition: vfs_fd.h:27