incubator-bluesky-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mabo...@apache.org
Subject svn commit: r1022999 [3/3] - /incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/
Date Fri, 15 Oct 2010 16:26:25 GMT
Modified: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/adminserver.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/adminserver.h?rev=1022999&r1=1022998&r2=1022999&view=diff
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/adminserver.h
(original)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/adminserver.h
Fri Oct 15 16:26:25 2010
@@ -32,7 +32,6 @@ class CAsyncSocketEx;
 #include "lissocket.h"
 #include "clientsocket.h"
 #include "multicomm.h"
-#include "jmutex.h"
 #include "error.h"
 #include <signal.h>  
 #include <arpa/inet.h>  
@@ -46,6 +45,8 @@ class CAsyncSocketEx;
 #include <netdb.h>  
 #include <setjmp.h> 
 #include <errno.h>
+//intend to imgrate jmutex to qmutex
+#include <QMutex>
 class CLisSocket;
 
 //Client list
@@ -75,10 +76,12 @@ public:
 	int Init();
 	CAdminServer();
 	virtual ~CAdminServer();
-    int DataSent(DWORD);
-    BOOL IsComplete(std::string);
     int rclSendMessage(DWORD,std::string);//send message to a ID with a string
+    /**
+      * @deprecated rclSendM();
+      */
     int rclSendM();//send_thread send message
+
     BOOL ParseRequest(CRCLMSG* pM, int event, SOCKET s, BOOL &bKeepAlive);
     int GotConnection(SOCKET,char*,int);//user join
     int Disconnect(SOCKET s);//delete a user
@@ -87,15 +90,15 @@ private:
 	int rclSendThreadHandle;//send_thread handle
     NodeChangeNotify NodeInfoOut;//node information out
     
-    JMutex umu;//user list 
-    JMutex tmu;//teacher list 
-    JMutex mmu;//MCU list 
-    JMutex smu;//seMCU list 
-    JMutex rmu;//room list 
-    JMutex imu;//IP list
-    JMutex dmu;//ID list 
-	JMutex Jtext_layoutC;
-	JMutex Jtext_layoutT;
+    QMutex umu;//user list
+    QMutex tmu;//teacher list
+    QMutex mmu;//MCU list
+    QMutex smu;//seMCU list
+    QMutex rmu;//room list
+    QMutex imu;//IP list
+    QMutex dmu;//ID list
+    QMutex Jtext_layoutC;
+    QMutex Jtext_layoutT;
 
     DWORD hScan;
     DWORD rclSysMax;// max number for system 
@@ -117,7 +120,9 @@ public:
 public:
 	int rclGetIPSameA(char *ClientIP,char *MCUIP);
     void rclDebugLog(char *log,char *vl="",int v2=0,int v3=0,int v4=0);
- 
+    /**
+      * @deprecated rclScanSys();
+      */
     void rclScanSys();
     int rclNodeChooseMCUIP(char* ip,char *pip,SOCKET s);
     int rclGetIPSame(char *ClientIP,char *MCUIP);
@@ -158,16 +163,27 @@ public:
 	int rclTeacherLogout(CRCLTeacherLogout *pMSG,SOCKET s);
 	int rclTeacherLogin(CRCLTeacherLogin *pMSG,SOCKET s,int event);	
 	int rclUserSendTextToGroup(DWORD userid,DWORD groupid,std::string text,int flag);	
-	int rclUserSendTextToUser();
 	int rclTeacherChat(CRCLTeacherChat *pMSG ,SOCKET s);
 	int rclBroadCast(DWORD);
-	void pingtest();
+        /**use icmp protocol to measure RTT time
+         * @deprecated pingtest();
+         */
+        void pingtest();
 		
 	void* statistics(int signo);  
 	unsigned short cal_chksum(unsigned short *addr,int len);  
 	int pack(int pack_no);  
+
+        /**use icmp protocol to measure RTT time
+          * @deprecated
+          */
 	void send_packet(void);  
+
+        /**use icmp protocol to measure RTT time
+          * @deprecated
+          */
 	void recv_packet(void);  
+
 	int unpack(char *buf,int len);  
 	void tv_sub(struct timeval *out,struct timeval *in); 
 	
@@ -176,10 +192,19 @@ public:
 	void rclShowMCUInfo();
 	void rclShowSeMCUInfo();
 	void rclShowRoomInfo();
+
+        /**
+          *@deprecated rclShowIPInfo()
+          */
 	void rclShowIPInfo();
 	void rclShowIDInfo();
+        /**@brief show focus student info
+          *@deprecated rclShowFocusInfo()
+          */
 	void rclShowFocusInfo();
-	
+        /**@brief what if server crash
+          *@deprecated rclShutdown()
+          */
 	void rclShutdown();
 
 	

