select: Introduce osmo_fd_{read,write}_{enable,disable}()

If we watn to migrate to something like epoll(), user application
code must call a function of the libosmocore API whenever it changes
its read/write interest in a file descriptor.

Let's introduce API so applications can be ported to this API,
before making direct 'ofd->when' manipulations illegal as a second step.

Change-Id: Idb89ba7bc7c129a6304a76900d17f47daf54d17d
diff --git a/include/osmocom/core/select.h b/include/osmocom/core/select.h
index bc60198..b410199 100644
--- a/include/osmocom/core/select.h
+++ b/include/osmocom/core/select.h
@@ -19,6 +19,8 @@
 #define OSMO_FD_WRITE	0x0002
 /*! Indicate interest in exceptions from the file descriptor */
 #define OSMO_FD_EXCEPT	0x0004
+/*! Used as when_mask in osmo_fd_update_when() */
+#define OSMO_FD_MASK	0xFFFF
 
 /* legacy naming dating back to early OpenBSC / bsc_hack of 2008 */
 #define BSC_FD_READ	OSMO_FD_READ
@@ -47,6 +49,24 @@
 		   int (*cb)(struct osmo_fd *fd, unsigned int what),
 		   void *data, unsigned int priv_nr);
 
+void osmo_fd_update_when(struct osmo_fd *ofd, unsigned int when_mask, unsigned int when);
+
+static inline void osmo_fd_read_enable(struct osmo_fd *ofd) {
+	osmo_fd_update_when(ofd, OSMO_FD_MASK, OSMO_FD_READ);
+}
+
+static inline void osmo_fd_read_disable(struct osmo_fd *ofd) {
+	osmo_fd_update_when(ofd, ~OSMO_FD_READ, 0);
+}
+
+static inline void osmo_fd_write_enable(struct osmo_fd *ofd) {
+	osmo_fd_update_when(ofd, OSMO_FD_MASK, OSMO_FD_WRITE);
+}
+
+static inline void osmo_fd_write_disable(struct osmo_fd *ofd) {
+	osmo_fd_update_when(ofd, ~OSMO_FD_WRITE, 0);
+}
+
 bool osmo_fd_is_registered(struct osmo_fd *fd);
 int osmo_fd_register(struct osmo_fd *fd);
 void osmo_fd_unregister(struct osmo_fd *fd);