---
include/openobex/obex.h | 1 +
include/openobex/obex_const.h | 7 +++++++
lib/obex.c | 16 ++++++++++++++++
lib/obex.sym | 1 +
lib/obex_main.c | 16 +++++++++++++---
lib/obex_main.h | 1 +
6 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/include/openobex/obex.h b/include/openobex/obex.h
index e773c12..4d15671 100644
--- a/include/openobex/obex.h
+++ b/include/openobex/obex.h
@@ -111,6 +111,7 @@ OPENOBEX_SYMBOL(void *) OBEX_GetUserData(obex_t *self);
OPENOBEX_SYMBOL(void) OBEX_SetEventCb(obex_t *self, obex_event_cb_t
eventcb, void * data);
OPENOBEX_SYMBOL(int) OBEX_SetTransportMTU(obex_t *self, uint16_t mtu_rx,
uint16_t mtu_tx_max);
OPENOBEX_SYMBOL(int) OBEX_GetFD(obex_t *self);
+OPENOBEX_SYMBOL(enum obex_data_direction) OBEX_GetDataDirection(obex_t *self);
OPENOBEX_SYMBOL(int) OBEX_RegisterCTransport(obex_t *self, obex_ctrans_t
*ctrans);
OPENOBEX_SYMBOL(int) OBEX_SetCustomData(obex_t *self, void * data);
diff --git a/include/openobex/obex_const.h b/include/openobex/obex_const.h
index f0cbbf0..eaf9a64 100644
--- a/include/openobex/obex_const.h
+++ b/include/openobex/obex_const.h
@@ -204,6 +204,13 @@ enum obex_transport_type {
OBEX_TRANS_BT_L2CAP = 7, /**< Bluetooth L2CAP */
};
+/** Possible directions for data */
+enum obex_data_direction {
+ OBEX_DATA_DIR_NONE = 0, /**< No data */
+ OBEX_DATA_DIR_RX = 1, /**< Incoming data */
+ OBEX_DATA_DIR_TX = 2, /**< Outgoing data */
+};
+
/* Standard headers */
#define OBEX_HDR_TYPE_UNICODE (0 << 6) /* zero terminated unicode string
(network byte order) */
#define OBEX_HDR_TYPE_BYTES (1 << 6) /* byte array */
diff --git a/lib/obex.c b/lib/obex.c
index 04016e1..ab22037 100644
--- a/lib/obex.c
+++ b/lib/obex.c
@@ -412,6 +412,22 @@ int CALLAPI OBEX_Work(obex_t *self, long timeout)
}
/**
+ Find out the current data transfer direction
+ \param self OBEX handle
+ \return see #obex_data_direction
+
+ If you want to check externally if a socket is readable/writable, this
+ function together with OBEX_GetFD() gives you full control when to
+ call OBEX_Work().
+ */
+LIB_SYMBOL
+enum obex_data_direction CALLAPI OBEX_GetDataDirection(obex_t *self)
+{
+ DEBUG(4, "\n");
+ return obex_get_data_direction(self);
+}
+
+/**
Feed OBEX with data when using a custom transport.
\param self OBEX handle
\param inputbuf Pointer to custom data
diff --git a/lib/obex.sym b/lib/obex.sym
index 3de52c7..4c07c29 100644
--- a/lib/obex.sym
+++ b/lib/obex.sym
@@ -7,6 +7,7 @@ OBEX_SetUserCallBack
OBEX_SetEventCb
OBEX_SetTransportMTU
OBEX_GetFD
+OBEX_GetDataDirection
OBEX_RegisterCTransport
OBEX_SetCustomData
OBEX_GetCustomData
diff --git a/lib/obex_main.c b/lib/obex_main.c
index 714571a..5a7864c 100644
--- a/lib/obex_main.c
+++ b/lib/obex_main.c
@@ -380,6 +380,18 @@ static int obex_mode(obex_t *self)
}
}
+enum obex_data_direction obex_get_data_direction (obex_t *self)
+{
+ if (self == NULL)
+ return OBEX_DATA_DIR_NONE;
+
+ if (self->state == STATE_IDLE ||
+ self->substate == SUBSTATE_RECEIVE_RX)
+ return OBEX_DATA_DIR_RX;
+ else
+ return OBEX_DATA_DIR_TX;
+}
+
/*
* Function obex_work (self, timeout)
*
@@ -390,9 +402,7 @@ int obex_work(obex_t *self, long timeout)
{
int ret;
- if (self->state == STATE_IDLE ||
- self->substate == SUBSTATE_RECEIVE_RX)
- {
+ if (obex_get_data_direction(self) == OBEX_DATA_DIR_RX) {
ret = obex_transport_handle_input(self, timeout);
if (ret <= 0)
return ret;
diff --git a/lib/obex_main.h b/lib/obex_main.h
index be154d1..4f1465c 100644
--- a/lib/obex_main.h
+++ b/lib/obex_main.h
@@ -76,6 +76,7 @@ int obex_get_buffer_status(buf_t *msg);
int obex_data_indication(struct obex *self);
buf_t* obex_data_receive(obex_t *self);
void obex_data_receive_finished(obex_t *self);
+enum obex_data_direction obex_get_data_direction (obex_t *self);
void obex_response_request(struct obex *self, uint8_t opcode);
void obex_data_request_prepare(struct obex *self, struct databuffer *msg,
--
1.7.5.4
------------------------------------------------------------------------------
Got Input? Slashdot Needs You.
Take our quick survey online. Come on, we don't ask for help often.
Plus, you'll get a chance to win $100 to spend on ThinkGeek.
http://p.sf.net/sfu/slashdot-survey
_______________________________________________
Openobex-users mailing list
[email protected]
http://lists.sourceforge.net/lists/listinfo/openobex-users