Modified: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/clientsocket.cpp
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/clientsocket.cpp?rev=1022999&r1=1022998&r2=1022999&view=diff
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/clientsocket.cpp
(original)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/clientsocket.cpp
Fri Oct 15 16:26:25 2010
@@ -14,84 +14,84 @@
 //KIND, either express or implied.  See the License for the
 //specific language governing permissions and limitations
 //under the License. 
-// ClientSocket.cpp: implementation of the CClientSocket class.
-//
-//////////////////////////////////////////////////////////////////////
-
-#include "stdafx.h"
-#include "clientsocket.h"
-#include "adminserver.h"
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
-extern CAdminServer server;
-CClientSocket::CClientSocket()
-{
-
-}
-
-CClientSocket::~CClientSocket()
-{
-	Close();
-}
-
-void CClientSocket::OnEvent()
-{
-	char recvbuffer[10000];
-	char caddr[50];
-    unsigned long len;
-	SOCKADDR lpSockAddr;
-    SOCKET s;
-	int iplen = sizeof(SOCKADDR);
-	BOOL rclb;
-	rclb = false;
-	if(m_lEvent == 0)			//no any event.
-		return;
-	IOCtl(FIONREAD, &len);
-	if(len==0){			//disconnect.
-		int ret = 1;
-
-		server.Disconnect(GetSocketHandle());
-		printf("read to close socket\n");
-		ShutDown(both);
-		while(ret>0){
-			ret = Receive(recvbuffer, 10000);	
-		}
-		Close();
-		printf("A client disconnected.\n");
-		return ;
-	}
-
-	s = GetSocketHandle();
-	if(GetPeerName(&lpSockAddr,&iplen))
-	{
-	SOCKADDR_IN* ip = (SOCKADDR_IN*)&lpSockAddr;
-		sprintf(caddr,"%d.%d.%d.%d",
-		        ((u_char*)&ip->sin_addr.s_addr)[0], 
-				((u_char*)&ip->sin_addr.s_addr)[1], 
-				((u_char*)&ip->sin_addr.s_addr)[2], 
-				((u_char*)&ip->sin_addr.s_addr)[3]);
-	server.GotConnection(s, caddr, ip->sin_port);		
-	printf("%s\n",caddr);
-
-	}
-	memset(recvbuffer, 0, 10000);
-	int recv_len = Receive(recvbuffer, 9999);
-	CRCLMSG* pM = (CRCLMSG*)recvbuffer;
-	int index = recv_len;
-	int packetlen = pM->msglen +8 - recv_len;
-	while(packetlen > 0)
-	{
-		recv_len = Receive(recvbuffer+index, packetlen);
-		printf("	recv a message lenth is %d\n",recv_len);
-		index += recv_len;
-		packetlen -= recv_len;
-	}
-	pM = (CRCLMSG*)recvbuffer;
-
-
-	if(!server.ParseRequest(pM, 1, s, rclb))
-		printf("parse failed\n");
-
-	return ;
+// ClientSocket.cpp: implementation of the CClientSocket class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#include "stdafx.h"
+#include "clientsocket.h"
+#include "adminserver.h"
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+extern CAdminServer server;
+CClientSocket::CClientSocket()
+{
+
+}
+
+CClientSocket::~CClientSocket()
+{
+    Close();
+}
+
+void CClientSocket::OnEvent()
+{
+    char recvbuffer[10000];
+    char caddr[50];
+    unsigned long len;
+    SOCKADDR lpSockAddr;
+    SOCKET s;
+    int iplen = sizeof(SOCKADDR);
+    BOOL rclb;
+    rclb = false;
+    if(m_lEvent == 0)			//no any event.
+        return;
+    IOCtl(FIONREAD, &len);
+    if(len==0){			//disconnect.
+        int ret = 1;
+
+        server.Disconnect(GetSocketHandle());
+        printf("read to close socket\n");
+        ShutDown(both);
+        while(ret>0){
+            ret = Receive(recvbuffer, 10000);
+        }
+        Close();
+        printf("A client disconnected.\n");
+        return ;
+    }
+
+    s = GetSocketHandle();
+    if(GetPeerName(&lpSockAddr,&iplen))
+    {
+	SOCKADDR_IN* ip = (SOCKADDR_IN*)&lpSockAddr;
+        sprintf(caddr,"%d.%d.%d.%d",
+                ((u_char*)&ip->sin_addr.s_addr)[0],
+                ((u_char*)&ip->sin_addr.s_addr)[1],
+                ((u_char*)&ip->sin_addr.s_addr)[2],
+                ((u_char*)&ip->sin_addr.s_addr)[3]);
+	server.GotConnection(s, caddr, ip->sin_port);		
+	printf("%s\n",caddr);
+
+    }
+    memset(recvbuffer, 0, 10000);
+    int recv_len = Receive(recvbuffer, 9999);
+    CRCLMSG* pM = (CRCLMSG*)recvbuffer;
+    int index = recv_len;
+    int packetlen = pM->msglen +8 - recv_len;
+    while(packetlen > 0)
+    {
+        recv_len = Receive(recvbuffer+index, packetlen);
+        printf("	recv a message lenth is %d\n",recv_len);
+        index += recv_len;
+        packetlen -= recv_len;
+    }
+    pM = (CRCLMSG*)recvbuffer;
+
+
+    if(!server.ParseRequest(pM, 1, s, rclb))
+        printf("parse failed\n");
+
+    return ;
 }

Modified: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/listencomm.cpp
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/listencomm.cpp?rev=1022999&r1=1022998&r2=1022999&view=diff
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/listencomm.cpp
(original)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/listencomm.cpp
Fri Oct 15 16:26:25 2010
@@ -15,114 +15,120 @@
 //specific language governing permissions and limitations
 //under the License. 
 
-// ListenComm.cpp: implementation of the CListenComm class.
-//
-//////////////////////////////////////////////////////////////////////
-
-#include "asyncsocketex.h"
-#include "listencomm.h"
-
-#define SOCKETMUTEX_LOCK	{\
-							socketmutex.Lock();	\
-							}
-							
-
-#define SOCKETMUTEX_UNLOCK	{	\
-							socketmutex.Unlock();}
-
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
-
-CListenComm::CListenComm()
-{
-
-	m_socket = 0;
-}
-
-CListenComm::~CListenComm()
-{
-	m_socket = 0;
-}
-
-bool CListenComm::Init()
-{
-	if(!CTCPComm::Init())
-		return false;
-
-	if (!socketmutex.IsInitialized())
-	{
-		if (socketmutex.Init() < 0)
-			return false;
-	}
-
-	return true;
-}
-
-int CListenComm::OnPollThreadError(int status)
-{
-
-	return -1;
-}
-
-int CListenComm::Poll()
-{
-	int nRes;
-	SOCKETMUTEX_LOCK	
-
-	if(m_socket == 0){
-		SOCKETMUTEX_UNLOCK
-		return 0;
-	}
-
-	nRes = m_socket->Poll();
-	if(nRes < 0){
-		SOCKETMUTEX_UNLOCK
-		return nRes;
-	}
-
-	m_socket->SetStatus(nRes);
-
-	SOCKETMUTEX_UNLOCK
-	return nRes;
-}
-
-int CListenComm::PolledSocket()
-{
-
-	SOCKETMUTEX_LOCK	
-
-	if(m_socket == 0){
-		SOCKETMUTEX_UNLOCK
-		return 0;
-	}
-
-	m_socket->OnEvent();
-
-	SOCKETMUTEX_UNLOCK
-	return 1;
-}
-
-
-void CListenComm::Attach(CAsyncSocketEx* socket)
-{
-	SOCKETMUTEX_LOCK	
-
-	m_socket = socket;
-	SOCKETMUTEX_UNLOCK
-}
-
-CAsyncSocketEx* CListenComm::Detach()
-{
-	SOCKETMUTEX_LOCK	
-	CAsyncSocketEx* p = m_socket;
-	m_socket = 0;
-	SOCKETMUTEX_UNLOCK
-	return p;
-}
-
-void CListenComm::OnPollThreadStep()
-{
-	
-	usleep(200000);
+// ListenComm.cpp: implementation of the CListenComm class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#include "asyncsocketex.h"
+#include "listencomm.h"
+
+#define SOCKETMUTEX_LOCK	{\
+                                                        socketmutex.lock();	\
+							}
+							
+
+#define SOCKETMUTEX_UNLOCK	{	\
+                                                        socketmutex.unlock();}
+
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+
+CListenComm::CListenComm()
+{
+
+	m_socket = 0;
+}
+
+CListenComm::~CListenComm()
+{
+	m_socket = 0;
+}
+
+bool CListenComm::Init()
+{
+	if(!CTCPComm::Init())
+		return false;
+
+//	if (!socketmutex.IsInitialized())
+//	{
+//		if (socketmutex.Init() < 0)
+//			return false;
+//	}
+
+        if (!socketmutex.tryLock())
+        {
+            socketmutex.unlock();
+        }
+        else
+            socketmutex.unlock();
+	return true;
+}
+
+int CListenComm::OnPollThreadError(int status)
+{
+
+	return -1;
+}
+
+int CListenComm::Poll()
+{
+	int nRes;
+	SOCKETMUTEX_LOCK	
+
+	if(m_socket == 0){
+		SOCKETMUTEX_UNLOCK
+		return 0;
+	}
+
+	nRes = m_socket->Poll();
+	if(nRes < 0){
+		SOCKETMUTEX_UNLOCK
+		return nRes;
+	}
+
+	m_socket->SetStatus(nRes);
+
+	SOCKETMUTEX_UNLOCK
+	return nRes;
+}
+
+int CListenComm::PolledSocket()
+{
+
+	SOCKETMUTEX_LOCK	
+
+	if(m_socket == 0){
+		SOCKETMUTEX_UNLOCK
+		return 0;
+	}
+
+	m_socket->OnEvent();
+
+	SOCKETMUTEX_UNLOCK
+	return 1;
+}
+
+
+void CListenComm::Attach(CAsyncSocketEx* socket)
+{
+	SOCKETMUTEX_LOCK	
+
+	m_socket = socket;
+	SOCKETMUTEX_UNLOCK
+}
+
+CAsyncSocketEx* CListenComm::Detach()
+{
+	SOCKETMUTEX_LOCK	
+	CAsyncSocketEx* p = m_socket;
+	m_socket = 0;
+	SOCKETMUTEX_UNLOCK
+	return p;
+}
+
+void CListenComm::OnPollThreadStep()
+{
+	
+	usleep(200000);
 }

