---
 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 0711c6d..b38cf93 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 cdcd823..c675802 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 9cffea2..b944a80 100644
--- a/lib/obex.c
+++ b/lib/obex.c
@@ -449,6 +449,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 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 6483738..10aa377 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 733e190..bd18921 100644
--- a/lib/obex_main.c
+++ b/lib/obex_main.c
@@ -342,6 +342,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)
  *
@@ -352,9 +364,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 55eca62..72ce3a3 100644
--- a/lib/obex_main.h
+++ b/lib/obex_main.h
@@ -75,6 +75,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


------------------------------------------------------------------------------
AppSumo Presents a FREE Video for the SourceForge Community by Eric 
Ries, the creator of the Lean Startup Methodology on "Lean Startup 
Secrets Revealed." This video shows you how to validate your ideas, 
optimize your ideas and identify your business strategy.
http://p.sf.net/sfu/appsumosfdev2dev
_______________________________________________
Openobex-users mailing list
Openobex-users@lists.sourceforge.net
http://lists.sourceforge.net/lists/listinfo/openobex-users

Reply via email to