diff options
author | Hyunil Park <hyunil46.park@samsung.com> | 2013-04-09 15:33:07 +0900 |
---|---|---|
committer | Hyunil Park <hyunil46.park@samsung.com> | 2013-04-09 15:33:07 +0900 |
commit | 0287a27281551a062fad1d1272d7a9966360904d (patch) | |
tree | 711eb2ab73c2754a50835b3cc904889794d9ad35 /src | |
parent | e5a814dd3c4b316dca3fa969b2abc346f1be78ed (diff) | |
download | libmm-wfd-0287a27281551a062fad1d1272d7a9966360904d.tar.gz libmm-wfd-0287a27281551a062fad1d1272d7a9966360904d.tar.bz2 libmm-wfd-0287a27281551a062fad1d1272d7a9966360904d.zip |
update source code for tizen 2.1
Change-Id: Iee4ad5825153cfb822f2c7cd5ef86a3331e2e972
Diffstat (limited to 'src')
-rwxr-xr-x | src/Makefile.am | 2 | ||||
-rwxr-xr-x | src/include/mm_wfd_proxy.h | 533 | ||||
-rwxr-xr-x | src/mm_wfd_priv.c | 6 | ||||
-rwxr-xr-x | src/mm_wfd_proxy.c | 1277 |
4 files changed, 917 insertions, 901 deletions
diff --git a/src/Makefile.am b/src/Makefile.am index f2464b2..1196bde 100755 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -58,5 +58,5 @@ libmmfwfd_la_LIBADD = $(GST_LIBS) \ -lmmfwfd_rtsp_server \ $(INIPARSER_LIBS) -libmmfwfd_la_CFLAGS += $(MMLOG_CFLAGS) -DMMF_LOG_OWNER=0x008 -DMMF_DEBUG_PREFIX=\"MMF-WFD\" -D_INTERNAL_SESSION_MANAGER_ +libmmfwfd_la_CFLAGS += $(MMLOG_CFLAGS) -DMMF_LOG_OWNER=0x02000000 -DMMF_DEBUG_PREFIX=\"MMF-WFD\" -D_INTERNAL_SESSION_MANAGER_ libmmfwfd_la_LIBADD += $(MMLOG_LIBS) diff --git a/src/include/mm_wfd_proxy.h b/src/include/mm_wfd_proxy.h index e1a067d..b2fb722 100755 --- a/src/include/mm_wfd_proxy.h +++ b/src/include/mm_wfd_proxy.h @@ -19,271 +19,270 @@ * limitations under the License. * */ - -#ifndef _WFDSOURCEPROXY_H_ -#define _WFDSOURCEPROXY_H_ - -/******************* - * Allow for C++ users - */ -#ifdef __cplusplus -extern "C" -{ -#endif - -#include <string.h> -#include <glib.h> -#include <mm_message.h> -#include <mm_error.h> -#include <mm_types.h> -#include <mm_debug.h> -#include <sys/types.h> -#include <sys/socket.h> -#include <netinet/in.h> -#include <netdb.h> - -/** - * Enumerations of wifi-display states. - */ -typedef enum { - WFDSRC_STATE_NULL = 0, /**< wifi-display is created, but not realized yet */ - WFDSRC_STATE_READY, /**< wifi-display is ready to play media */ - WFDSRC_STATE_CONNECTION_WAIT, /** < wifi-display is waiting for connection */ - WFDSRC_STATE_CONNECTED, /** < wifi-display is connected */ - WFDSRC_STATE_PLAYING, /**< wifi-display is now playing media */ - WFDSRC_STATE_PAUSED, /**< wifi-display is paused while playing media */ - WFDSRC_STATE_NONE, /**< wifi-display is not created yet */ - WFDSRC_STATE_NUM /**< Number of wifi-display states */ -} WfdSrcProxyState; - -typedef enum { - WFDSRC_COMMAND_NONE = 0, - WFDSRC_COMMAND_CREATE, - WFDSRC_COMMAND_DESTROY, - WFDSRC_COMMAND_REALIZE, - WFDSRC_COMMAND_UNREALIZE, - WFDSRC_COMMAND_CONNECT, - WFDSRC_COMMAND_START, - WFDSRC_COMMAND_STOP, - WFDSRC_COMMAND_PAUSE, - WFDSRC_COMMAND_RESUME, - WFDSRC_COMMAND_NUM, -}WfdSrcProxyCmd; - -/** - * Enumerations of wifi-display source module errors and proxy errors - * Note: Ensure appending of proxy errors after WFD source module errors - */ -typedef enum { - WFDSRC_ERROR_NONE = 0, - WFDSRC_ERROR_UNKNOWN, - WFDSRC_ERROR_WFD_INVALID_ARGUMENT, - WFDSRC_ERROR_WFD_NO_FREE_SPACE, - WFDSRC_ERROR_WFD_NOT_INITIALIZED, - WFDSRC_ERROR_WFD_NO_OP, - WFDSRC_ERROR_WFD_INVALID_STATE, - WFDSRC_ERROR_WFD_INTERNAL -} WfdSrcProxyRet; - -/** - * Application callback, - */ -typedef void (*WfdSrcProxyStateError_cb) (MMHandleType pHandle, - WfdSrcProxyRet error_code, - WfdSrcProxyState state, - void *user_data); - -/******************************************************* - * Function Name: WfdSrcProxyInit - * ========= - * Description: - * ======= - * This API does the following - * - creates handle - * - creates socket and connect to server address ( IPC) - * - This ensures socket listen on server to be successful - * - call back registration - * Arguments: - * ======= - * pHandle - pointer to WfdSrcProxyInfo - * appCb - pointer to application callback - * - * Return : return WfdSrcProxyRet - * ==== - *******************************************************/ -WfdSrcProxyRet WfdSrcProxyInit( - MMHandleType *pHandle, - WfdSrcProxyStateError_cb *appCb, - void *user_data ); - - -/******************************************************* - * Function Name: WfdSrcProxyDeInit - * ========= - * Description: - * ======= - * - Free the handle - * - close the sockets - * - * Arguments: - * ======= - * pHandle - pointer to WfdSrcProxyInfo - * - * Return : return WfdSrcProxyRet - * ==== - *******************************************************/ -WfdSrcProxyRet WfdSrcProxyDeInit(MMHandleType pHandle ); - - -/******************************************************* - * Function Name: WfdSrcProxySetIPAddrAndPort - * ========= - * Description: - * ======= - * This API sets IP address and port number to be used by WFD source. - * Application should call this API after Initialize is called. - * IP address and port number is sent to WFD source Server (daemon) - * on IPC - * - * Arguments: - * ======= - * pHandle - pointer to WfdSrcProxyInfo - * wfdsrcIP - IP address string - * wfdsrcPort : Port no string - * - * Return : return WfdSrcProxyRet - * ==== - ******************************************************/ -WfdSrcProxyRet WfdSrcProxySetIPAddrAndPort( - MMHandleType pHandle, - char *wfdsrcIP, - char *wfdsrcPort); - -/******************************************************* - * Function Name: WfdSrcProxyConnect - * ========= - * Description: - * ======= - * This API is used to connect WiFi display source to client. - * After return, display mode should be set to X - * refer to utilx_scrnconf_set_dispmode() - * - * Arguments: - * ======= - * pHandle - pointer to WfdSrcProxyInfo - * - * Return : return WfdSrcProxyRet - * ==== - ******************************************************/ -WfdSrcProxyRet WfdSrcProxyConnect(MMHandleType pHandle); - -/******************************************************* - * Function Name: WfdSrcProxyStart - * ========= - * Description: - * ======= - * This API is used to start WiFi display source to start sending data - * to client. - * - * Arguments: - * ======= - * pHandle - pointer to WfdSrcProxyInfo - * - * Return : return WfdSrcProxyRet - * ==== - ******************************************************/ -WfdSrcProxyRet WfdSrcProxyStart(MMHandleType pHandle); - -/******************************************************* - * Function Name: WfdSrcProxyPause - * ========= - * Description: - * ======= - * This API is used to pause WFD streaming between source and sink. - * This pauses the streaming between WFD source and sink. So that - * when user resumes back, streaming does not continue from the point - * where it stopped, instead it will start from current content. - * - * Arguments: - * ======= - * pHandle - pointer to WfdSrcProxyInfo - * - * Return : return WfdSrcProxyRet - * ==== - ******************************************************/ -WfdSrcProxyRet WfdSrcProxyPause(MMHandleType pHandle); - -/******************************************************* - * Function Name: WfdSrcProxyResume - * ========= - * Description: - * ======= - * This API is used to resume WFD streaming between source and sink - * Resume after pause starts from current content that is viewed on source - * No caching of content from the time it is paused is done. - * - * Arguments: - * pHandle - pointer to WfdSrcProxyInfo - * - * Return : return WfdSrcProxyRet - * ==== - ******************************************************/ -WfdSrcProxyRet WfdSrcProxyResume(MMHandleType pHandle); - -/******************************************************* - * Function Name: WfdSrcProxyStop - * ========= - * Description: - * ======= - * This API stops WFD streaming between source and sink. - * The Server(daemon) will be still running even after stop. - * - * Arguments: - * ======= - * pHandle - pointer to WfdSrcProxyInfo - * - * Return : return one of WfdSrcProxyRet - * ==== - ******************************************************/ -WfdSrcProxyRet WfdSrcProxyStop(MMHandleType pHandle); - -/******************************************************* - * Function Name: WfdSrcProxyDestroyServer - * ========= - * Description: - * ======= - * This API destroy WFD server which is already in STOP state. - * The Server(daemon) will be destroyed after this call. - * - * Arguments: - * ======= - * pHandle - pointer to WfdSrcProxyInfo - * - * Return : return one of WfdSrcProxyRet - * ==== - ******************************************************/ -WfdSrcProxyRet WfdSrcProxyDestroyServer(MMHandleType pHandle); - -/******************************************************* - * Function Name: WfdSrcProxyGetCurrentState - * ========= - * Description: - * ======= - * This API is a provision given to Application, if in any case - * application needs to know the status of WiFi Source server state. - * This is a synchronous call. - * Arguments: - * ======= - * pHandle - pointer to WfdSrcProxyInfo - * - * Return : return one of the states from WfdSrcProxyState - * ==== - ******************************************************/ -WfdSrcProxyState WfdSrcProxyGetCurrentState(MMHandleType pHandle); - - -#ifdef __cplusplus -} -#endif //__cplusplus - +#ifndef _WFDSOURCEPROXY_H_
+#define _WFDSOURCEPROXY_H_
+
+/*******************
+ * Allow for C++ users
+ */
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+#include <string.h>
+#include <glib.h>
+#include <mm_message.h>
+#include <mm_error.h>
+#include <mm_types.h>
+#include <mm_debug.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+
+/**
+ * Enumerations of wifi-display states.
+ */
+typedef enum {
+ WFDSRC_STATE_NULL = 0, /**< wifi-display is created, but not realized yet */
+ WFDSRC_STATE_READY, /**< wifi-display is ready to play media */
+ WFDSRC_STATE_CONNECTION_WAIT, /** < wifi-display is waiting for connection */
+ WFDSRC_STATE_CONNECTED, /** < wifi-display is connected */
+ WFDSRC_STATE_PLAYING, /**< wifi-display is now playing media */
+ WFDSRC_STATE_PAUSED, /**< wifi-display is paused while playing media */
+ WFDSRC_STATE_NONE, /**< wifi-display is not created yet */
+ WFDSRC_STATE_NUM /**< Number of wifi-display states */
+} WfdSrcProxyState;
+
+typedef enum {
+ WFDSRC_COMMAND_NONE = 0,
+ WFDSRC_COMMAND_CREATE,
+ WFDSRC_COMMAND_DESTROY,
+ WFDSRC_COMMAND_REALIZE,
+ WFDSRC_COMMAND_UNREALIZE,
+ WFDSRC_COMMAND_CONNECT,
+ WFDSRC_COMMAND_START,
+ WFDSRC_COMMAND_STOP,
+ WFDSRC_COMMAND_PAUSE,
+ WFDSRC_COMMAND_RESUME,
+ WFDSRC_COMMAND_NUM,
+}WfdSrcProxyCmd;
+
+/**
+ * Enumerations of wifi-display source module errors and proxy errors
+ * Note: Ensure appending of proxy errors after WFD source module errors
+ */
+typedef enum {
+ WFDSRC_ERROR_NONE = 0,
+ WFDSRC_ERROR_UNKNOWN,
+ WFDSRC_ERROR_WFD_INVALID_ARGUMENT,
+ WFDSRC_ERROR_WFD_NO_FREE_SPACE,
+ WFDSRC_ERROR_WFD_NOT_INITIALIZED,
+ WFDSRC_ERROR_WFD_NO_OP,
+ WFDSRC_ERROR_WFD_INVALID_STATE,
+ WFDSRC_ERROR_WFD_INTERNAL
+} WfdSrcProxyRet;
+
+/**
+ * Application callback,
+ */
+typedef void (*WfdSrcProxyStateError_cb) (MMHandleType pHandle,
+ WfdSrcProxyRet error_code,
+ WfdSrcProxyState state,
+ void *user_data);
+
+/*******************************************************
+ * Function Name: WfdSrcProxyInit
+ * =========
+ * Description:
+ * =======
+ * This API does the following
+ * - creates handle
+ * - creates socket and connect to server address ( IPC)
+ * - This ensures socket listen on server to be successful
+ * - call back registration
+ * Arguments:
+ * =======
+ * pHandle - pointer to WfdSrcProxyInfo
+ * appCb - pointer to application callback
+ *
+ * Return : return WfdSrcProxyRet
+ * ====
+ *******************************************************/
+WfdSrcProxyRet WfdSrcProxyInit(
+ MMHandleType *pHandle,
+ WfdSrcProxyStateError_cb *appCb,
+ void *user_data );
+
+
+/*******************************************************
+ * Function Name: WfdSrcProxyDeInit
+ * =========
+ * Description:
+ * =======
+ * - Free the handle
+ * - close the sockets
+ *
+ * Arguments:
+ * =======
+ * pHandle - pointer to WfdSrcProxyInfo
+ *
+ * Return : return WfdSrcProxyRet
+ * ====
+ *******************************************************/
+WfdSrcProxyRet WfdSrcProxyDeInit(MMHandleType pHandle );
+
+
+/*******************************************************
+ * Function Name: WfdSrcProxySetIPAddrAndPort
+ * =========
+ * Description:
+ * =======
+ * This API sets IP address and port number to be used by WFD source.
+ * Application should call this API after Initialize is called.
+ * IP address and port number is sent to WFD source Server (daemon)
+ * on IPC
+ *
+ * Arguments:
+ * =======
+ * pHandle - pointer to WfdSrcProxyInfo
+ * wfdsrcIP - IP address string
+ * wfdsrcPort : Port no string
+ *
+ * Return : return WfdSrcProxyRet
+ * ====
+ ******************************************************/
+WfdSrcProxyRet WfdSrcProxySetIPAddrAndPort(
+ MMHandleType pHandle,
+ char *wfdsrcIP,
+ char *wfdsrcPort);
+
+/*******************************************************
+ * Function Name: WfdSrcProxyConnect
+ * =========
+ * Description:
+ * =======
+ * This API is used to connect WiFi display source to client.
+ * After return, display mode should be set to X
+ * refer to utilx_scrnconf_set_dispmode()
+ *
+ * Arguments:
+ * =======
+ * pHandle - pointer to WfdSrcProxyInfo
+ *
+ * Return : return WfdSrcProxyRet
+ * ====
+ ******************************************************/
+WfdSrcProxyRet WfdSrcProxyConnect(MMHandleType pHandle);
+
+/*******************************************************
+ * Function Name: WfdSrcProxyStart
+ * =========
+ * Description:
+ * =======
+ * This API is used to start WiFi display source to start sending data
+ * to client.
+ *
+ * Arguments:
+ * =======
+ * pHandle - pointer to WfdSrcProxyInfo
+ *
+ * Return : return WfdSrcProxyRet
+ * ====
+ ******************************************************/
+WfdSrcProxyRet WfdSrcProxyStart(MMHandleType pHandle);
+
+/*******************************************************
+ * Function Name: WfdSrcProxyPause
+ * =========
+ * Description:
+ * =======
+ * This API is used to pause WFD streaming between source and sink.
+ * This pauses the streaming between WFD source and sink. So that
+ * when user resumes back, streaming does not continue from the point
+ * where it stopped, instead it will start from current content.
+ *
+ * Arguments:
+ * =======
+ * pHandle - pointer to WfdSrcProxyInfo
+ *
+ * Return : return WfdSrcProxyRet
+ * ====
+ ******************************************************/
+WfdSrcProxyRet WfdSrcProxyPause(MMHandleType pHandle);
+
+/*******************************************************
+ * Function Name: WfdSrcProxyResume
+ * =========
+ * Description:
+ * =======
+ * This API is used to resume WFD streaming between source and sink
+ * Resume after pause starts from current content that is viewed on source
+ * No caching of content from the time it is paused is done.
+ *
+ * Arguments:
+ * pHandle - pointer to WfdSrcProxyInfo
+ *
+ * Return : return WfdSrcProxyRet
+ * ====
+ ******************************************************/
+WfdSrcProxyRet WfdSrcProxyResume(MMHandleType pHandle);
+
+/*******************************************************
+ * Function Name: WfdSrcProxyStop
+ * =========
+ * Description:
+ * =======
+ * This API stops WFD streaming between source and sink.
+ * The Server(daemon) will be still running even after stop.
+ *
+ * Arguments:
+ * =======
+ * pHandle - pointer to WfdSrcProxyInfo
+ *
+ * Return : return one of WfdSrcProxyRet
+ * ====
+ ******************************************************/
+WfdSrcProxyRet WfdSrcProxyStop(MMHandleType pHandle);
+
+/*******************************************************
+ * Function Name: WfdSrcProxyDestroyServer
+ * =========
+ * Description:
+ * =======
+ * This API destroy WFD server which is already in STOP state.
+ * The Server(daemon) will be destroyed after this call.
+ *
+ * Arguments:
+ * =======
+ * pHandle - pointer to WfdSrcProxyInfo
+ *
+ * Return : return one of WfdSrcProxyRet
+ * ====
+ ******************************************************/
+WfdSrcProxyRet WfdSrcProxyDestroyServer(MMHandleType pHandle);
+
+/*******************************************************
+ * Function Name: WfdSrcProxyGetCurrentState
+ * =========
+ * Description:
+ * =======
+ * This API is a provision given to Application, if in any case
+ * application needs to know the status of WiFi Source server state.
+ * This is a synchronous call.
+ * Arguments:
+ * =======
+ * pHandle - pointer to WfdSrcProxyInfo
+ *
+ * Return : return one of the states from WfdSrcProxyState
+ * ====
+ ******************************************************/
+WfdSrcProxyState WfdSrcProxyGetCurrentState(MMHandleType pHandle);
+
+
+#ifdef __cplusplus
+}
+#endif //__cplusplus
+
#endif //_WFDSOURCEPROXY_H_ diff --git a/src/mm_wfd_priv.c b/src/mm_wfd_priv.c index 45f1cda..0760519 100755 --- a/src/mm_wfd_priv.c +++ b/src/mm_wfd_priv.c @@ -144,10 +144,10 @@ int _mmwfd_destroy (MMHandleType hwfd) // @ /* destroy can called at anytime */ MMWFD_CHECK_STATE_RETURN_IF_FAIL ( wfd, MMWFD_COMMAND_DESTROY ); + g_object_unref (wfd->client); + g_object_unref (wfd->server); g_object_unref (wfd->mapping); g_object_unref (wfd->factory); - g_object_unref (wfd->mapping); - g_object_unref (wfd->server); /* release attributes */ _mmwfd_deconstruct_attribute( wfd ); @@ -280,7 +280,7 @@ int _mmwfd_start (MMHandleType hwfd) // @ MMWFD_CHECK_STATE_RETURN_IF_FAIL( wfd, MMWFD_COMMAND_START ); /* set client params */ - gst_rtsp_server_set_client_params (wfd->server, wfd->client, WFD_INI()->videosrc_element, WFD_INI()->session_mode, WFD_INI()->videobitrate, + gst_rtsp_server_set_client_params (wfd->server, wfd->client, WFD_INI()->videosrc_element, WFD_INI()->session_mode, WFD_INI()->videobitrate, WFD_INI()->mtu_size, WFD_INI()->infile); if (!gst_rtsp_server_start_client (wfd->server, wfd->client)) diff --git a/src/mm_wfd_proxy.c b/src/mm_wfd_proxy.c index 23a76d3..9b1b6a6 100755 --- a/src/mm_wfd_proxy.c +++ b/src/mm_wfd_proxy.c @@ -19,662 +19,679 @@ * limitations under the License. * */ - -#include "mm_wfd_proxy.h" -#include <gst/gst.h> -#include <fcntl.h> - -#include <dbus/dbus.h> -#include <dbus/dbus-shared.h> -#include <dbus/dbus-glib-lowlevel.h> - -#include "wfd-stub.h" -#include <dlog.h> - -#define DEST_HOST "127.0.0.1" -#define WFD_PROXY_COMM_PORT 8888 -#define WFD_TIME_SPAN_100_MILLISECOND (100 * G_TIME_SPAN_MILLISECOND) +
+#include "mm_wfd_proxy.h"
+#include <gst/gst.h>
+#include <fcntl.h>
+
+#include <dbus/dbus.h>
+#include <dbus/dbus-shared.h>
+#include <dbus/dbus-glib-lowlevel.h>
+
+#include "wfd-stub.h"
+#include <dlog.h>
+
+#define DEST_HOST "127.0.0.1"
+#define WFD_PROXY_COMM_PORT 8888
+#define WFD_TIME_SPAN_100_MILLISECOND (100 * G_TIME_SPAN_MILLISECOND)
#define LIMIT_TIME 50 /* 5 sec */ - -/*WFD_PROXY_SET_IP_PORT -IP 192.168.16.1 -PORT 2022 -*/ -/* REPLAY WFD_PROXY_SET_IP_PORT -MM_ERROR_NONE -*/ -// WFD_PROXY_START -/* REPLAY WFD_PROXY_START -MM_ERROR_NONE -*/ -// WFD_PROXY_STOP -/* REPLAY WFD_PROXY_STOP -MM_ERROR_NONE -*/ -// WFD_PROXY_PAUSE -/* REPLAY WFD_PROXY_PAUSE -MM_ERROR_NONE -*/ -// WFD_PROXY_RESUME -/* REPLAY WFD_PROXY_RESUME -MM_ERROR_NONE -*/ -//WFD_PROXY_DESTROY -/* REPLAY WFD_PROXY_DESTROY -MM_ERROR_NONE -*/ -// WFD_PROXY_STATE_QUERY -/* REPLAY WFD_PROXY_STATE_QUERY -MM_WFD_STATE_NULL -MM_WFD_STATE_READY -MM_WFD_STATE_PLAYING -MM_WFD_STATE_NONE -*/ - -/* NOTIFY -MM_WFD_STATE_READY -WFDSRC_ERROR_UNKNOWN -*/ - -/** - * Data structure to hold call back info for proxy to send asynchronous - * info received from WFD daemon - */ -typedef struct{ - WfdSrcProxyStateError_cb applicationCb; - void *user_data; - GCond *cond; - GMutex *cond_lock; - char outbuff[512]; - char inbuff[512]; - int sockfd; - gboolean quitloop; - GThread *thread; - gboolean response; -} WfdSrcProxy; - -static int wfd_proxy_initialize(WfdSrcProxy *wfd); -static WfdSrcProxyState wfd_proxy_message_parse_state (const char * data, guint size); -static WfdSrcProxyRet wfd_proxy_message_parse_status (const char * data, guint size); -static gboolean is_cmd_valid_in_current_state(WfdSrcProxyState aState, WfdSrcProxyCmd acmd); -static gboolean proxy_write (WfdSrcProxy *wfd, char *wbuf); -WfdSrcProxyState convert_string_to_state(gchar *buffer); -WfdSrcProxyRet convert_string_to_status(gchar *buffer); - -WfdSrcProxyRet WfdSrcProxyInit( - MMHandleType *pHandle, - WfdSrcProxyStateError_cb *appCb, - void *user_data ) -{ - WfdSrcProxy *temp = NULL; - - debug_fenter(); - debug_log("mm_wfd_proxy_create \n"); - - return_val_if_fail(pHandle, WFDSRC_ERROR_WFD_INVALID_ARGUMENT); +
+/*WFD_PROXY_SET_IP_PORT
+IP 192.168.16.1
+PORT 2022
+*/
+/* REPLAY WFD_PROXY_SET_IP_PORT
+MM_ERROR_NONE
+*/
+// WFD_PROXY_START
+/* REPLAY WFD_PROXY_START
+MM_ERROR_NONE
+*/
+// WFD_PROXY_STOP
+/* REPLAY WFD_PROXY_STOP
+MM_ERROR_NONE
+*/
+// WFD_PROXY_PAUSE
+/* REPLAY WFD_PROXY_PAUSE
+MM_ERROR_NONE
+*/
+// WFD_PROXY_RESUME
+/* REPLAY WFD_PROXY_RESUME
+MM_ERROR_NONE
+*/
+//WFD_PROXY_DESTROY
+/* REPLAY WFD_PROXY_DESTROY
+MM_ERROR_NONE
+*/
+// WFD_PROXY_STATE_QUERY
+/* REPLAY WFD_PROXY_STATE_QUERY
+MM_WFD_STATE_NULL
+MM_WFD_STATE_READY
+MM_WFD_STATE_PLAYING
+MM_WFD_STATE_NONE
+*/
+
+/* NOTIFY
+MM_WFD_STATE_READY
+WFDSRC_ERROR_UNKNOWN
+*/
+
+/**
+ * Data structure to hold call back info for proxy to send asynchronous
+ * info received from WFD daemon
+ */
+typedef struct{
+ WfdSrcProxyStateError_cb applicationCb;
+ void *user_data;
+ GCond *cond;
+ GMutex *cond_lock;
+ char outbuff[512];
+ char inbuff[512];
+ int sockfd;
+ gboolean quitloop;
+ GThread *thread;
+ gboolean response;
+ gboolean server_destroyed;
+} WfdSrcProxy;
+
+static int wfd_proxy_initialize(WfdSrcProxy *wfd);
+static WfdSrcProxyState wfd_proxy_message_parse_state (const char * data, guint size);
+static WfdSrcProxyRet wfd_proxy_message_parse_status (const char * data, guint size);
+static gboolean is_cmd_valid_in_current_state(WfdSrcProxyState aState, WfdSrcProxyCmd acmd);
+static gboolean proxy_write (WfdSrcProxy *wfd, char *wbuf);
+WfdSrcProxyState convert_string_to_state(gchar *buffer);
+WfdSrcProxyRet convert_string_to_status(gchar *buffer);
+
+WfdSrcProxyRet WfdSrcProxyInit(
+ MMHandleType *pHandle,
+ WfdSrcProxyStateError_cb *appCb,
+ void *user_data )
+{
+ WfdSrcProxy *temp = NULL;
+
+ debug_fenter();
+ debug_log("mm_wfd_proxy_create \n");
+
+ return_val_if_fail(pHandle, WFDSRC_ERROR_WFD_INVALID_ARGUMENT);
int ret = 0; - temp = g_malloc(sizeof(WfdSrcProxy)); - if(!temp) - { - debug_log("WfdSrcProxy malloc failed. out of memory"); - return WFDSRC_ERROR_WFD_NO_FREE_SPACE; - } - temp->cond = g_cond_new (); - temp->cond_lock = g_mutex_new (); - temp->applicationCb = appCb; - temp->user_data = user_data; - temp->quitloop = FALSE; - temp->response = FALSE; + temp = g_malloc(sizeof(WfdSrcProxy));
+ if(!temp)
+ {
+ debug_log("WfdSrcProxy malloc failed. out of memory");
+ return WFDSRC_ERROR_WFD_NO_FREE_SPACE;
+ }
+ temp->cond = g_cond_new ();
+ temp->cond_lock = g_mutex_new ();
+ temp->applicationCb = appCb;
+ temp->user_data = user_data;
+ temp->quitloop = FALSE;
+ temp->response = FALSE;
+ temp->server_destroyed = FALSE;
ret = wfd_proxy_initialize(temp); if(ret < 0) return WFDSRC_ERROR_WFD_NOT_INITIALIZED; - *pHandle = (MMHandleType)temp; - debug_fleave (); - return WFDSRC_ERROR_NONE; -} - -WfdSrcProxyRet WfdSrcProxyDeInit(MMHandleType pHandle ) -{ - WfdSrcProxy *lwfd; - debug_fenter(); - - return_val_if_fail(pHandle, WFDSRC_ERROR_WFD_NOT_INITIALIZED); - lwfd = (WfdSrcProxy *)pHandle; - lwfd->quitloop = TRUE; - debug_log("client close socket\n"); - shutdown (lwfd->sockfd, SHUT_RDWR); - g_thread_join(lwfd->thread); - if(lwfd->cond_lock) g_mutex_free(lwfd->cond_lock); - if(lwfd->cond) g_cond_free(lwfd->cond); - debug_log("client after thread join\n"); - g_free(lwfd); - debug_leave(); - return WFDSRC_ERROR_NONE; -} - -WfdSrcProxyRet WfdSrcProxySetIPAddrAndPort( - MMHandleType pHandle, - char *wfdsrcIP, - char *wfdsrcPort) -{ - WfdSrcProxyState lstate; - WfdSrcProxy *lwfd; - GString *proxy_cmd; - gchar *cmd_string; - gint64 end_time; + *pHandle = (MMHandleType)temp;
+ debug_fleave ();
+ return WFDSRC_ERROR_NONE;
+}
+
+WfdSrcProxyRet WfdSrcProxyDeInit(MMHandleType pHandle )
+{
+ WfdSrcProxy *lwfd;
+ debug_fenter();
+
+ return_val_if_fail(pHandle, WFDSRC_ERROR_WFD_NOT_INITIALIZED);
+ lwfd = (WfdSrcProxy *)pHandle;
+ lwfd->quitloop = TRUE;
+ debug_log("client close socket\n");
+ shutdown (lwfd->sockfd, SHUT_RDWR);
+ if(!lwfd->server_destroyed)
+ g_thread_join(lwfd->thread);
+ if(lwfd->cond_lock) g_mutex_free(lwfd->cond_lock);
+ if(lwfd->cond) g_cond_free(lwfd->cond);
+ debug_log("client after thread join\n");
+ g_free(lwfd);
+ debug_leave();
+ return WFDSRC_ERROR_NONE;
+}
+
+WfdSrcProxyRet WfdSrcProxySetIPAddrAndPort(
+ MMHandleType pHandle,
+ char *wfdsrcIP,
+ char *wfdsrcPort)
+{
+ WfdSrcProxyState lstate;
+ WfdSrcProxy *lwfd;
+ GString *proxy_cmd;
+ gchar *cmd_string;
+ gint64 end_time;
int limit = 0; - debug_fenter(); - - return_val_if_fail(pHandle, WFDSRC_ERROR_WFD_NOT_INITIALIZED); - return_val_if_fail(wfdsrcIP, WFDSRC_ERROR_WFD_NOT_INITIALIZED); - return_val_if_fail(wfdsrcPort, WFDSRC_ERROR_WFD_NOT_INITIALIZED); - - lwfd = (WfdSrcProxy *)pHandle; - lstate = WfdSrcProxyGetCurrentState(pHandle); - if(!is_cmd_valid_in_current_state(lstate, WFDSRC_COMMAND_STOP)) - return WFDSRC_ERROR_WFD_INVALID_STATE; - proxy_cmd = g_string_new (""); - g_string_append_printf (proxy_cmd, "WFD_PROXY_SET_IP_PORT"); - g_string_append_printf (proxy_cmd, "\r\nIP "); - g_string_append_printf (proxy_cmd, wfdsrcIP); - g_string_append_printf (proxy_cmd, "\r\nPORT "); - g_string_append_printf (proxy_cmd, wfdsrcPort); - g_string_append_printf (proxy_cmd, "\r\n"); - cmd_string = g_string_free (proxy_cmd, FALSE); - debug_log("WfdSrcProxySetIPAddrAndPort command sent: %s \n", cmd_string); - lwfd->response = FALSE; - proxy_write(lwfd, cmd_string); -retry: - debug_log("try timed wait...\n"); - end_time = g_get_monotonic_time () + WFD_TIME_SPAN_100_MILLISECOND; - if (!g_cond_wait_until(lwfd->cond, lwfd->cond_lock, end_time)) - { - debug_log("Out of timed wait but due to timeout...\n"); + debug_fenter();
+
+ return_val_if_fail(pHandle, WFDSRC_ERROR_WFD_NOT_INITIALIZED);
+ return_val_if_fail(wfdsrcIP, WFDSRC_ERROR_WFD_NOT_INITIALIZED);
+ return_val_if_fail(wfdsrcPort, WFDSRC_ERROR_WFD_NOT_INITIALIZED);
+
+ lwfd = (WfdSrcProxy *)pHandle;
+ return_val_if_fail(!lwfd->server_destroyed, WFDSRC_ERROR_WFD_NOT_INITIALIZED);
+ lstate = WfdSrcProxyGetCurrentState(pHandle);
+ if(!is_cmd_valid_in_current_state(lstate, WFDSRC_COMMAND_STOP))
+ return WFDSRC_ERROR_WFD_INVALID_STATE;
+ proxy_cmd = g_string_new ("");
+ g_string_append_printf (proxy_cmd, "WFD_PROXY_SET_IP_PORT");
+ g_string_append_printf (proxy_cmd, "\r\nIP ");
+ g_string_append_printf (proxy_cmd, wfdsrcIP);
+ g_string_append_printf (proxy_cmd, "\r\nPORT ");
+ g_string_append_printf (proxy_cmd, wfdsrcPort);
+ g_string_append_printf (proxy_cmd, "\r\n");
+ cmd_string = g_string_free (proxy_cmd, FALSE);
+ debug_log("WfdSrcProxySetIPAddrAndPort command sent: %s \n", cmd_string);
+ lwfd->response = FALSE;
+ proxy_write(lwfd, cmd_string);
+retry:
+ debug_log("try timed wait...\n");
+ end_time = g_get_monotonic_time () + WFD_TIME_SPAN_100_MILLISECOND;
+ if (!g_cond_wait_until(lwfd->cond, lwfd->cond_lock, end_time))
+ {
+ debug_log("Out of timed wait but due to timeout...\n");
limit ++; if(limit > LIMIT_TIME) return WFDSRC_ERROR_WFD_INTERNAL; - if(!lwfd->response) goto retry; - } - - debug_log("WfdSrcProxySetIPAddrAndPort replay for command: %s \n", lwfd->inbuff); - debug_leave(); - return wfd_proxy_message_parse_status(lwfd->inbuff, strlen(lwfd->inbuff)); -} - -WfdSrcProxyRet WfdSrcProxyConnect(MMHandleType pHandle) -{ - WfdSrcProxyState lstate; - WfdSrcProxy *lwfd; - GString *proxy_cmd; - gchar *cmd_string; - gint64 end_time; + if(!lwfd->response) goto retry;
+ }
+
+ debug_log("WfdSrcProxySetIPAddrAndPort replay for command: %s \n", lwfd->inbuff);
+ debug_leave();
+ return wfd_proxy_message_parse_status(lwfd->inbuff, strlen(lwfd->inbuff));
+}
+
+WfdSrcProxyRet WfdSrcProxyConnect(MMHandleType pHandle)
+{
+ WfdSrcProxyState lstate;
+ WfdSrcProxy *lwfd;
+ GString *proxy_cmd;
+ gchar *cmd_string;
+ gint64 end_time;
int limit = 0; - debug_fenter(); - - return_val_if_fail(pHandle, WFDSRC_ERROR_WFD_NOT_INITIALIZED); - lwfd = (WfdSrcProxy *)pHandle; - lstate = WfdSrcProxyGetCurrentState(pHandle); - if(!is_cmd_valid_in_current_state(lstate, WFDSRC_COMMAND_CONNECT)) - return WFDSRC_ERROR_WFD_INVALID_STATE; - proxy_cmd = g_string_new (""); - g_string_append_printf (proxy_cmd, "WFD_PROXY_CONNECT"); - g_string_append_printf (proxy_cmd, "\r\n"); - cmd_string = g_string_free (proxy_cmd, FALSE); - debug_log("WfdSrcProxyConnect command sent: %s \n", cmd_string); - lwfd->response = FALSE; - proxy_write(lwfd, cmd_string); -retry: - debug_log("try timed wait...\n"); - end_time = g_get_monotonic_time () + WFD_TIME_SPAN_100_MILLISECOND; - if (!g_cond_wait_until(lwfd->cond, lwfd->cond_lock, end_time)) - { - debug_log("Out of timed wait but due to timeout...\n"); + debug_fenter();
+
+ return_val_if_fail(pHandle, WFDSRC_ERROR_WFD_NOT_INITIALIZED);
+ lwfd = (WfdSrcProxy *)pHandle;
+ return_val_if_fail(!lwfd->server_destroyed, WFDSRC_ERROR_WFD_NOT_INITIALIZED);
+ lstate = WfdSrcProxyGetCurrentState(pHandle);
+ if(!is_cmd_valid_in_current_state(lstate, WFDSRC_COMMAND_CONNECT))
+ return WFDSRC_ERROR_WFD_INVALID_STATE;
+ proxy_cmd = g_string_new ("");
+ g_string_append_printf (proxy_cmd, "WFD_PROXY_CONNECT");
+ g_string_append_printf (proxy_cmd, "\r\n");
+ cmd_string = g_string_free (proxy_cmd, FALSE);
+ debug_log("WfdSrcProxyConnect command sent: %s \n", cmd_string);
+ lwfd->response = FALSE;
+ proxy_write(lwfd, cmd_string);
+retry:
+ debug_log("try timed wait...\n");
+ end_time = g_get_monotonic_time () + WFD_TIME_SPAN_100_MILLISECOND;
+ if (!g_cond_wait_until(lwfd->cond, lwfd->cond_lock, end_time))
+ {
+ debug_log("Out of timed wait but due to timeout...\n");
limit ++; if(limit > LIMIT_TIME) return WFDSRC_ERROR_WFD_INTERNAL; - if(!lwfd->response) goto retry; - } - - debug_log("WfdSrcProxyConnect inbuff for command: %s \n", lwfd->inbuff); - debug_leave(); - return wfd_proxy_message_parse_status(lwfd->inbuff, strlen(lwfd->inbuff)); -} - -WfdSrcProxyRet WfdSrcProxyStart(MMHandleType pHandle) -{ - WfdSrcProxyState lstate; - WfdSrcProxy *lwfd; - GString *proxy_cmd; - gchar *cmd_string; - gint64 end_time; + if(!lwfd->response) goto retry;
+ }
+
+ debug_log("WfdSrcProxyConnect inbuff for command: %s \n", lwfd->inbuff);
+ debug_leave();
+ return wfd_proxy_message_parse_status(lwfd->inbuff, strlen(lwfd->inbuff));
+}
+
+WfdSrcProxyRet WfdSrcProxyStart(MMHandleType pHandle)
+{
+ WfdSrcProxyState lstate;
+ WfdSrcProxy *lwfd;
+ GString *proxy_cmd;
+ gchar *cmd_string;
+ gint64 end_time;
int limit = 0; - debug_fenter(); - - return_val_if_fail(pHandle, WFDSRC_ERROR_WFD_NOT_INITIALIZED); - lwfd = (WfdSrcProxy *)pHandle; - lstate = WfdSrcProxyGetCurrentState(pHandle); - if(!is_cmd_valid_in_current_state(lstate, WFDSRC_COMMAND_START)) - return WFDSRC_ERROR_WFD_INVALID_STATE; - proxy_cmd = g_string_new (""); - g_string_append_printf (proxy_cmd, "WFD_PROXY_START"); - g_string_append_printf (proxy_cmd, "\r\n"); - cmd_string = g_string_free (proxy_cmd, FALSE); - debug_log("WfdSrcProxyStart command sent: %s \n", cmd_string); - lwfd->response = FALSE; - proxy_write(lwfd, cmd_string); -retry: - debug_log("try timed wait...\n"); - end_time = g_get_monotonic_time () + WFD_TIME_SPAN_100_MILLISECOND; - if (!g_cond_wait_until(lwfd->cond, lwfd->cond_lock, end_time)) - { - debug_log("Out of timed wait but due to timeout...\n"); + debug_fenter();
+
+ return_val_if_fail(pHandle, WFDSRC_ERROR_WFD_NOT_INITIALIZED);
+ lwfd = (WfdSrcProxy *)pHandle;
+ return_val_if_fail(!lwfd->server_destroyed, WFDSRC_ERROR_WFD_NOT_INITIALIZED);
+ lstate = WfdSrcProxyGetCurrentState(pHandle);
+ if(!is_cmd_valid_in_current_state(lstate, WFDSRC_COMMAND_START))
+ return WFDSRC_ERROR_WFD_INVALID_STATE;
+ proxy_cmd = g_string_new ("");
+ g_string_append_printf (proxy_cmd, "WFD_PROXY_START");
+ g_string_append_printf (proxy_cmd, "\r\n");
+ cmd_string = g_string_free (proxy_cmd, FALSE);
+ debug_log("WfdSrcProxyStart command sent: %s \n", cmd_string);
+ lwfd->response = FALSE;
+ proxy_write(lwfd, cmd_string);
+retry:
+ debug_log("try timed wait...\n");
+ end_time = g_get_monotonic_time () + WFD_TIME_SPAN_100_MILLISECOND;
+ if (!g_cond_wait_until(lwfd->cond, lwfd->cond_lock, end_time))
+ {
+ debug_log("Out of timed wait but due to timeout...\n");
limit ++; if(limit > LIMIT_TIME) return WFDSRC_ERROR_WFD_INTERNAL; - if(!lwfd->response) goto retry; - } - - debug_log("WfdSrcProxyStart inbuff for command: %s \n", lwfd->inbuff); - debug_leave(); - return wfd_proxy_message_parse_status(lwfd->inbuff, strlen(lwfd->inbuff)); -} - -WfdSrcProxyRet WfdSrcProxyPause(MMHandleType pHandle) -{ - WfdSrcProxyState lstate; - WfdSrcProxy *lwfd; - GString *proxy_cmd; - gchar *cmd_string; - gint64 end_time; + if(!lwfd->response) goto retry;
+ }
+
+ debug_log("WfdSrcProxyStart inbuff for command: %s \n", lwfd->inbuff);
+ debug_leave();
+ return wfd_proxy_message_parse_status(lwfd->inbuff, strlen(lwfd->inbuff));
+}
+
+WfdSrcProxyRet WfdSrcProxyPause(MMHandleType pHandle)
+{
+ WfdSrcProxyState lstate;
+ WfdSrcProxy *lwfd;
+ GString *proxy_cmd;
+ gchar *cmd_string;
+ gint64 end_time;
int limit = 0; - debug_fenter(); - - return_val_if_fail(pHandle, WFDSRC_ERROR_WFD_NOT_INITIALIZED); - lwfd = (WfdSrcProxy *)pHandle; - lstate = WfdSrcProxyGetCurrentState(pHandle); - if(!is_cmd_valid_in_current_state(lstate, WFDSRC_COMMAND_PAUSE)) - return WFDSRC_ERROR_WFD_INVALID_STATE; - proxy_cmd = g_string_new (""); - g_string_append_printf (proxy_cmd, "WFD_PROXY_PAUSE"); - g_string_append_printf (proxy_cmd, "\r\n"); - cmd_string = g_string_free (proxy_cmd, FALSE); - debug_log("WfdSrcProxyPause command sent: %s \n", cmd_string); - lwfd->response = FALSE; - proxy_write(lwfd, cmd_string); -retry: - debug_log("try timed wait...\n"); - end_time = g_get_monotonic_time () + WFD_TIME_SPAN_100_MILLISECOND; - if (!g_cond_wait_until(lwfd->cond, lwfd->cond_lock, end_time)) - { - debug_log("Out of timed wait but due to timeout...\n"); + debug_fenter();
+
+ return_val_if_fail(pHandle, WFDSRC_ERROR_WFD_NOT_INITIALIZED);
+ lwfd = (WfdSrcProxy *)pHandle;
+ return_val_if_fail(!lwfd->server_destroyed, WFDSRC_ERROR_WFD_NOT_INITIALIZED);
+ lstate = WfdSrcProxyGetCurrentState(pHandle);
+ if(!is_cmd_valid_in_current_state(lstate, WFDSRC_COMMAND_PAUSE))
+ return WFDSRC_ERROR_WFD_INVALID_STATE;
+ proxy_cmd = g_string_new ("");
+ g_string_append_printf (proxy_cmd, "WFD_PROXY_PAUSE");
+ g_string_append_printf (proxy_cmd, "\r\n");
+ cmd_string = g_string_free (proxy_cmd, FALSE);
+ debug_log("WfdSrcProxyPause command sent: %s \n", cmd_string);
+ lwfd->response = FALSE;
+ proxy_write(lwfd, cmd_string);
+retry:
+ debug_log("try timed wait...\n");
+ end_time = g_get_monotonic_time () + WFD_TIME_SPAN_100_MILLISECOND;
+ if (!g_cond_wait_until(lwfd->cond, lwfd->cond_lock, end_time))
+ {
+ debug_log("Out of timed wait but due to timeout...\n");
limit ++; if(limit > LIMIT_TIME) return WFDSRC_ERROR_WFD_INTERNAL; - if(!lwfd->response) goto retry; - } - - debug_log("WfdSrcProxyPause inbuff for command: %s \n", lwfd->inbuff); - debug_leave(); - return wfd_proxy_message_parse_status(lwfd->inbuff, strlen(lwfd->inbuff)); -} - -WfdSrcProxyRet WfdSrcProxyResume(MMHandleType pHandle) -{ - WfdSrcProxyState lstate; - WfdSrcProxy *lwfd; - GString *proxy_cmd; - gchar *cmd_string; - gint64 end_time; + if(!lwfd->response) goto retry;
+ }
+
+ debug_log("WfdSrcProxyPause inbuff for command: %s \n", lwfd->inbuff);
+ debug_leave();
+ return wfd_proxy_message_parse_status(lwfd->inbuff, strlen(lwfd->inbuff));
+}
+
+WfdSrcProxyRet WfdSrcProxyResume(MMHandleType pHandle)
+{
+ WfdSrcProxyState lstate;
+ WfdSrcProxy *lwfd;
+ GString *proxy_cmd;
+ gchar *cmd_string;
+ gint64 end_time;
int limit = 0; - debug_fenter(); - - return_val_if_fail(pHandle, WFDSRC_ERROR_WFD_NOT_INITIALIZED); - lwfd = (WfdSrcProxy *)pHandle; - lstate = WfdSrcProxyGetCurrentState(pHandle); - if(!is_cmd_valid_in_current_state(lstate, WFDSRC_COMMAND_RESUME)) - return WFDSRC_ERROR_WFD_INVALID_STATE; - proxy_cmd = g_string_new (""); - g_string_append_printf (proxy_cmd, "WFD_PROXY_RESUME"); - g_string_append_printf (proxy_cmd, "\r\n"); - cmd_string = g_string_free (proxy_cmd, FALSE); - debug_log("WfdSrcProxyResume command sent: %s \n", cmd_string); - lwfd->response = FALSE; - proxy_write(lwfd, cmd_string); -retry: - debug_log("try timed wait...\n"); - end_time = g_get_monotonic_time () + WFD_TIME_SPAN_100_MILLISECOND; - if (!g_cond_wait_until(lwfd->cond, lwfd->cond_lock, end_time)) - { - debug_log("Out of timed wait but due to timeout...\n"); + debug_fenter();
+
+ return_val_if_fail(pHandle, WFDSRC_ERROR_WFD_NOT_INITIALIZED);
+ lwfd = (WfdSrcProxy *)pHandle;
+ return_val_if_fail(!lwfd->server_destroyed, WFDSRC_ERROR_WFD_NOT_INITIALIZED);
+ lstate = WfdSrcProxyGetCurrentState(pHandle);
+ if(!is_cmd_valid_in_current_state(lstate, WFDSRC_COMMAND_RESUME))
+ return WFDSRC_ERROR_WFD_INVALID_STATE;
+ proxy_cmd = g_string_new ("");
+ g_string_append_printf (proxy_cmd, "WFD_PROXY_RESUME");
+ g_string_append_printf (proxy_cmd, "\r\n");
+ cmd_string = g_string_free (proxy_cmd, FALSE);
+ debug_log("WfdSrcProxyResume command sent: %s \n", cmd_string);
+ lwfd->response = FALSE;
+ proxy_write(lwfd, cmd_string);
+retry:
+ debug_log("try timed wait...\n");
+ end_time = g_get_monotonic_time () + WFD_TIME_SPAN_100_MILLISECOND;
+ if (!g_cond_wait_until(lwfd->cond, lwfd->cond_lock, end_time))
+ {
+ debug_log("Out of timed wait but due to timeout...\n");
limit ++; if(limit > LIMIT_TIME) return WFDSRC_ERROR_WFD_INTERNAL; - if(!lwfd->response) goto retry; - } - - debug_log("WfdSrcProxyResume inbuff for command: %s \n", lwfd->inbuff); - debug_leave(); - return wfd_proxy_message_parse_status(lwfd->inbuff, strlen(lwfd->inbuff)); -} - -WfdSrcProxyRet WfdSrcProxyStop(MMHandleType pHandle) -{ - WfdSrcProxyState lstate; - WfdSrcProxy *lwfd; - GString *proxy_cmd; - gchar *cmd_string; - gint64 end_time; + if(!lwfd->response) goto retry;
+ }
+
+ debug_log("WfdSrcProxyResume inbuff for command: %s \n", lwfd->inbuff);
+ debug_leave();
+ return wfd_proxy_message_parse_status(lwfd->inbuff, strlen(lwfd->inbuff));
+}
+
+WfdSrcProxyRet WfdSrcProxyStop(MMHandleType pHandle)
+{
+ WfdSrcProxyState lstate;
+ WfdSrcProxy *lwfd;
+ GString *proxy_cmd;
+ gchar *cmd_string;
+ gint64 end_time;
int limit = 0; - debug_fenter(); - - return_val_if_fail(pHandle, WFDSRC_ERROR_WFD_NOT_INITIALIZED); - lwfd = (WfdSrcProxy *)pHandle; - lstate = WfdSrcProxyGetCurrentState(pHandle); - if(!is_cmd_valid_in_current_state(lstate, WFDSRC_COMMAND_STOP)) - return WFDSRC_ERROR_WFD_INVALID_STATE; - proxy_cmd = g_string_new (""); - g_string_append_printf (proxy_cmd, "WFD_PROXY_STOP"); - g_string_append_printf (proxy_cmd, "\r\n"); - cmd_string = g_string_free (proxy_cmd, FALSE); - debug_log("WfdSrcProxyStop command sent: %s \n", cmd_string); - lwfd->response = FALSE; - proxy_write(lwfd, cmd_string); -retry: - debug_log("try timed wait...\n"); - end_time = g_get_monotonic_time () + WFD_TIME_SPAN_100_MILLISECOND; - if (!g_cond_wait_until(lwfd->cond, lwfd->cond_lock, end_time)) - { - debug_log("Out of timed wait but due to timeout...\n"); + debug_fenter();
+
+ return_val_if_fail(pHandle, WFDSRC_ERROR_WFD_NOT_INITIALIZED);
+ lwfd = (WfdSrcProxy *)pHandle;
+ return_val_if_fail(!lwfd->server_destroyed, WFDSRC_ERROR_WFD_NOT_INITIALIZED);
+ lstate = WfdSrcProxyGetCurrentState(pHandle);
+ if(!is_cmd_valid_in_current_state(lstate, WFDSRC_COMMAND_STOP))
+ return WFDSRC_ERROR_WFD_INVALID_STATE;
+ proxy_cmd = g_string_new ("");
+ g_string_append_printf (proxy_cmd, "WFD_PROXY_STOP");
+ g_string_append_printf (proxy_cmd, "\r\n");
+ cmd_string = g_string_free (proxy_cmd, FALSE);
+ debug_log("WfdSrcProxyStop command sent: %s \n", cmd_string);
+ lwfd->response = FALSE;
+ proxy_write(lwfd, cmd_string);
+retry:
+ debug_log("try timed wait...\n");
+ end_time = g_get_monotonic_time () + WFD_TIME_SPAN_100_MILLISECOND;
+ if (!g_cond_wait_until(lwfd->cond, lwfd->cond_lock, end_time))
+ {
+ debug_log("Out of timed wait but due to timeout...\n");
limit ++; if(limit > LIMIT_TIME) return WFDSRC_ERROR_WFD_INTERNAL; - if(!lwfd->response) goto retry; - } - - debug_log("WfdSrcProxyStop inbuff for command: %s \n", lwfd->inbuff); - debug_leave(); - return wfd_proxy_message_parse_status(lwfd->inbuff, strlen(lwfd->inbuff)); -} - -WfdSrcProxyRet WfdSrcProxyDestroyServer(MMHandleType pHandle) -{ - WfdSrcProxyState lstate; - WfdSrcProxy *lwfd; - GString *proxy_cmd; - gchar *cmd_string; - gint64 end_time; + if(!lwfd->response) goto retry;
+ }
+
+ debug_log("WfdSrcProxyStop inbuff for command: %s \n", lwfd->inbuff);
+ debug_leave();
+ return wfd_proxy_message_parse_status(lwfd->inbuff, strlen(lwfd->inbuff));
+}
+
+WfdSrcProxyRet WfdSrcProxyDestroyServer(MMHandleType pHandle)
+{
+ WfdSrcProxyState lstate;
+ WfdSrcProxy *lwfd;
+ GString *proxy_cmd;
+ gchar *cmd_string;
+ gint64 end_time;
int limit = 0; - debug_fenter(); - - return_val_if_fail(pHandle, WFDSRC_ERROR_WFD_NOT_INITIALIZED); - lwfd = (WfdSrcProxy *)pHandle; - lstate = WfdSrcProxyGetCurrentState(pHandle); - if(!is_cmd_valid_in_current_state(lstate, WFDSRC_COMMAND_STOP)) - return WFDSRC_ERROR_WFD_INVALID_STATE; - proxy_cmd = g_string_new (""); - g_string_append_printf (proxy_cmd, "WFD_PROXY_DESTROY"); - g_string_append_printf (proxy_cmd, "\r\n"); - cmd_string = g_string_free (proxy_cmd, FALSE); - debug_log("WfdSrcProxyDestroyServer command sent: %s \n", cmd_string); - lwfd->response = FALSE; - proxy_write(lwfd, cmd_string); -retry: - debug_log("try timed wait...\n"); - end_time = g_get_monotonic_time () + WFD_TIME_SPAN_100_MILLISECOND; - if (!g_cond_wait_until(lwfd->cond, lwfd->cond_lock, end_time)) - { - debug_log("Out of timed wait but due to timeout...\n"); + debug_fenter();
+
+ return_val_if_fail(pHandle, WFDSRC_ERROR_WFD_NOT_INITIALIZED);
+ lwfd = (WfdSrcProxy *)pHandle;
+ return_val_if_fail(!lwfd->server_destroyed, WFDSRC_ERROR_WFD_NOT_INITIALIZED);
+ lstate = WfdSrcProxyGetCurrentState(pHandle);
+ if(!is_cmd_valid_in_current_state(lstate, WFDSRC_COMMAND_STOP))
+ return WFDSRC_ERROR_WFD_INVALID_STATE;
+ proxy_cmd = g_string_new ("");
+ g_string_append_printf (proxy_cmd, "WFD_PROXY_DESTROY");
+ g_string_append_printf (proxy_cmd, "\r\n");
+ cmd_string = g_string_free (proxy_cmd, FALSE);
+ debug_log("WfdSrcProxyDestroyServer command sent: %s \n", cmd_string);
+ lwfd->response = FALSE;
+ proxy_write(lwfd, cmd_string);
+retry:
+ debug_log("try timed wait...\n");
+ end_time = g_get_monotonic_time () + WFD_TIME_SPAN_100_MILLISECOND;
+ if (!g_cond_wait_until(lwfd->cond, lwfd->cond_lock, end_time))
+ {
+ debug_log("Out of timed wait but due to timeout...\n");
limit ++; if(limit > LIMIT_TIME) return WFDSRC_ERROR_WFD_INTERNAL; - if(!lwfd->response) goto retry; - } - - debug_log("WfdSrcProxyDestroyServer inbuff for command: %s \n", lwfd->inbuff); - debug_leave(); - return wfd_proxy_message_parse_status(lwfd->inbuff, strlen(lwfd->inbuff)); -} - -WfdSrcProxyState WfdSrcProxyGetCurrentState(MMHandleType pHandle) -{ - WfdSrcProxy *lwfd; - GString *proxy_cmd; - gchar *cmd_string; - gint64 end_time; + if(!lwfd->response) goto retry;
+ }
+
+ debug_log("WfdSrcProxyDestroyServer inbuff for command: %s \n", lwfd->inbuff);
+ debug_leave();
+ return wfd_proxy_message_parse_status(lwfd->inbuff, strlen(lwfd->inbuff));
+}
+
+WfdSrcProxyState WfdSrcProxyGetCurrentState(MMHandleType pHandle)
+{
+ WfdSrcProxy *lwfd;
+ GString *proxy_cmd;
+ gchar *cmd_string;
+ gint64 end_time;
int limit = 0; - debug_fenter(); - - return_val_if_fail(pHandle, WFDSRC_ERROR_WFD_NOT_INITIALIZED); - lwfd = (WfdSrcProxy *)pHandle; - proxy_cmd = g_string_new (""); - g_string_append_printf (proxy_cmd, "WFD_PROXY_STATE_QUERY"); - g_string_append_printf (proxy_cmd, "\r\n"); - cmd_string = g_string_free (proxy_cmd, FALSE); - debug_log("WfdSrcProxyGetCurrentState command sent: %s \n", cmd_string); - lwfd->response = FALSE; - proxy_write(lwfd, cmd_string); -retry: - debug_log("try timed wait...\n"); - end_time = g_get_monotonic_time () + WFD_TIME_SPAN_100_MILLISECOND; - if (!g_cond_wait_until(lwfd->cond, lwfd->cond_lock, end_time)) - { - debug_log("Out of timed wait but due to timeout...\n"); + debug_fenter();
+
+ return_val_if_fail(pHandle, WFDSRC_ERROR_WFD_NOT_INITIALIZED);
+ lwfd = (WfdSrcProxy *)pHandle;
+ return_val_if_fail(!lwfd->server_destroyed, WFDSRC_ERROR_WFD_NOT_INITIALIZED);
+ proxy_cmd = g_string_new ("");
+ g_string_append_printf (proxy_cmd, "WFD_PROXY_STATE_QUERY");
+ g_string_append_printf (proxy_cmd, "\r\n");
+ cmd_string = g_string_free (proxy_cmd, FALSE);
+ debug_log("WfdSrcProxyGetCurrentState command sent: %s \n", cmd_string);
+ lwfd->response = FALSE;
+ proxy_write(lwfd, cmd_string);
+retry:
+ debug_log("try timed wait...\n");
+ end_time = g_get_monotonic_time () + WFD_TIME_SPAN_100_MILLISECOND;
+ if (!g_cond_wait_until(lwfd->cond, lwfd->cond_lock, end_time))
+ {
+ debug_log("Out of timed wait but due to timeout...\n");
limit ++; if(limit > LIMIT_TIME) return WFDSRC_ERROR_WFD_INTERNAL; - if(!lwfd->response) goto retry; - } - debug_log("WfdSrcProxyGetCurrentState inbuff for command: %s \n", lwfd->inbuff); - debug_leave(); - return wfd_proxy_message_parse_state(lwfd->inbuff, strlen(lwfd->inbuff)); -} - -static gboolean proxy_write (WfdSrcProxy *wfd, char *wbuf) -{ - write(wfd->sockfd, wbuf, strlen(wbuf)); - return TRUE; -} - -static void* wfd_proxy_thread_function(void * asrc) -{ - fd_set read_flags,write_flags; - WfdSrcProxy *wfd = (WfdSrcProxy *)asrc; - int rc; - while(!wfd->quitloop) - { - FD_ZERO(&read_flags); - FD_ZERO(&write_flags); - FD_SET(wfd->sockfd, &read_flags); - debug_log("Waiting on select()...\n"); - rc = select(wfd->sockfd+1, &read_flags, NULL, NULL, NULL); - if(rc < 0) - continue; - if(FD_ISSET(wfd->sockfd, &read_flags)) - { //Socket ready for reading - FD_CLR(wfd->sockfd, &read_flags); - memset(&(wfd->inbuff),0,sizeof(wfd->inbuff)); - debug_log("socket ready for reading...\n"); - rc = read(wfd->sockfd, wfd->inbuff, sizeof(wfd->inbuff)-1); - if (rc <= 0) - { - debug_log("socket connection closed\n"); - goto cleanup; - } - debug_log("wfd_proxy replay for command: %s \n", wfd->inbuff); - if(g_strrstr(wfd->inbuff, "NOTIFY")) - { - if(wfd->applicationCb) - { - gchar **notify; - notify = g_strsplit(wfd->inbuff,"\r\n",0); - wfd->applicationCb(asrc, convert_string_to_status(notify[2]), convert_string_to_state(notify[1]), wfd->user_data); - } - } - else - { - debug_log("wfd_proxy signalling \n"); - wfd->response = TRUE; - g_cond_signal(wfd->cond); - debug_log("wfd_proxy signal emitted \n"); - } - } - } -cleanup: - close (wfd->sockfd); - FD_CLR (wfd->sockfd, &read_flags); - debug_log("thread function signal\n"); - g_cond_signal(wfd->cond); - debug_log("thread function quit\n"); - return NULL; -} - -static int wfd_proxy_initialize(WfdSrcProxy *wfd) -{ - DBusGConnection *bus = NULL; - DBusGProxy *proxy = NULL; - g_type_init(); - debug_log("wfd_proxy_initialize init \n"); - int portno; - struct sockaddr_in serv_addr; - struct hostent *server; - GError *error = NULL; - debug_log("wfd_proxy_initialize get before socket\n"); - wfd->sockfd = socket(AF_INET, SOCK_STREAM, 0); - if (wfd->sockfd < 0) - { - debug_log("ERROR opening socket\n"); - return -1; - } - - debug_log("wfd_proxy_initialize get socket created\n"); - server = gethostbyname(DEST_HOST); - if (server == NULL) { - debug_log("ERROR, no such host\n"); - return -1; - } - portno = WFD_PROXY_COMM_PORT; - bzero((char *) &serv_addr, sizeof(serv_addr)); - serv_addr.sin_family = AF_INET; - debug_log("wfd_proxy_initialize bcopy\n"); - bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length); - serv_addr.sin_port = htons(portno); - debug_log("wfd_proxy_initialize get socket before connect\n"); - if (connect(wfd->sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) - { - int return_code = 0; - int pid = getpid(); - debug_log("----------- wfd_proxy_initialize socket connect failed it means server is not yet started ------------\n"); - debug_log("going to start WFD server \n"); - bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error); - if (bus == NULL) { - debug_log("dbus bus get failed\n"); - return -1; - } - proxy = dbus_g_proxy_new_for_name(bus, - "com.samsung.wfd.server", - "/com/samsung/wfd/server", - "com.samsung.wfd.server"); - if (proxy == NULL) { - debug_log("dbus bus proxy get failed\n"); - return -1; - } - if (!com_samsung_wfd_server_test_method(proxy, pid, "miracast_server", &return_code, &error)) { - debug_log( - "com_samsung_wfd_server_test_method()failed.test_name[%s], " - "return_code[%d]\n", "miracast_server", return_code); - debug_log("error->message is %s\n", error->message); - } - sleep(1); - debug_log("wfd_proxy_initialize trying for connect\n"); - if (connect(wfd->sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) { - debug_log("wfd_proxy_initialize trying to connect failed\n"); - return -1; - } - } - debug_log("WFD server initiated and connected\n"); - wfd->thread = g_thread_create ((GThreadFunc) wfd_proxy_thread_function, wfd, TRUE, &error); - return 0; -} - -static gboolean is_cmd_valid_in_current_state(WfdSrcProxyState aState, WfdSrcProxyCmd acmd) -{ - //TODO state checking needs to be implemented - return TRUE; -} - -WfdSrcProxyState convert_string_to_state(gchar *buffer) -{ - g_return_val_if_fail (buffer != NULL, WFDSRC_STATE_NUM); - if(!strcmp(buffer, "MM_WFD_STATE_NULL")) return WFDSRC_STATE_NULL; - if(!strcmp(buffer, "MM_WFD_STATE_READY")) return WFDSRC_STATE_READY; - if(!strcmp(buffer, "MM_WFD_STATE_CONNECTION_WAIT")) return WFDSRC_STATE_CONNECTION_WAIT; - if(!strcmp(buffer, "MM_WFD_STATE_CONNECTED")) return WFDSRC_STATE_CONNECTED; - if(!strcmp(buffer, "MM_WFD_STATE_PLAYING")) return WFDSRC_STATE_PLAYING; - if(!strcmp(buffer, "MM_WFD_STATE_PAUSED")) return WFDSRC_STATE_PAUSED; - if(!strcmp(buffer, "MM_WFD_STATE_NONE")) return WFDSRC_STATE_NONE; - return WFDSRC_STATE_NULL; -} - -WfdSrcProxyRet convert_string_to_status(gchar *buffer) -{ - g_return_val_if_fail (buffer != NULL, WFDSRC_ERROR_UNKNOWN); - if(!strcmp(buffer, "MM_ERROR_NONE")) return WFDSRC_ERROR_NONE; - if(!strcmp(buffer, "MM_ERROR_UNKNOWN")) return WFDSRC_ERROR_UNKNOWN; - if(!strcmp(buffer, "MM_ERROR_WFD_INVALID_ARGUMENT")) return WFDSRC_ERROR_WFD_INVALID_ARGUMENT; - if(!strcmp(buffer, "MM_ERROR_WFD_NO_FREE_SPACE")) return WFDSRC_ERROR_WFD_NO_FREE_SPACE; - if(!strcmp(buffer, "MM_ERROR_WFD_NOT_INITIALIZED")) return WFDSRC_ERROR_WFD_NOT_INITIALIZED; - if(!strcmp(buffer, "MM_ERROR_WFD_NO_OP")) return WFDSRC_ERROR_WFD_NO_OP; - if(!strcmp(buffer, "MM_ERROR_WFD_INVALID_STATE")) return WFDSRC_ERROR_WFD_INVALID_STATE; - if(!strcmp(buffer, "MM_ERROR_WFD_INTERNAL")) return WFDSRC_ERROR_WFD_INTERNAL; - return WFDSRC_ERROR_UNKNOWN; -} - -static WfdSrcProxyState wfd_proxy_message_parse_state (const char * data, guint size) -{ - gchar *p; - gchar buffer[128]; - guint idx = 0; - gboolean statequery = false; - g_return_val_if_fail (data != NULL, WFDSRC_STATE_NUM); - g_return_val_if_fail (size != 0, WFDSRC_STATE_NUM); - - p = (gchar *) data; - while (TRUE) { - if (*p == '\0') - break; - idx = 0; - while (*p != '\n' && *p != '\r' && *p != '\0') { - if (idx < sizeof (buffer) - 1) - buffer[idx++] = *p; - p++; - } - buffer[idx] = '\0'; - if(g_strrstr(buffer, "REPLAY WFD_PROXY_STATE_QUERY")) statequery = TRUE; - else if(statequery) return convert_string_to_state(buffer); - if (*p == '\0') - break; - p+=2; - } - return WFDSRC_STATE_NUM; -} - -WfdSrcProxyRet wfd_proxy_message_parse_status (const char * data, guint size) -{ - gchar *p; - gchar buffer[128]; - guint idx = 0; - gboolean replay = false; - g_return_val_if_fail (data != NULL, WFDSRC_ERROR_UNKNOWN); - g_return_val_if_fail (size != 0, WFDSRC_ERROR_UNKNOWN); - - p = (gchar *) data; - while (TRUE) { - if (*p == '\0') - break; - idx = 0; - while (*p != '\n' && *p != '\r' && *p != '\0') { - if (idx < sizeof (buffer) - 1) - buffer[idx++] = *p; - p++; - } - buffer[idx] = '\0'; - if(g_strrstr(buffer, "REPLAY")) replay = TRUE; - else if(replay) return convert_string_to_status(buffer); - if (*p == '\0') - break; - p+=2; - } - return WFDSRC_ERROR_UNKNOWN; -} + if(!lwfd->response) goto retry;
+ }
+ debug_log("WfdSrcProxyGetCurrentState inbuff for command: %s \n", lwfd->inbuff);
+ debug_leave();
+ return wfd_proxy_message_parse_state(lwfd->inbuff, strlen(lwfd->inbuff));
+}
+
+static gboolean proxy_write (WfdSrcProxy *wfd, char *wbuf)
+{
+ write(wfd->sockfd, wbuf, strlen(wbuf));
+ return TRUE;
+}
+
+static void* wfd_proxy_thread_function(void * asrc)
+{
+ fd_set read_flags,write_flags;
+ WfdSrcProxy *wfd = (WfdSrcProxy *)asrc;
+ int rc;
+ while(!wfd->quitloop)
+ {
+ FD_ZERO(&read_flags);
+ FD_ZERO(&write_flags);
+ FD_SET(wfd->sockfd, &read_flags);
+ debug_log("Waiting on select()...\n");
+ rc = select(wfd->sockfd+1, &read_flags, NULL, NULL, NULL);
+ if(rc < 0)
+ continue;
+ if(FD_ISSET(wfd->sockfd, &read_flags))
+ { //Socket ready for reading
+ FD_CLR(wfd->sockfd, &read_flags);
+ memset(&(wfd->inbuff),0,sizeof(wfd->inbuff));
+ debug_log("socket ready for reading...\n");
+ rc = read(wfd->sockfd, wfd->inbuff, sizeof(wfd->inbuff)-1);
+ if (rc <= 0)
+ {
+ debug_log("socket connection closed\n");
+ wfd->server_destroyed = TRUE;
+ goto cleanup;
+ }
+ debug_log("wfd_proxy replay for command: %s \n", wfd->inbuff);
+ if(g_strrstr(wfd->inbuff, "NOTIFY"))
+ {
+ if(wfd->applicationCb)
+ {
+ gchar **notify;
+ notify = g_strsplit(wfd->inbuff,"\r\n",0);
+ wfd->applicationCb(asrc, convert_string_to_status(notify[2]), convert_string_to_state(notify[1]), wfd->user_data);
+ }
+ }
+ else
+ {
+ debug_log("wfd_proxy signalling \n");
+ wfd->response = TRUE;
+ g_cond_signal(wfd->cond);
+ debug_log("wfd_proxy signal emitted \n");
+ }
+ }
+ }
+cleanup:
+ close (wfd->sockfd);
+ FD_CLR (wfd->sockfd, &read_flags);
+ debug_log("thread function signal\n");
+ g_cond_signal(wfd->cond);
+ debug_log("thread function quit\n");
+ if((!wfd->quitloop) && wfd->applicationCb)
+ {
+ debug_log("sending notification to proxytest");
+ wfd->applicationCb(asrc, WFDSRC_ERROR_WFD_INVALID_STATE, WFDSRC_STATE_NULL, wfd->user_data);
+ }
+ return NULL;
+}
+
+static int wfd_proxy_initialize(WfdSrcProxy *wfd)
+{
+ DBusGConnection *bus = NULL;
+ DBusGProxy *proxy = NULL;
+ g_type_init();
+ debug_log("wfd_proxy_initialize init \n");
+ int portno;
+ struct sockaddr_in serv_addr;
+ struct hostent *server;
+ GError *error = NULL;
+ debug_log("wfd_proxy_initialize get before socket\n");
+ wfd->sockfd = socket(AF_INET, SOCK_STREAM, 0);
+ if (wfd->sockfd < 0)
+ {
+ debug_log("ERROR opening socket\n");
+ return -1;
+ }
+
+ debug_log("wfd_proxy_initialize get socket created\n");
+ server = gethostbyname(DEST_HOST);
+ if (server == NULL) {
+ debug_log("ERROR, no such host\n");
+ return -1;
+ }
+ portno = WFD_PROXY_COMM_PORT;
+ bzero((char *) &serv_addr, sizeof(serv_addr));
+ serv_addr.sin_family = AF_INET;
+ debug_log("wfd_proxy_initialize bcopy\n");
+ bcopy((char *)server->h_addr, (char *)&serv_addr.sin_addr.s_addr, server->h_length);
+ serv_addr.sin_port = htons(portno);
+ debug_log("wfd_proxy_initialize get socket before connect\n");
+ if (connect(wfd->sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0)
+ {
+ int return_code = 0;
+ int pid = getpid();
+ debug_log("----------- wfd_proxy_initialize socket connect failed it means server is not yet started ------------\n");
+ debug_log("going to start WFD server \n");
+ bus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
+ if (bus == NULL) {
+ debug_log("dbus bus get failed\n");
+ return -1;
+ }
+ proxy = dbus_g_proxy_new_for_name(bus,
+ "com.samsung.wfd.server",
+ "/com/samsung/wfd/server",
+ "com.samsung.wfd.server");
+ if (proxy == NULL) {
+ debug_log("dbus bus proxy get failed\n");
+ return -1;
+ }
+ if (!com_samsung_wfd_server_test_method(proxy, pid, "miracast_server", &return_code, &error)) {
+ debug_log(
+ "com_samsung_wfd_server_test_method()failed.test_name[%s], "
+ "return_code[%d]\n", "miracast_server", return_code);
+ debug_log("error->message is %s\n", error->message);
+ }
+ sleep(1);
+ debug_log("wfd_proxy_initialize trying for connect\n");
+ if (connect(wfd->sockfd,(struct sockaddr *) &serv_addr,sizeof(serv_addr)) < 0) {
+ debug_log("wfd_proxy_initialize trying to connect failed\n");
+ return -1;
+ }
+ }
+ debug_log("WFD server initiated and connected\n");
+ wfd->thread = g_thread_create ((GThreadFunc) wfd_proxy_thread_function, wfd, TRUE, &error);
+ return 0;
+}
+
+static gboolean is_cmd_valid_in_current_state(WfdSrcProxyState aState, WfdSrcProxyCmd acmd)
+{
+ //TODO state checking needs to be implemented
+ return TRUE;
+}
+
+WfdSrcProxyState convert_string_to_state(gchar *buffer)
+{
+ g_return_val_if_fail (buffer != NULL, WFDSRC_STATE_NUM);
+ if(!strcmp(buffer, "MM_WFD_STATE_NULL")) return WFDSRC_STATE_NULL;
+ if(!strcmp(buffer, "MM_WFD_STATE_READY")) return WFDSRC_STATE_READY;
+ if(!strcmp(buffer, "MM_WFD_STATE_CONNECTION_WAIT")) return WFDSRC_STATE_CONNECTION_WAIT;
+ if(!strcmp(buffer, "MM_WFD_STATE_CONNECTED")) return WFDSRC_STATE_CONNECTED;
+ if(!strcmp(buffer, "MM_WFD_STATE_PLAYING")) return WFDSRC_STATE_PLAYING;
+ if(!strcmp(buffer, "MM_WFD_STATE_PAUSED")) return WFDSRC_STATE_PAUSED;
+ if(!strcmp(buffer, "MM_WFD_STATE_NONE")) return WFDSRC_STATE_NONE;
+ return WFDSRC_STATE_NULL;
+}
+
+WfdSrcProxyRet convert_string_to_status(gchar *buffer)
+{
+ g_return_val_if_fail (buffer != NULL, WFDSRC_ERROR_UNKNOWN);
+ if(!strcmp(buffer, "MM_ERROR_NONE")) return WFDSRC_ERROR_NONE;
+ if(!strcmp(buffer, "MM_ERROR_UNKNOWN")) return WFDSRC_ERROR_UNKNOWN;
+ if(!strcmp(buffer, "MM_ERROR_WFD_INVALID_ARGUMENT")) return WFDSRC_ERROR_WFD_INVALID_ARGUMENT;
+ if(!strcmp(buffer, "MM_ERROR_WFD_NO_FREE_SPACE")) return WFDSRC_ERROR_WFD_NO_FREE_SPACE;
+ if(!strcmp(buffer, "MM_ERROR_WFD_NOT_INITIALIZED")) return WFDSRC_ERROR_WFD_NOT_INITIALIZED;
+ if(!strcmp(buffer, "MM_ERROR_WFD_NO_OP")) return WFDSRC_ERROR_WFD_NO_OP;
+ if(!strcmp(buffer, "MM_ERROR_WFD_INVALID_STATE")) return WFDSRC_ERROR_WFD_INVALID_STATE;
+ if(!strcmp(buffer, "MM_ERROR_WFD_INTERNAL")) return WFDSRC_ERROR_WFD_INTERNAL;
+ return WFDSRC_ERROR_UNKNOWN;
+}
+
+static WfdSrcProxyState wfd_proxy_message_parse_state (const char * data, guint size)
+{
+ gchar *p;
+ gchar buffer[128];
+ guint idx = 0;
+ gboolean statequery = false;
+ g_return_val_if_fail (data != NULL, WFDSRC_STATE_NUM);
+ g_return_val_if_fail (size != 0, WFDSRC_STATE_NUM);
+
+ p = (gchar *) data;
+ while (TRUE) {
+ if (*p == '\0')
+ break;
+ idx = 0;
+ while (*p != '\n' && *p != '\r' && *p != '\0') {
+ if (idx < sizeof (buffer) - 1)
+ buffer[idx++] = *p;
+ p++;
+ }
+ buffer[idx] = '\0';
+ if(g_strrstr(buffer, "REPLAY WFD_PROXY_STATE_QUERY")) statequery = TRUE;
+ else if(statequery) return convert_string_to_state(buffer);
+ if (*p == '\0')
+ break;
+ p+=2;
+ }
+ return WFDSRC_STATE_NUM;
+}
+
+WfdSrcProxyRet wfd_proxy_message_parse_status (const char * data, guint size)
+{
+ gchar *p;
+ gchar buffer[128];
+ guint idx = 0;
+ gboolean replay = false;
+ g_return_val_if_fail (data != NULL, WFDSRC_ERROR_UNKNOWN);
+ g_return_val_if_fail (size != 0, WFDSRC_ERROR_UNKNOWN);
+
+ p = (gchar *) data;
+ while (TRUE) {
+ if (*p == '\0')
+ break;
+ idx = 0;
+ while (*p != '\n' && *p != '\r' && *p != '\0') {
+ if (idx < sizeof (buffer) - 1)
+ buffer[idx++] = *p;
+ p++;
+ }
+ buffer[idx] = '\0';
+ if(g_strrstr(buffer, "REPLAY")) replay = TRUE;
+ else if(replay) return convert_string_to_status(buffer);
+ if (*p == '\0')
+ break;
+ p+=2;
+ }
+ return WFDSRC_ERROR_UNKNOWN;
+}
|