Modified: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/listencomm.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/listencomm.h?rev=1022999&r1=1022998&r2=1022999&view=diff
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/listencomm.h
(original)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/listencomm.h
Fri Oct 15 16:26:25 2010
@@ -15,34 +15,34 @@
 //specific language governing permissions and limitations
 //under the License. 
 
-// ListenComm.h: interface for the CListenComm class.
-//
-//////////////////////////////////////////////////////////////////////
-
-#if !defined(LISTENCOMM_H)
-#define LISTENCOMM_H
-
-#include "tcpcomm.h"
-#include "jmutex.h"
-
-class CListenComm : public CTCPComm  
-{
-public:
-	CAsyncSocketEx* Detach();
-	void Attach(CAsyncSocketEx* socket);
-	CListenComm();
-	virtual ~CListenComm();
-	virtual bool Init();
-
-protected:
-	virtual void OnPollThreadStep();
-	virtual int OnPollThreadError(int status);
-	virtual int PolledSocket();
-	virtual int Poll() ;
-
-private:
-	JMutex socketmutex;
-	CAsyncSocketEx* m_socket;
-};
-
+// ListenComm.h: interface for the CListenComm class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#if !defined(LISTENCOMM_H)
+#define LISTENCOMM_H
+
+#include "tcpcomm.h"
+#include <QMutex>
+
+class CListenComm : public CTCPComm  
+{
+public:
+	CAsyncSocketEx* Detach();
+	void Attach(CAsyncSocketEx* socket);
+	CListenComm();
+	virtual ~CListenComm();
+	virtual bool Init();
+
+protected:
+	virtual void OnPollThreadStep();
+	virtual int OnPollThreadError(int status);
+	virtual int PolledSocket();
+	virtual int Poll() ;
+
+private:
+        QMutex socketmutex;
+	CAsyncSocketEx* m_socket;
+};
+
 #endif // !defined(LISTENCOMM_H)

Modified: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/mainwindow.cpp
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/mainwindow.cpp?rev=1022999&r1=1022998&r2=1022999&view=diff
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/mainwindow.cpp
(original)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/mainwindow.cpp
Fri Oct 15 16:26:25 2010
@@ -3,9 +3,9 @@
 #include "adminserver.h"
 CAdminServer server;
 MainWindow::MainWindow(QWidget *parent)
-    : QMainWindow(parent), ui(new Ui::MainWindow)
+    : QMainWindow(parent), ui(new Ui::mainWindow)
 {
-   // server.Init();
+    server.Init();
 
     ui->setupUi(this);
 }

Modified: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/mainwindow.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/mainwindow.h?rev=1022999&r1=1022998&r2=1022999&view=diff
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/mainwindow.h
(original)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/mainwindow.h
Fri Oct 15 16:26:25 2010
@@ -6,7 +6,7 @@
 //CAdminServer server;
 namespace Ui
 {
-    class MainWindow;
+    class mainWindow;
 }
 
 class MainWindow : public QMainWindow
@@ -18,7 +18,7 @@ public:
     ~MainWindow();
     void StartTserver();
 private:
-    Ui::MainWindow *ui;
+    Ui::mainWindow *ui;
 };
 
 

Modified: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/mainwindow.ui
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/mainwindow.ui?rev=1022999&r1=1022998&r2=1022999&view=diff
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/mainwindow.ui
(original)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/mainwindow.ui
Fri Oct 15 16:26:25 2010
@@ -6,20 +6,31 @@
    <rect>
     <x>0</x>
     <y>0</y>
-    <width>600</width>
-    <height>400</height>
+    <width>680</width>
+    <height>537</height>
    </rect>
   </property>
   <property name="windowTitle">
    <string>MainWindow</string>
   </property>
-  <widget class="QWidget" name="centralWidget"/>
+  <widget class="QWidget" name="centralWidget">
+   <widget class="QTextBrowser" name="tServerMsg">
+    <property name="geometry">
+     <rect>
+      <x>10</x>
+      <y>130</y>
+      <width>331</width>
+      <height>361</height>
+     </rect>
+    </property>
+   </widget>
+  </widget>
   <widget class="QMenuBar" name="menuBar">
    <property name="geometry">
     <rect>
      <x>0</x>
      <y>0</y>
-     <width>600</width>
+     <width>680</width>
      <height>25</height>
     </rect>
    </property>

Modified: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/msgtype.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/msgtype.h?rev=1022999&r1=1022998&r2=1022999&view=diff
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/msgtype.h (original)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/msgtype.h Fri
Oct 15 16:26:25 2010
@@ -18,7 +18,7 @@
 #include "stdafx.h"
 #include <list>
 #include <string>
-#include "jmutex.h"
+#include <QMutex>
 #define ServerVersionID 0x10000000
 #define NAMELEN 200
 
@@ -129,8 +129,8 @@ struct CRCLRoom 
 	DWORD rclTeacherID;
 	DWORD rclMCUID;
 	DWORD rclFocusUserID;
-	JMutex cs;
-	JMutex ms;
+        QMutex cs;
+        QMutex ms;
 	
 	std::list<DWORD> rclUserRoom;
 	

Modified: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/multicomm.cpp
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/multicomm.cpp?rev=1022999&r1=1022998&r2=1022999&view=diff
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/multicomm.cpp
(original)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/multicomm.cpp
Fri Oct 15 16:26:25 2010
@@ -16,169 +16,169 @@
 //under the License. 
 
 
-// MultiComm.cpp: implementation of the CMultiComm class.
-//
-//////////////////////////////////////////////////////////////////////
-
-#include "stdafx.h"
-#include <list>
-
-#include "clientsocket.h"
-#include "multicomm.h"
-
-#define LISTMUTEX_LOCK		{	\
-							listmutex.Lock();	\
-							}
-							
-
-#define LISTMUTEX_UNLOCK	{\
-							listmutex.Unlock();}
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
-
-CMultiComm::CMultiComm()
-{
-
-}
-
-CMultiComm::~CMultiComm()
-{
-	ClearList();
-}
-
-bool CMultiComm::Init()
-{
-	if(!CTCPComm::Init())
-		return false;
-
-	if (!listmutex.IsInitialized())
-	{
-		if (listmutex.Init() < 0)
-			return false;
-	}
-
-	return true;
-}
-
-int CMultiComm::OnPollThreadError(int status)
-{
-	LISTMUTEX_LOCK
-	LISTMUTEX_UNLOCK
-	return -1;
-}
-
-void CMultiComm::OnPollThreadStep()
-{
-	
-
-	usleep(200000);
-}
-
-int CMultiComm::PolledSocket()
-{
-
-	CAsyncSocketEx* psocket = 0;
-	LISTMUTEX_LOCK
-	
-	SOCKETLIST::iterator index;
-	for(index=m_socketlist.begin(); index!=m_socketlist.end(); ++index){
-		psocket = *index;
-		if(psocket){
-			psocket->OnEvent();
-			if(psocket->GetSocketHandle() == INVALID_SOCKET){
-				*index = 0;
-				delete psocket;
-			}
-		}
-	}
-
-	m_socketlist.remove(0);
-	LISTMUTEX_UNLOCK
-	return 0;
-}
-int CMultiComm::Poll()
-{
-	int nRes;
-	CAsyncSocketEx* psocket = 0;
-	LISTMUTEX_LOCK
-	
-	SOCKETLIST::iterator index;
-
-	for(index=m_socketlist.begin(); index!=m_socketlist.end(); index++){
-		psocket = *index;
-		if(psocket){
-			nRes = psocket->Poll();
-			if(nRes<0){
-				LISTMUTEX_UNLOCK
-				return nRes;
-			}
-			psocket->SetStatus(nRes);
-		}
-	}
-
-	LISTMUTEX_UNLOCK
-	return 0;
-}
-
-void CMultiComm::ClearList()
-{
-	CClientSocket* p = 0;
-
-	SOCKETLIST::iterator index;
-
-	LISTMUTEX_LOCK
-
-	for(index=m_socketlist.begin(); index!=m_socketlist.end(); index++){
-		p = *index;
-		if(p){
-			delete p;
-		}
-	}
-
-	m_socketlist.clear();
-
-	LISTMUTEX_UNLOCK
-}
-
-bool CMultiComm::AddSocket(SOCKET socket)
-{
-	CClientSocket* p;
-	CClientSocket* psocket;
-	SOCKETLIST::iterator index;
-	if(socket == 0)
-		return true;
-
-	psocket = new CClientSocket;
-	if(psocket == 0)
-		return false;
-	psocket->Attach(socket, 0);
-
-	LISTMUTEX_LOCK
-
-	for(index=m_socketlist.begin(); index!=m_socketlist.end(); index++){
-		p = *index;
-		if(p){
-			if(p->GetSocketHandle() == socket){
-					LISTMUTEX_UNLOCK
-					return true;
-			}
-		}
-	}
-
-	m_socketlist.insert(m_socketlist.end(), psocket);
-	LISTMUTEX_UNLOCK
-	return true;
-}
-
-unsigned int CMultiComm::GetCount()
-{
-	unsigned int count;
-	LISTMUTEX_LOCK
-
-	count = m_socketlist.size();
-
-	LISTMUTEX_UNLOCK
-
-	return count;
+// MultiComm.cpp: implementation of the CMultiComm class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#include "stdafx.h"
+#include <list>
+
+#include "clientsocket.h"
+#include "multicomm.h"
+
+#define LISTMUTEX_LOCK		{	\
+                                                        listmutex.lock();	\
+							}
+							
+
+#define LISTMUTEX_UNLOCK	{\
+                                                        listmutex.unlock();}
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+
+CMultiComm::CMultiComm()
+{
+
+}
+
+CMultiComm::~CMultiComm()
+{
+	ClearList();
+}
+
+bool CMultiComm::Init()
+{
+	if(!CTCPComm::Init())
+		return false;
+
+        if (!listmutex.tryLock())
+	{
+                    listmutex.unlock();
+	}
+        else
+            listmutex.unlock();
+	return true;
+}
+
+int CMultiComm::OnPollThreadError(int status)
+{
+	LISTMUTEX_LOCK
+	LISTMUTEX_UNLOCK
+	return -1;
+}
+
+void CMultiComm::OnPollThreadStep()
+{
+	
+
+	usleep(200000);
+}
+
+int CMultiComm::PolledSocket()
+{
+
+	CAsyncSocketEx* psocket = 0;
+	LISTMUTEX_LOCK
+	
+	SOCKETLIST::iterator index;
+	for(index=m_socketlist.begin(); index!=m_socketlist.end(); ++index){
+		psocket = *index;
+		if(psocket){
+			psocket->OnEvent();
+			if(psocket->GetSocketHandle() == INVALID_SOCKET){
+				*index = 0;
+				delete psocket;
+			}
+		}
+	}
+
+	m_socketlist.remove(0);
+	LISTMUTEX_UNLOCK
+	return 0;
+}
+int CMultiComm::Poll()
+{
+	int nRes;
+	CAsyncSocketEx* psocket = 0;
+	LISTMUTEX_LOCK
+	
+	SOCKETLIST::iterator index;
+
+	for(index=m_socketlist.begin(); index!=m_socketlist.end(); index++){
+		psocket = *index;
+		if(psocket){
+			nRes = psocket->Poll();
+			if(nRes<0){
+				LISTMUTEX_UNLOCK
+				return nRes;
+			}
+			psocket->SetStatus(nRes);
+		}
+	}
+
+	LISTMUTEX_UNLOCK
+	return 0;
+}
+
+void CMultiComm::ClearList()
+{
+	CClientSocket* p = 0;
+
+	SOCKETLIST::iterator index;
+
+	LISTMUTEX_LOCK
+
+	for(index=m_socketlist.begin(); index!=m_socketlist.end(); index++){
+		p = *index;
+		if(p){
+			delete p;
+		}
+	}
+
+	m_socketlist.clear();
+
+	LISTMUTEX_UNLOCK
+}
+
+bool CMultiComm::AddSocket(SOCKET socket)
+{
+	CClientSocket* p;
+	CClientSocket* psocket;
+	SOCKETLIST::iterator index;
+	if(socket == 0)
+		return true;
+
+	psocket = new CClientSocket;
+	if(psocket == 0)
+		return false;
+	psocket->Attach(socket, 0);
+
+	LISTMUTEX_LOCK
+
+	for(index=m_socketlist.begin(); index!=m_socketlist.end(); index++){
+		p = *index;
+		if(p){
+			if(p->GetSocketHandle() == socket){
+					LISTMUTEX_UNLOCK
+					return true;
+			}
+		}
+	}
+
+	m_socketlist.insert(m_socketlist.end(), psocket);
+	LISTMUTEX_UNLOCK
+	return true;
+}
+
+unsigned int CMultiComm::GetCount()
+{
+	unsigned int count;
+	LISTMUTEX_LOCK
+
+	count = m_socketlist.size();
+
+	LISTMUTEX_UNLOCK
+
+	return count;
 }

Modified: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/multicomm.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/multicomm.h?rev=1022999&r1=1022998&r2=1022999&view=diff
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/multicomm.h (original)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/multicomm.h Fri
Oct 15 16:26:25 2010
@@ -15,40 +15,39 @@
 //specific language governing permissions and limitations
 //under the License. 
 
-// MultiComm.h: interface for the CMultiComm class.
-//
-//////////////////////////////////////////////////////////////////////
-
-#if !defined(MULTICOMM_H)
-#define MULTICOMM_H
-
-#include "tcpcomm.h"
-#include "jmutex.h"
-
-typedef std::list<CClientSocket*>	SOCKETLIST;
-
-class CLisSocket;
-class CMultiComm : public CTCPComm  
-{
-	friend class CLisSocket;
-	friend class CClientSocket;
-public:
-	CMultiComm();
-	virtual ~CMultiComm();
-	virtual bool Init();
-
-protected:
-	virtual int OnPollThreadError(int status);
-	virtual int PolledSocket();
-	virtual int Poll() ;
-	virtual void OnPollThreadStep();
-public:
-	void ClearList();
-private:
-	unsigned int GetCount();
-	bool AddSocket(SOCKET socket);
-	JMutex listmutex;
-	SOCKETLIST m_socketlist;
-};
-
+// MultiComm.h: interface for the CMultiComm class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#if !defined(MULTICOMM_H)
+#define MULTICOMM_H
+
+#include "tcpcomm.h"
+#include <QMutex>
+typedef std::list<CClientSocket*>	SOCKETLIST;
+
+class CLisSocket;
+class CMultiComm : public CTCPComm  
+{
+	friend class CLisSocket;
+	friend class CClientSocket;
+public:
+	CMultiComm();
+	virtual ~CMultiComm();
+	virtual bool Init();
+
+protected:
+	virtual int OnPollThreadError(int status);
+	virtual int PolledSocket();
+	virtual int Poll() ;
+	virtual void OnPollThreadStep();
+public:
+	void ClearList();
+private:
+	unsigned int GetCount();
+	bool AddSocket(SOCKET socket);
+        QMutex listmutex;
+	SOCKETLIST m_socketlist;
+};
+
 #endif // !defined(MULTICOMM_H)

Modified: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/tcpcomm.cpp
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/tcpcomm.cpp?rev=1022999&r1=1022998&r2=1022999&view=diff
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/tcpcomm.cpp (original)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/tcpcomm.cpp Fri
Oct 15 16:26:25 2010
@@ -15,74 +15,74 @@
 //specific language governing permissions and limitations
 //under the License. 
 
-// TCPComm.cpp: implementation of the CTCPComm class.
-//
-//////////////////////////////////////////////////////////////////////
-
-#include "stdafx.h"
-#include "asyncsocketex.h"
-#include "tcpcomm.h"
-#include "tcppollthread.h"
-
-//////////////////////////////////////////////////////////////////////
-// Construction/Destruction
-//////////////////////////////////////////////////////////////////////
-
-CTCPComm::CTCPComm()
-{
-
-	m_pThread = 0;
-}
-
-CTCPComm::~CTCPComm()
-{
-	Stop();
-
-}
-
-
-int CTCPComm::OnPollThreadError(int status)
-{
-	return -1;
-}
-
-bool CTCPComm::Init()
-{
-
-	if(m_pThread){
-		m_pThread->Stop();
-		return true;
-	}
-
-	m_pThread = new CTCPPollThread(this);
-
-	if(m_pThread)
-		return true;
-
-	return false;
-}
-
-int CTCPComm::Start()
-{
-	if(m_pThread == 0){
-		return -1;
-	}
-	return m_pThread->Start();
-}
-
-bool CTCPComm::IsPolling()
-{
-	if(m_pThread == 0){
-		return false;
-	}
-	return m_pThread->IsRunning();
-}
-
-
-void CTCPComm::Stop()
-{
-	if(m_pThread){
-		m_pThread->Stop();
-	}
-
+// TCPComm.cpp: implementation of the CTCPComm class.
+//
+//////////////////////////////////////////////////////////////////////
+
+#include "stdafx.h"
+#include "asyncsocketex.h"
+#include "tcpcomm.h"
+#include "tcppollthread.h"
+
+//////////////////////////////////////////////////////////////////////
+// Construction/Destruction
+//////////////////////////////////////////////////////////////////////
+
+CTCPComm::CTCPComm()
+{
+
+	m_pThread = 0;
+}
+
+CTCPComm::~CTCPComm()
+{
+	Stop();
+
+}
+
+
+int CTCPComm::OnPollThreadError(int status)
+{
+	return -1;
+}
+
+bool CTCPComm::Init()
+{
+
+	if(m_pThread){
+		m_pThread->Stop();
+		return true;
+	}
+
+	m_pThread = new CTCPPollThread(this);
+
+	if(m_pThread)
+		return true;
+
+	return false;
+}
+
+int CTCPComm::Start()
+{
+	if(m_pThread == 0){
+		return -1;
+	}
+	return m_pThread->Start();
+}
+
+bool CTCPComm::IsPolling()
+{
+	if(m_pThread == 0){
+		return false;
+	}
+        return m_pThread->isRunning();
+}
+
+
+void CTCPComm::Stop()
+{
+	if(m_pThread){
+		m_pThread->Stop();
+	}
+
 }

Modified: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/tcppollthread.cpp
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/tcppollthread.cpp?rev=1022999&r1=1022998&r2=1022999&view=diff
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/tcppollthread.cpp
(original)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/tcppollthread.cpp
Fri Oct 15 16:26:25 2010
@@ -18,7 +18,7 @@
 #include "tcpcomm.h"
 
 CTCPPollThread::CTCPPollThread(CTCPComm* pcomm)
-{
+{
 	m_pcomm = pcomm;
 	stop = false;
 }
@@ -30,68 +30,68 @@ CTCPPollThread::~CTCPPollThread()
  
 int CTCPPollThread::Start()
 {
-	if (JThread::IsRunning())
+        if (QThread::isRunning())
 		return -1;
 	
-	if (!stopmutex.IsInitialized())
-	{
-		if (stopmutex.Init() < 0)
-			return -1;
-	}
+    if (!stopmutex.tryLock())
+        {
+            return -1;
+        }
+       stopmutex.unlock();
 	stop = false;
-	if (JThread::Start() < 0)
-		return -1;
+       QThread::start(InheritPriority);
+
 	return 0;
 }
 
 void CTCPPollThread::Stop()
 {	
-	if (!IsRunning())
+        if (!isRunning())
 		return;
 	
-	stopmutex.Lock();
-	stop = true;
-	stopmutex.Unlock();
+        stopmutex.lock();
+        stop = true;
+        stopmutex.unlock();
 	
 	
-	if (JThread::IsRunning())
+        if (QThread::isRunning())
 	{
-		JThread::Kill();
-	}
+            this->terminate();
+        }
 	stop = false;
 }
 
-void *CTCPPollThread::Thread()
+void CTCPPollThread::run()
 {
-	JThread::ThreadStarted();
-	
-	int status;
-	bool stopthread;
-
-	stopmutex.Lock();
-	stopthread = stop;
-	stopmutex.Unlock();
-	while (!stopthread)
-	{
-
-		status = m_pcomm->Poll();
-		if(status < 0 ){
-			stopthread = 0;
-			m_pcomm->OnPollThreadError(status);
-		}
-		else{
-			status = m_pcomm->PolledSocket();
-			if(status < 0){
-				stopthread = true;
-				m_pcomm->OnPollThreadError(status);
-			}
-			else{
-				m_pcomm->OnPollThreadStep();
-				stopmutex.Lock();
-				stopthread = stop;
-				stopmutex.Unlock();
-			}
-		}
-	}
-	return 0;
+    QThread::started();
+
+    int status;
+    bool stopthread;
+
+    stopmutex.lock();
+     stopthread = stop;
+     stopmutex.unlock();
+    while (!stopthread)
+    {
+
+            status = m_pcomm->Poll();
+            if(status < 0 ){
+                    stopthread = 0;
+                    m_pcomm->OnPollThreadError(status);
+            }
+            else{
+                    status = m_pcomm->PolledSocket();
+                    if(status < 0){
+                            stopthread = true;
+                            m_pcomm->OnPollThreadError(status);
+                    }
+                    else{
+                            m_pcomm->OnPollThreadStep();
+                            stopmutex.lock();
+                             stopthread = stop;
+                             stopmutex.unlock();
+                    }
+            }
+    }
 }
+

Modified: incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/tcppollthread.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/tcppollthread.h?rev=1022999&r1=1022998&r2=1022999&view=diff
==============================================================================
--- incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/tcppollthread.h
(original)
+++ incubator/bluesky/branches/apache-bluesky-realclass0.2.0/TserverQT-0.2.0/tcppollthread.h
Fri Oct 15 16:26:25 2010
@@ -21,11 +21,11 @@
 
 
 
-#include "jthread.h"
-#include "jmutex.h"
+#include <QMutex>
+#include <QThread>
 
 class CTCPComm;
-class CTCPPollThread : private JThread
+class CTCPPollThread : private QThread
 {
 	friend class CTCPComm;
 public:
@@ -33,11 +33,12 @@ public:
 	~CTCPPollThread();
 	int Start();
 	void Stop();
+        void run();
 private:
-	void *Thread();
+//	void *Thread();
 	
 	bool stop;
-	JMutex stopmutex;
+        QMutex stopmutex;
 	CTCPComm *m_pcomm;
 };
 



Mime
View raw message