You are viewing a plain text version of this content. The canonical link for it is here.
Posted to bluesky-commits@incubator.apache.org by pi...@apache.org on 2009/11/30 12:01:26 UTC
svn commit: r885392 [21/25] - in /incubator/bluesky/trunk/RealClass:
Student/src/ Teacher/ Teacher/autom4te.cache/ Teacher/src/
Teacher/src/.deps/ Teacher/src/pic/
Added: incubator/bluesky/trunk/RealClass/Teacher/src/asyncsocketex.cpp
URL: http://svn.apache.org/viewvc/incubator/bluesky/trunk/RealClass/Teacher/src/asyncsocketex.cpp?rev=885392&view=auto
==============================================================================
--- incubator/bluesky/trunk/RealClass/Teacher/src/asyncsocketex.cpp (added)
+++ incubator/bluesky/trunk/RealClass/Teacher/src/asyncsocketex.cpp Mon Nov 30 12:01:23 2009
@@ -0,0 +1,20 @@
+/** \file asyncsocketex.cpp imitation of asyncsocketex under windows platform
+ * warp of socket communication.
+*
+*Licensed to the Apache Software Foundation (ASF) under one
+*or more contributor license agreements. See the NOTICE file
+*distributed with this work for additional information
+*regarding copyright ownership. The ASF licenses this file
+*to you under the Apache License, Version 2.0 (the
+*"License"); you may not use this file except in compliance
+*with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+*Unless required by applicable law or agreed to in writing,
+*software distributed under the License is distributed on an
+*"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+*KIND, either express or implied. See the License for the
+*specific language governing permissions and limitations
+*under the License.
+*/
#include "stdafx.h"
#include "asyncsocketex.h"
CAsyncSocketEx::CAsyncSocketEx()
{
m_SocketData.hSocket = INVALID_SOCKET;
m_SocketData.nSocketIndex = -1;
m_lEvent = 0;
}
CAsyncSocketEx::~CAsyncSocketEx()
{
Close();
}
bool CAsyncSocketEx::Create(UINT nSocketPort /*=0*/,
int nSocketType /*=SOCK_STREAM*/, LPCTSTR lpszSocketAddress /*=NULL*/)
{
SOCKET hSocket = socket(AF_INET, nSocketType, 0);
if (hSocket == INVALID_SOCKET)
return false;
m_SocketData.hSocket = hSocket;
if (!Bind(nSocketPort, lpszSocketAddress))
{
Close();
return false;
}
return true;
}
bool CAsyncSocketEx::Bind(UINT nSocketPort, LPCTSTR lpszSocketAddress)
{
SOCKADDR_IN sockAddr;
memset(&sockAddr, 0, sizeof(sockAddr));
LPSTR lpszAscii = (LPSTR) lpszSocketAddress;
sockAddr.sin_family = AF_INET;
if (lpszAscii == NULL)
sockAddr.sin_addr.s_addr = htonl(INADDR_ANY);
else
{
DWORD lResult = inet_addr(lpszAscii);
if (lResult == INADDR_NONE)
{
return false;
}
sockAddr.sin
_addr.s_addr = lResult;
}
sockAddr.sin_port = htons((u_short) nSocketPort);
return Bind((SOCKADDR*) &sockAddr, sizeof(sockAddr));
}
bool CAsyncSocketEx::Bind(const SOCKADDR* lpSockAddr, int nSockAddrLen)
{
if (!bind(m_SocketData.hSocket, lpSockAddr, nSockAddrLen))
return true;
else
return false;
}
void CAsyncSocketEx::Close()
{
if (m_SocketData.hSocket != INVALID_SOCKET)
{
if (close(m_SocketData.hSocket) == SOCKET_ERROR)
{
printf("\nclose socket error.");
return;
}
m_SocketData.hSocket = INVALID_SOCKET;
m_lEvent = 0;
}
}
bool CAsyncSocketEx::GetSockOpt(int nOptionName, void* lpOptionValue,
int* lpOptionLen, int nLevel /* = SOL_SOCKET*/)
{
int status;
if (m_SocketData.hSocket == 0)
return false;
status = getsockopt(m_SocketData.hSocket, nLevel, nOptionName,
lpOptionValue, (socklen_t*) lpOptionLen);
if (status != 0)
return false;
return true;
}
bool CAsyncSocketEx::SetSockOpt(int nOptionName, const void* lpOptionValue,
int nO
ptionLen, int nLevel /* = SOL_SOCKET*/)
{
int status;
if (m_SocketData.hSocket == 0)
return false;
status = setsockopt(m_SocketData.hSocket, nLevel, nOptionName,
lpOptionValue, nOptionLen);
if (status != 0)
return false;
return true;
}
int CAsyncSocketEx::Receive(void* lpBuf, int nBufLen, int nFlags /*=0*/)
{
return recv(m_SocketData.hSocket, (LPSTR) lpBuf, nBufLen, nFlags);
}
int CAsyncSocketEx::Send(const void* lpBuf, int nBufLen, int nFlags /*=0*/)
{
return send(m_SocketData.hSocket, (LPSTR) lpBuf, nBufLen, nFlags);
}
bool CAsyncSocketEx::Connect(LPCTSTR lpszHostAddress, UINT nHostPort)
{
SOCKADDR_IN sockAddr;
memset(&sockAddr, 0, sizeof(sockAddr));
LPSTR lpszAscii = (LPSTR) lpszHostAddress;
sockAddr.sin_family = AF_INET;
sockAddr.sin_addr.s_addr = inet_addr(lpszAscii);
sockAddr.sin_port = htons((u_short) nHostPort);
return CAsyncSocketEx::Connect((SOCKADDR*) &sockAddr, sizeof(sockAddr));
}
bool CAsyncSocketEx::Connect(const SOCKADDR* lpSock
Addr, int nSockAddrLen)
{
if (m_SocketData.hSocket == INVALID_SOCKET)
return false;
return SOCKET_ERROR != connect(m_SocketData.hSocket, lpSockAddr,
nSockAddrLen);
}
bool CAsyncSocketEx::GetPeerName(SOCKADDR* lpSockAddr, int* lpSockAddrLen)
{
if (!getpeername(m_SocketData.hSocket, lpSockAddr,
(socklen_t*) lpSockAddrLen))
return true;
else
return false;
}
bool CAsyncSocketEx::GetSockName(SOCKADDR* lpSockAddr, int* lpSockAddrLen)
{
if (!getsockname(m_SocketData.hSocket, lpSockAddr,
(socklen_t*) lpSockAddrLen))
return true;
else
return false;
}
bool CAsyncSocketEx::ShutDown(int nHow /*=sends*/)
{
if (!shutdown(m_SocketData.hSocket, nHow))
return true;
else
return false;
}
SOCKET CAsyncSocketEx::Detach()
{
SOCKET socket = m_SocketData.hSocket;
m_SocketData.hSocket = INVALID_SOCKET;
m_lEvent = 0;
return socket;
}
bool CAsyncSocketEx::Attach(SOCKET hSocket, long lEvent /* = 0 */)
{
if (hSocket == INVALID_SOCKET || !hSocket)
return false;
m_SocketData.hSocket = hSocket;
m_lEvent = lEvent;
return true;
}
bool CAsyncSocketEx::Listen(int nConnectionBacklog /*=5*/)
{
if (!listen(m_SocketData.hSocket, nConnectionBacklog))
return true;
else
return false;
}
bool CAsyncSocketEx::Accept(CAsyncSocketEx& rConnectedSocket,
SOCKADDR* lpSockAddr /*=NULL*/, int* lpSockAddrLen /*=NULL*/)
{
SOCKET hTemp = accept(m_SocketData.hSocket, lpSockAddr,
(socklen_t*) lpSockAddrLen);
if (hTemp == INVALID_SOCKET)
return false;
rConnectedSocket.m_SocketData.hSocket = hTemp;
return true;
}
bool CAsyncSocketEx::IOCtl(long lCommand, DWORD* lpArgument)
{
if (!ioctl(m_SocketData.hSocket, lCommand, lpArgument))
return false;
else
return true;
}
int CAsyncSocketEx::GetLastError()
{
return -1;
}
SOCKET CAsyncSocketEx::GetSocketHandle()
{
return m_SocketData.hSocket;
}
int CAsyncSocketEx::Poll()
{
fd_set fdsetread;
struct timeval tv;
FD_ZERO(&fdsetread);
FD_SET(m_SocketData.hSocket, &fdsetread);
tv.tv_se
c = 0;
tv.tv_usec = 10000;
if (select(FD_SETSIZE, &fdsetread, 0, 0, &tv) < 0)
{
m_lEvent = -1;
return m_lEvent;
}
m_lEvent = 0;
if (FD_ISSET(m_SocketData.hSocket, &fdsetread))
{
m_lEvent = 1;
}
return m_lEvent;
}
void CAsyncSocketEx::OnEvent()
{
return;
}
Added: incubator/bluesky/trunk/RealClass/Teacher/src/asyncsocketex.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/trunk/RealClass/Teacher/src/asyncsocketex.h?rev=885392&view=auto
==============================================================================
--- incubator/bluesky/trunk/RealClass/Teacher/src/asyncsocketex.h (added)
+++ incubator/bluesky/trunk/RealClass/Teacher/src/asyncsocketex.h Mon Nov 30 12:01:23 2009
@@ -0,0 +1,159 @@
+/** \file asyncsocketex.h imitate CAsyncSocket under windows platform
+ *
+*Licensed to the Apache Software Foundation (ASF) under one
+*or more contributor license agreements. See the NOTICE file
+*distributed with this work for additional information
+*regarding copyright ownership. The ASF licenses this file
+*to you under the Apache License, Version 2.0 (the
+*"License"); you may not use this file except in compliance
+*with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+*Unless required by applicable law or agreed to in writing,
+*software distributed under the License is distributed on an
+*"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+*KIND, either express or implied. See the License for the
+*specific language governing permissions and limitations
+*under the License.
+*/
+
+#include "stdafx.h"
+#if !defined(ASYNCSOCKETEX_H)
+#define ASYNCSOCKETEX_H
+//! Socket communication
+class CAsyncSocketEx
+{
+
+public:
+ //!Constructor
+ CAsyncSocketEx();
+ //!Destructor
+ virtual ~CAsyncSocketEx();
+
+ /** create socket
+ * \param nSocketPort port of socket
+ * \param nSocketType socket type
+ * \param socket address string
+ */
+ bool Create(UINT nSocketPort = 0, int nSocketType = SOCK_STREAM,
+ LPCTSTR lpszSocketAddress = NULL);
+ //!Get Socket Handle
+ SOCKET GetSocketHandle();
+ //!Get the status
+ inline long GetStatus()
+ {
+ return m_lEvent;
+ }
+ ;
+ //!Set the status
+ inline void SetStatus(long lEvent)
+ {
+ m_lEvent = lEvent;
+ }
+ ;
+ //!Attaches a socket handle to a CAsyncSocket object
+ /*!
+ \param hSocket the socket
+ \param lEvent the status
+ */
+ bool Attach(SOCKET hSocket, long lEvent = 0);
+
+ //!Detaches a socket handle from a CAsyncSocket object
+ SOCKET Detach();
+
+ //!Gets the error status for the last operation that failed.
+ static int GetLastError();
+
+ virtual int Poll();
+
+ //!Gets the address of the peer socket to which the socket is connected
+ /*!
+ \param lpSockAddr SOCKADDR struct
+ \param lpSockAddrLen length of SOCKADDR struct
+ */
+ bool GetPeerName(SOCKADDR* lpSockAddr, int* lpSockAddrLen);
+
+ //!Gets the local name for a socket
+ /*!
+ \param lpSockAddr SOCKADDR struct
+ \param lpSockAddrLen length of SOCKADDR struct
+ */
+ bool GetSockName(SOCKADDR* lpSockAddr, int* lpSockAddrLen);
+
+ //!Retrieves a socket option
+ /*!
+ \param nOptionName the socket option name
+ \param lpOptionValue the socket option value
+ \param nLevel SOL_SOCKET
+ */
+ bool GetSockOpt(int nOptionName, void* lpOptionValue, int* lpOptionLen,
+ int nLevel = SOL_SOCKET);
+
+ //!Sets a socket option
+ /*!
+ \param nOptionName the socket option name
+ \param lpOptionValue the socket option value
+ \param nLevel SOL_SOCKET
+ */
+ bool SetSockOpt(int nOptionName, const void* lpOptionValue, int nOptionLen,
+ int nLevel = SOL_SOCKET);
+ //!close the socket
+ virtual void Close();
+ /** bind socket to certain port
+ * \param nSocketPort port which is about to bind
+ * \param lpszSocketAddress ip address about to bind
+ */
+ bool Bind(UINT nSocketPort, LPCTSTR lpszSocketAddress);
+ /** overload of Bind() use SOCKADDR struct to bind
+ * \param *lpSockAddr SOCKADDR type
+ * \param nSockAddrLen size of SOCKADDR struct
+ */
+ bool Bind(const SOCKADDR* lpSockAddr, int nSockAddrLen);
+ //!connect the socket: port and LPCTSTR address
+ virtual bool Connect(LPCTSTR lpszHostAddress, UINT nHostPort);
+ //!connect the socket: SOCKADDR address and length
+ virtual bool Connect(const SOCKADDR* lpSockAddr, int nSockAddrLen);
+ //!listen to hSocket accept nConnectionBacklog simultaneously
+ /*
+ \param nConnectionBacklog max connection at the same time
+ */
+ bool Listen(int nConnectionBacklog = 5);
+ /**accept a new connection on a socket
+ * \param rConnectedSocket connected socket
+ * \param * lpSockAddr SOCKADDR struct
+ * \param * lpSockAddrLen length of SOCKADDR struct
+ */
+ virtual bool Accept(CAsyncSocketEx& rConnectedSocket, SOCKADDR* lpSockAddr =
+ NULL, int* lpSockAddrLen = NULL);
+ //!address transform
+ bool IOCtl(long lCommand, DWORD* lpArgument);
+ //!ShutDown connection
+ bool ShutDown(int nHow = sends);
+ //!receive data
+ virtual int Receive(void* lpBuf, int nBufLen, int nFlags = 0);
+ //!send data
+ virtual int Send(const void* lpBuf, int nBufLen, int nFlags = 0);
+ /** virtual function OnEvent(): wait signal to trigger event
+ *
+ */
+ virtual void OnEvent();
+
+ enum
+ {
+ receives = 0, sends = 1, both = 2
+ };
+
+
+protected:
+ struct t_AsyncSocketExData
+ {
+ SOCKET hSocket;
+ int nSocketIndex;
+ } m_SocketData;
+
+ long m_lEvent;
+
+};
+
+#endif // !defined(ASYNCSOCKETEX_H)
Added: incubator/bluesky/trunk/RealClass/Teacher/src/callbacks.cc
URL: http://svn.apache.org/viewvc/incubator/bluesky/trunk/RealClass/Teacher/src/callbacks.cc?rev=885392&view=auto
==============================================================================
--- incubator/bluesky/trunk/RealClass/Teacher/src/callbacks.cc (added)
+++ incubator/bluesky/trunk/RealClass/Teacher/src/callbacks.cc Mon Nov 30 12:01:23 2009
@@ -0,0 +1,1365 @@
+/** \file callbacks.cc implementation for GUI operations
+*
+*
+*Licensed to the Apache Software Foundation (ASF) under one
+*or more contributor license agreements. See the NOTICE file
+*distributed with this work for additional information
+*regarding copyright ownership. The ASF licenses this file
+*to you under the Apache License, Version 2.0 (the
+*"License"); you may not use this file except in compliance
+*with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+*Unless required by applicable law or agreed to in writing,
+*software distributed under the License is distributed on an
+*"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+*KIND, either express or implied. See the License for the
+*specific language governing permissions and limitations
+*under the License.
+*/
+
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <gtk/gtk.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <stdio.h>
+#include <sys/un.h>
+#include <unistd.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include "client_communicate.h"
+#include <iostream>
+#include "callbacks.hh"
+#include "interface.hh"
+#include "support.hh"
+#include "stdafx.h"
+#include "trcclient.hh"
+#include "languagechoose.h"
+#include "en_de_audio.h"
+#include "en_de_video.h"
+#include "en_de_screen.h"
+#include "errorinfo.h"
+#include <gdk/gdkx.h>
+
+extern CVideoReceiver g_studet_videoreceiver;
+extern CAudioReceiver g_student_audioreceiver;
+
+extern CAudioSender g_teacher_audiosender;
+extern CV4LVideoSender g_teacher_v4lvideosender;
+extern CScreenSender g_teacher_screensender;
+
+extern entry_setpara ncteacher_get_para;
+extern entry_usepara ncteacher_get_user;
+
+extern int g_work_mode;
+extern int g_video_mode;
+extern struct CRCLTeacherLogin teachlogin;
+extern client_ts_communicate client_comm;
+
+extern GtkWidget *creatclass;
+extern GtkWidget *stopclass;
+extern GtkWidget *set_item;
+extern GtkWidget *login;
+extern GtkWidget *exitsys;
+
+extern GtkWidget *file_entry;
+extern GtkWidget *view_file_button;
+
+extern GtkWidget *modetech;
+extern GtkWidget *modecomu;
+extern GtkWidget *set_toolbutton;
+extern GtkWidget *join_toolbutton;
+extern GtkWidget *exit_toolbutton;
+extern GtkWidget *creat_toolbutton;
+extern GtkWidget *cancel_toolbutton;
+extern GtkWidget *tech_toolbutton;
+extern GtkWidget *commu_toolbutton;
+extern GtkWidget *allow_chat_toolbutton;
+extern GtkWidget *rec_toolbutton;
+extern GtkWidget *videoEntry;
+extern GtkWidget *audioEntry;
+extern GtkWidget *student_clist;
+extern GtkWidget *enserverport;
+extern GtkWidget *concentrate_add_button;
+extern GtkWidget *concentrate_concel_button;
+extern GtkWidget *student_list_label;
+extern GtkTextBuffer *commu_buffer;
+extern GtkTextIter commu_end;
+extern GtkTextIter commu_start;
+extern GtkWidget *studentimage;
+extern GtkWidget *teacherimage;
+extern GtkWidget *rec_delay_set_dialog;
+extern GtkWidget *chat_entry;
+extern GtkWidget *chat_button;
+extern GtkAdjustment *adj;
+extern GtkWidget *commu_textview;
+
+extern GtkWidget *review_image;
+extern GtkWidget *combobox4;
+extern GtkWidget *combobox5;
+
+extern int g_VideoDevCount;
+extern char g_DevName[10][32];
+extern int student_list_num;
+extern CRCLCreateGroup CreateGroup;
+
+gfloat upper1, page_size1, value, step;
+
+int allow_chat_set = 0;//0: stop chat;1: allow chat
+
+int is_focus_set = 0; //0: haven't set concentrate 1:set already
+
+int record_courseware_set = 0; // 0:record 1:stop record
+
+
+int clist_focusid;
+int class_state;
+
+int g_temp_video_mode = 1; // 1:video
+int g_temp_work_mode = 0; //0: teach 1:record
+int dev_num_temp = 0;
+extern int v4l_dev_num;
+int check_viewbutton = 0;
+extern int delay_time;
+extern CRCLCreateGroup CreateGroup;
+
+int error_info_no = 0;
+gboolean ncteacher_timer_callback(void *para)
+{
+
+ client_ts_communicate::studentlist_mutex.Lock();
+
+ char listpre[100];
+ char listnow[10];
+ memset(listpre, 0, sizeof(listpre));
+ memset(listnow, 0, sizeof(listnow));
+ sprintf(listnow, "%d", GTK_CLIST(student_clist)->rows);
+
+ strcpy(listpre, plistpre);
+ strcat(listpre, "(");
+ strcat(listpre, listnow);
+ strcat(listpre, pnumb);
+
+ gtk_label_set_text(GTK_LABEL(student_list_label), listpre);
+
+ client_ts_communicate::studentlist_mutex.Unlock();
+
+ switch (error_info_no)
+ {
+ case 0:
+ return true;
+
+ case 3:
+ Error_dia(ERROR003, ERROR_S003);
+ error_info_no = 0;
+ break;
+
+ case 5:
+ Error_dia(ERROR005, ERROR_S005);
+ error_info_no = 0;
+ break;
+
+ case 10:
+ Error_dia(ERROR010, ERROR_S010);
+ error_info_no = 0;
+ break;
+
+ case 12:
+ Error_dia(ERROR012, ERROR_S012);
+ error_info_no = 0;
+ break;
+ case 19:
+ Error_dia(ERROR019, ERROR_S019);
+ error_info_no = 0;
+ break;
+ case 20:
+ Error_dia(ERROR020, ERROR_S020);
+ error_info_no = 0;
+ break;
+
+ case 40:
+
+ upper1 = GTK_ADJUSTMENT(adj)->upper;
+ page_size1 = GTK_ADJUSTMENT(adj)->page_size;
+ value = upper1 - page_size1;
+ gtk_adjustment_set_value(GTK_ADJUSTMENT(adj), value);
+ error_info_no = 0;
+
+ break;
+
+ default:
+
+ break;
+ }
+ return true;
+}
+
+void save_setpara_to_file()
+{
+ FILE *fp;
+ entry_setpara *save_setpara;
+ if ((fp = fopen("ncteacher_setpara.conf", "wt+")) == NULL)
+ {
+ printf("Error:can't open parameter file!\n");
+ return;
+ }
+
+ save_setpara = &ncteacher_get_para;
+ fwrite(save_setpara, sizeof(struct entry_setpara), 1, fp);
+ fclose(fp);
+}
+
+void save_userpara_to_file()
+{
+ FILE *fp;
+
+ entry_usepara *save_usepara;
+ if ((fp = fopen("ncteacher_userpara.conf", "wt+")) == NULL)
+ {
+ printf("Error:can't open user parameter file!\n");
+ return;
+ }
+
+ save_usepara = &ncteacher_get_user;
+ fwrite(save_usepara, sizeof(struct entry_usepara), 1, fp);
+ fclose(fp);
+}
+//!get clients' clist
+int get_client_clist()
+{
+ CRCLMSG send_mes;
+ CRCLTeacherGetClientList TeacherGetClientList;
+
+ TeacherGetClientList.TeacherID = client_comm.TeacherID;
+ TeacherGetClientList.RoomID = client_comm.GroupID;
+
+ send_mes.rclType = 1070;
+ send_mes.msglen = sizeof(TeacherGetClientList);
+ memcpy(send_mes.msg, &TeacherGetClientList, sizeof(TeacherGetClientList));
+
+ if (client_comm.send_mes(send_mes, send_mes.msglen + 8) < 0)
+ {
+ Error_dia(ERROR007, ERROR_S007);
+ perror("send get client list failed!");
+ return -1;
+ }
+ return 0;
+}
+
+void on_login_activate(GtkMenuItem *menuitem, gpointer user_data)
+{
+ GtkWidget *dialog2;
+ dialog2 = create_login_dialog();
+ gtk_widget_show(dialog2);
+
+}
+
+void on_exitsys_activate(GtkMenuItem *menuitem, gpointer user_data)
+{
+ CRCLMSG send_mes;
+ CRCLTeacherLogout Teacher_logout;
+
+ Teacher_logout.TeacherID = client_comm.TeacherID;
+
+ send_mes.rclType = 5030;
+ send_mes.msglen = sizeof(Teacher_logout);
+ memcpy(send_mes.msg, &Teacher_logout, sizeof(Teacher_logout));
+
+ if (client_comm.send_mes(send_mes, send_mes.msglen + 8) < 0)
+ {
+ perror("send logout message failed!");
+ }
+
+ client_comm.close_socket(2);
+
+ switch (g_video_mode)
+ {
+ case 1:
+ g_teacher_v4lvideosender.CloseXImage();
+ g_teacher_v4lvideosender.Stop();
+ g_teacher_v4lvideosender.ClearDestinations();
+ break;
+ }
+
+ g_teacher_screensender.Stop();
+ g_student_audioreceiver.Stop();
+ gtk_main_quit();
+}
+
+void on_modecomu_activate(GtkMenuItem *menuitem, gpointer user_data)
+{
+ CRCLMSG send_mes;
+
+ CRCLTeacherSwitchMode mode_change;
+
+ mode_change.GroupID = client_comm.GroupID;
+ mode_change.ModeType = 0;
+ class_state = 0;//communicate
+ send_mes.rclType = 1080;
+ send_mes.msglen = sizeof(mode_change);
+ memcpy(send_mes.msg, &mode_change, sizeof(mode_change));
+
+ if (client_comm.send_mes(send_mes, send_mes.msglen + 8) < 0)
+ {
+ Error_dia(ERROR008, ERROR_S008);
+ perror("send swith to communicate mode message failed!");
+ return;
+ }
+
+ gtk_widget_set_sensitive(modetech, TRUE);
+ gtk_widget_set_sensitive(tech_toolbutton, TRUE);
+
+ gtk_widget_set_sensitive(modecomu, FALSE);
+ gtk_widget_set_sensitive(commu_toolbutton, FALSE);
+ if (allow_chat_set == 1)
+ gtk_tool_button_set_label((GtkToolButton*) allow_chat_toolbutton,
+ pmodeswich);
+ gtk_widget_set_sensitive(allow_chat_toolbutton, FALSE);
+ g_teacher_screensender.Stop();
+ g_teacher_screensender.Record(false);
+
+ switch (g_video_mode)
+ {
+ case 1:
+ g_teacher_v4lvideosender.Record(false);
+ break;
+ }
+ g_teacher_audiosender.Record(false);
+
+ switch (g_video_mode)
+ {
+ case 1:
+ g_teacher_v4lvideosender.CreateXImage(GDK_WINDOW_XID(
+ studentimage->window), 510, 75 + 225, 320, 220);
+ break;
+ }
+
+ if (!g_studet_videoreceiver.Init())
+ exit(1);
+
+ g_studet_videoreceiver.CreateXImage(GDK_WINDOW_XID(studentimage->window),
+ 510, 75, 320, 220);
+
+ printf("CreateGroup.CVPort is %d \n", CreateGroup.CVPort);
+
+ if (g_studet_videoreceiver.Start(CreateGroup.CVPort) < 0)
+ exit(2);
+
+ if (!g_student_audioreceiver.Init())
+ exit(1);
+
+ if (g_student_audioreceiver.Start(CreateGroup.CAPort) < 0)
+ exit(2);
+
+}
+
+void on_creatclass_activate(GtkMenuItem *menuitem, gpointer user_data)
+{
+ GtkWidget *class_dialog1;
+ class_dialog1 = creat_class_dialog();
+ gtk_widget_show(class_dialog1);
+}
+
+void on_stopclass_activate(GtkMenuItem *menuitem, gpointer user_data)
+{
+ CRCLMSG send_mes;
+
+ TRCDestoryGroup DestoryGroup;
+ send_mes.rclType = 10010;
+ DestoryGroup.TeacherID = client_comm.TeacherID;
+ DestoryGroup.GroupID = client_comm.GroupID;
+
+ send_mes.msglen = sizeof(DestoryGroup);
+ memcpy(send_mes.msg, &DestoryGroup, sizeof(DestoryGroup));
+ if (client_comm.send_mes(send_mes, send_mes.msglen + 8) < 0)
+ {
+ Error_dia(ERROR006, ERROR_S006);
+ perror("send failed!");
+ return;
+ }
+
+ client_ts_communicate::studentlist_mutex.Lock();
+ gtk_clist_freeze(GTK_CLIST(student_clist));
+ gtk_clist_clear(GTK_CLIST(student_clist));
+ gtk_clist_thaw(GTK_CLIST(student_clist));
+ client_ts_communicate::studentlist_mutex.Unlock();
+
+ g_student_audioreceiver.Stop();
+
+ g_studet_videoreceiver.CloseXImage();
+ g_studet_videoreceiver.Stop();
+
+ switch (g_video_mode)
+ {
+ case 1:
+ g_teacher_v4lvideosender.CloseXImage();
+ g_teacher_v4lvideosender.Stop();
+ g_teacher_v4lvideosender.ClearDestinations();
+ break;
+ }
+ g_teacher_audiosender.Pause();
+ g_teacher_screensender.Stop();
+
+ is_focus_set = 0;
+
+ gtk_widget_set_sensitive(creatclass, TRUE);
+ gtk_widget_set_sensitive(creat_toolbutton, TRUE);
+
+ gtk_widget_set_sensitive(stopclass, FALSE);
+ gtk_widget_set_sensitive(cancel_toolbutton, FALSE);
+
+ gtk_widget_set_sensitive(modetech, FALSE);
+ gtk_widget_set_sensitive(tech_toolbutton, FALSE);
+
+ gtk_widget_set_sensitive(modecomu, FALSE);
+ gtk_widget_set_sensitive(commu_toolbutton, FALSE);
+
+ gtk_widget_set_sensitive(chat_button, FALSE);
+ if (allow_chat_set == 1)
+ gtk_tool_button_set_label((GtkToolButton*) allow_chat_toolbutton,
+ pmodeswich);
+ gtk_widget_set_sensitive(allow_chat_toolbutton, FALSE);
+}
+
+void on_modetech_activate(GtkMenuItem *menuitem, gpointer user_data)
+{
+ CRCLMSG send_mes;
+
+ CRCLTeacherSwitchMode mode_change;
+
+ mode_change.GroupID = client_comm.GroupID;
+ mode_change.ModeType = 1;
+ class_state = 1;//teach
+ send_mes.rclType = 1080;
+ send_mes.msglen = sizeof(mode_change);
+ memcpy(send_mes.msg, &mode_change, sizeof(mode_change));
+
+ if (client_comm.send_mes(send_mes, send_mes.msglen + 8) < 0)
+ {
+ Error_dia(ERROR008, ERROR_S008);
+ perror("send swith to teach mode message failed!");
+ return;
+ }
+
+ gtk_widget_set_sensitive(modetech, FALSE);
+ gtk_widget_set_sensitive(tech_toolbutton, FALSE);
+
+ gtk_widget_set_sensitive(modecomu, TRUE);
+ gtk_widget_set_sensitive(commu_toolbutton, TRUE);
+ gtk_widget_set_sensitive(allow_chat_toolbutton, TRUE);
+
+ g_teacher_screensender.Start();
+
+ g_studet_videoreceiver.CloseXImage();
+ g_studet_videoreceiver.Stop();
+
+ g_student_audioreceiver.Stop();
+
+ switch (g_video_mode)
+ {
+ case 1:
+ g_teacher_v4lvideosender.CloseXImage();
+ break;
+ }
+
+}
+
+void on_set_activate(GtkMenuItem *menuitem, gpointer user_data)
+{
+ GtkWidget *para_dialog;
+ para_dialog = create_para_dialog();
+ gtk_widget_show(para_dialog);
+
+}
+
+void on_stuimg_activate(GtkMenuItem *menuitem, gpointer user_data)
+{
+
+}
+
+void on_techimg_activate(GtkMenuItem *menuitem, gpointer user_data)
+{
+
+}
+
+void on_networkokbutton_clicked(GtkButton *button, gpointer netdialog)
+{
+
+ get_networkconfig();
+ if (get_classpara() < 0)
+ return;
+ gtk_widget_set_sensitive(login, TRUE);
+ gtk_widget_set_sensitive(join_toolbutton, TRUE);
+
+ save_setpara_to_file();
+ gtk_widget_destroy(GTK_WIDGET(netdialog));
+
+}
+
+void on_networkcancelbutton_clicked(GtkObject *object, gpointer user_data)
+{
+ gtk_widget_destroy(GTK_WIDGET(user_data));
+}
+
+void on_loginokbutton_clicked(GtkButton *button, gpointer user_data)
+{
+
+ DWORD Dcenterport;
+ Dcenterport = ncteacher_get_para.serverport;
+ if (get_loadsys() < 0)
+ return;
+
+ LPCTSTR ts_addr = ncteacher_get_para.serverip;
+
+ UINT ts_port = Dcenterport;
+ if (client_comm.establish_connect(ts_addr, ts_port) < 0)
+ {
+ Error_dia(ERROR001, ERROR_S001);
+ return;
+ }
+
+ CRCLMSG send_mes;
+
+ send_mes.rclType = 5000;
+ send_mes.msglen = sizeof(teachlogin);
+ memcpy(send_mes.msg, &teachlogin, sizeof(teachlogin));
+
+ if (client_comm.send_mes(send_mes, send_mes.msglen + 8) < 0)
+ {
+ perror("send failed!");
+ Error_dia(ERROR002, ERROR_S002);
+ return;
+ }
+
+ gtk_widget_set_sensitive(creatclass, TRUE);
+ gtk_widget_set_sensitive(creat_toolbutton, TRUE);
+
+ gtk_widget_set_sensitive(exitsys, TRUE);
+ gtk_widget_set_sensitive(exit_toolbutton, TRUE);
+
+ gtk_widget_set_sensitive(login, FALSE);
+ gtk_widget_set_sensitive(join_toolbutton, FALSE);
+ save_userpara_to_file();
+ gtk_widget_destroy(GTK_WIDGET(user_data));
+
+}
+
+void on_login_cancelbutton_destroy(GtkObject *object, gpointer user_data)
+{
+ gtk_widget_destroy(GTK_WIDGET(user_data));
+}
+
+void on_creat_cancelbut_clicked(GtkButton *button, gpointer user_data)
+{
+ gtk_widget_destroy(GTK_WIDGET(user_data));
+}
+
+void on_creat_okbutton_clicked(GtkButton *button, gpointer user_data)
+{
+
+ CRCLMSG send_mes;
+
+ if (get_classname() < 0)
+ return;
+
+ send_mes.rclType = 10000;
+ CreateGroup.TeacherID = client_comm.TeacherID;
+
+ send_mes.msglen = sizeof(CreateGroup);
+ memcpy(send_mes.msg, &CreateGroup, sizeof(CreateGroup));
+ if (client_comm.send_mes(send_mes, send_mes.msglen + 8) < 0)
+ {
+ Error_dia(ERROR004, ERROR_S004);
+ perror("send creat class message failed!");
+ return;
+ }
+ class_state = 1;
+ gtk_widget_destroy(GTK_WIDGET(user_data));
+
+}
+
+void on_set_toolbutton_clicked(GtkToolButton *toolbutton, gpointer user_data)
+{
+ GtkWidget *para_dialog;
+ para_dialog = create_para_dialog();
+ gtk_widget_show(para_dialog);
+
+}
+
+void on_join_toolbutton_clicked(GtkToolButton *toolbutton, gpointer user_data)
+{
+ GtkWidget *dialog2;
+ dialog2 = create_login_dialog();
+ gtk_widget_show(dialog2);
+}
+
+void on_exit_toolbutton_clicked(GtkToolButton *toolbutton, gpointer user_data)
+{
+ GtkWidget *dialog5;
+ dialog5 = create_exit_system_dialog();
+ gtk_widget_show(dialog5);
+}
+
+void on_creat_toolbutton_clicked(GtkToolButton *toolbutton, gpointer user_data)
+{
+
+ GtkWidget *class_dialog1;
+ class_dialog1 = creat_class_dialog();
+ gtk_widget_show(class_dialog1);
+
+}
+
+void on_cancel_toolbutton_clicked(GtkToolButton *toolbutton, gpointer user_data)
+{
+ GtkWidget *dialog4;
+ dialog4 = create_cancle_class_dialog();
+ gtk_widget_show(dialog4);
+
+}
+
+void on_tech_toolbutton_clicked(GtkToolButton *toolbutton, gpointer user_data)
+{
+ CRCLMSG send_mes;
+
+ CRCLTeacherSwitchMode mode_change;
+
+ mode_change.GroupID = client_comm.GroupID;
+ mode_change.ModeType = 1;
+ class_state = 1;
+ send_mes.rclType = 1080;
+ send_mes.msglen = sizeof(mode_change);
+ memcpy(send_mes.msg, &mode_change, sizeof(mode_change));
+
+ if (client_comm.send_mes(send_mes, send_mes.msglen + 8) < 0)
+ {
+ Error_dia(ERROR008, ERROR_S008);
+ perror("send swith to teach mode message failed!");
+ return;
+ }
+
+ gtk_widget_set_sensitive(modetech, FALSE);
+ gtk_widget_set_sensitive(tech_toolbutton, FALSE);
+
+ gtk_widget_set_sensitive(modecomu, TRUE);
+ gtk_widget_set_sensitive(commu_toolbutton, TRUE);
+
+ gtk_widget_set_sensitive(allow_chat_toolbutton, TRUE);
+
+ g_teacher_screensender.Start();
+
+ g_studet_videoreceiver.CloseXImage();
+ g_studet_videoreceiver.Stop();
+
+ g_student_audioreceiver.Stop();
+
+ switch (g_video_mode)
+ {
+ case 1:
+ g_teacher_v4lvideosender.CloseXImage();
+ break;
+ }
+
+}
+
+void on_commu_toolbutton_clicked(GtkToolButton *toolbutton, gpointer user_data)
+{
+
+ CRCLMSG send_mes;
+
+ CRCLTeacherSwitchMode mode_change;
+
+ mode_change.GroupID = client_comm.GroupID;
+ mode_change.ModeType = 0;
+ class_state = 0;
+ send_mes.rclType = 1080;
+ send_mes.msglen = sizeof(mode_change);
+ memcpy(send_mes.msg, &mode_change, sizeof(mode_change));
+
+ if (client_comm.send_mes(send_mes, send_mes.msglen + 8) < 0)
+ {
+ Error_dia(ERROR008, ERROR_S008);
+ perror("send swith to communicate mode message failed!");
+ return;
+ }
+
+ gtk_widget_set_sensitive(modetech, TRUE);
+ gtk_widget_set_sensitive(tech_toolbutton, TRUE);
+
+ gtk_widget_set_sensitive(modecomu, FALSE);
+ gtk_widget_set_sensitive(commu_toolbutton, FALSE);
+ if (allow_chat_set == 1)
+ gtk_tool_button_set_label((GtkToolButton*) allow_chat_toolbutton,
+ pmodeswich);
+ gtk_widget_set_sensitive(allow_chat_toolbutton, FALSE);
+
+ g_teacher_screensender.Stop();
+ g_teacher_screensender.Record(false);
+
+ switch (g_video_mode)
+ {
+ case 1:
+ g_teacher_v4lvideosender.Record(false);
+ break;
+ }
+
+ g_teacher_audiosender.Record(false);
+
+ switch (g_video_mode)
+ {
+ case 1:
+ g_teacher_v4lvideosender.CreateXImage(GDK_WINDOW_XID(
+ studentimage->window), 510, 75 + 225, 320, 220);
+ break;
+ }
+
+ if (!g_studet_videoreceiver.Init())
+ exit(1);
+
+ g_studet_videoreceiver.CreateXImage(GDK_WINDOW_XID(studentimage->window),
+ 510, 75, 320, 220);
+ printf("CreateGroup.CVPort is %d \n", CreateGroup.CVPort);
+
+ if (g_studet_videoreceiver.Start(CreateGroup.CVPort) < 0)
+ exit(2);
+
+ if (!g_student_audioreceiver.Init())
+ exit(1);
+
+ if (g_student_audioreceiver.Start(CreateGroup.CAPort) < 0)
+ exit(2);
+
+}
+
+void on_student_clist_select_row(GtkCList *clist, gint row, gint column,
+ GdkEvent *event, gpointer user_data)
+{
+ client_ts_communicate::studentlist_mutex.Lock();
+ gtk_clist_freeze(GTK_CLIST(student_clist));
+
+ gint now_cur = GTK_CLIST(student_clist)->focus_row;
+ gtk_clist_thaw(GTK_CLIST(student_clist));
+ client_ts_communicate::studentlist_mutex.Unlock();
+
+ gchar *text;
+
+ if (is_focus_set == 0 && class_state == 0)
+ {
+
+ client_ts_communicate::studentlist_mutex.Lock();
+ gtk_clist_freeze(GTK_CLIST(student_clist));
+ gtk_clist_get_text(GTK_CLIST(student_clist), now_cur, 0, &text);
+ gtk_clist_thaw(GTK_CLIST(student_clist));
+ client_ts_communicate::studentlist_mutex.Unlock();
+
+ clist_focusid = atoi(text);
+ printf("get focuse id is %d\n", clist_focusid);
+
+ gtk_widget_set_sensitive(concentrate_add_button, TRUE);
+
+ }
+
+ else if (is_focus_set == 1 && class_state == 0)
+ gtk_widget_set_sensitive(concentrate_concel_button, TRUE);
+
+}
+
+void on_concentrate_add_button_clicked(GtkButton *button, gpointer user_data)
+{
+ CRCLMSG send_mes;
+
+ if (is_focus_set == 0)
+ {
+ CRCLTeacherAllowClientFocus teacher_allow;
+
+ teacher_allow.TeacherID = client_comm.TeacherID;
+ teacher_allow.ClientID = clist_focusid;
+ teacher_allow.GroupID = client_comm.GroupID;
+
+ send_mes.rclType = 1050;
+ send_mes.msglen = sizeof(teacher_allow);
+ memcpy(send_mes.msg, &teacher_allow, sizeof(teacher_allow));
+
+ if (client_comm.send_mes(send_mes, send_mes.msglen + 8) < 0)
+ {
+ Error_dia(ERROR009, ERROR_S009);
+ perror("send allow student focus failed!");
+ return;
+ }
+
+ gtk_widget_set_sensitive(concentrate_add_button, FALSE);
+ }
+
+}
+void on_concentrate_concel_button_clicked(GtkButton *button, gpointer user_data)
+{
+ CRCLMSG send_mes;
+
+ if (is_focus_set == 1)
+ {
+ CRCLTeacherCancelClientFocus teacher_cancel;
+
+ teacher_cancel.TeacherID = client_comm.TeacherID;
+ teacher_cancel.ClientID = clist_focusid;
+ teacher_cancel.GroupID = client_comm.GroupID;
+
+ send_mes.rclType = 1060;
+ send_mes.msglen = sizeof(teacher_cancel);
+ memcpy(send_mes.msg, &teacher_cancel, sizeof(teacher_cancel));
+
+ if (client_comm.send_mes(send_mes, send_mes.msglen + 8) < 0)
+ {
+ Error_dia(ERROR011, ERROR_S011);
+ perror("send cancel student focus failed!");
+ return;
+ }
+
+ gtk_widget_set_sensitive(concentrate_concel_button, FALSE);
+ }
+}
+
+void send_chat_entry()
+{
+ const char *entry1 = gtk_entry_get_text(GTK_ENTRY(chat_entry));
+ upper1 = GTK_ADJUSTMENT(adj)->upper;
+ page_size1 = GTK_ADJUSTMENT(adj)->page_size;
+ step = GTK_ADJUSTMENT(adj)->step_increment;
+ value = upper1 - page_size1 + step;
+ if ((*entry1) == NULL)
+ return;
+
+ CRCLMSG send_mes;
+
+ CRCLTeacherTextBroadcast teacher_text;
+ teacher_text.ClientID = client_comm.TeacherID;
+ teacher_text.GroupID = client_comm.GroupID;
+ memset(teacher_text.Info, 0, 1024);
+ teacher_text.InfoLength = strlen(entry1) >= 1000 ? 1000 : strlen(entry1);
+
+ if (strlen(entry1) >= 1000)
+ {
+
+ memcpy(teacher_text.Info, entry1, 1000);
+
+ }
+ else
+ strcpy(teacher_text.Info, entry1);
+
+ send_mes.rclType = 1000;
+ send_mes.msglen = sizeof(teacher_text);
+ memcpy(send_mes.msg, &teacher_text, sizeof(teacher_text));
+
+ if (client_comm.send_mes(send_mes, send_mes.msglen + 8) < 0)
+ {
+ Error_dia(ERROR013, ERROR_S013);
+ perror("send chat message failed!");
+ }
+
+ char teacher_chat[1000];
+ strcpy(teacher_chat, pteacher_chat);
+ strcat(teacher_chat, teacher_text.Info);
+ strcat(teacher_chat, "\n");
+ client_comm.get_text_from_msg(teacher_chat);
+
+ gtk_adjustment_set_value(GTK_ADJUSTMENT(adj), value);
+ gtk_entry_set_text(GTK_ENTRY(chat_entry), "");
+
+}
+
+void on_chat_button_clicked(GtkButton *button, gpointer user_data)
+{
+ send_chat_entry();
+}
+
+void on_chat_entry_activate(GtkWidget *widget, GtkWidget *entry)
+{
+ send_chat_entry();
+}
+
+void on_allow_chat_toolbutton_clicked(GtkToolButton *toolbutton,
+ gpointer user_data)
+{
+ if (allow_chat_set == 0)
+ {
+ CRCLMSG send_mes;
+ CRCLTeacherIfAllowChat allow_chat;
+ allow_chat.GroupID = client_comm.GroupID;
+ allow_chat.Check = 0;//stop
+ send_mes.rclType = 1090;
+ send_mes.msglen = sizeof(allow_chat);
+ memcpy(send_mes.msg, &allow_chat, sizeof(allow_chat));
+ if (client_comm.send_mes(send_mes, send_mes.msglen + 8) < 0)
+ {
+ Error_dia(ERROR019, ERROR_S019);
+ perror("send not_allow_chat message failed!");
+ return;
+ }
+ printf("stop/n");
+
+ gtk_tool_button_set_label(toolbutton, _(palwcht));
+
+ }
+ if (allow_chat_set == 1)
+ {
+ CRCLMSG send_mes;
+ CRCLTeacherIfAllowChat allow_chat;
+ allow_chat.GroupID = client_comm.GroupID;
+ allow_chat.Check = 1;
+ send_mes.rclType = 1090;
+ send_mes.msglen = sizeof(allow_chat);
+ memcpy(send_mes.msg, &allow_chat, sizeof(allow_chat));
+ if (client_comm.send_mes(send_mes, send_mes.msglen + 8) < 0)
+ {
+ Error_dia(ERROR020, ERROR_S020);
+ perror("send allow_chat message failed!");
+ return;
+ }
+ printf("allow/n");
+ gtk_tool_button_set_label(toolbutton, pmodeswich);
+ }
+
+}
+void on_advance_button_clicked(GtkButton *button, gpointer user_data)
+{
+ gtk_widget_set_sensitive(enserverport, TRUE);
+ gtk_widget_set_sensitive(videoEntry, TRUE);
+ gtk_widget_set_sensitive(audioEntry, TRUE);
+}
+
+void on_choose_activate(GtkMenuItem *menuitem, gpointer user_data)
+{
+ GtkWidget *choose_dialog1;
+ choose_dialog1 = create_choose_dialog();
+ gtk_widget_show(choose_dialog1);
+
+}
+
+void on_combo_box_choose1(GtkObject *object, gpointer user_data)
+{
+ int position1;
+ int i, j;
+
+ position1 = gtk_combo_box_get_active(GTK_COMBO_BOX(user_data));
+
+ switch (position1)
+ {
+ case 0://v4l
+ {
+ gtk_combo_box_remove_text(GTK_COMBO_BOX(combobox5), 0);
+
+ printf("video dev is %s ,%d\n", g_DevName[0], g_VideoDevCount);
+ for (i = 0; i < g_VideoDevCount; i++)
+ gtk_combo_box_insert_text(GTK_COMBO_BOX(combobox5), i, g_DevName[i]);
+
+ gtk_combo_box_set_active(GTK_COMBO_BOX(combobox5), 0);
+
+ g_temp_video_mode = 1;
+ break;
+ }
+
+ printf("dev_num:%d\n", v4l_dev_num);
+ printf("%d in here!\n", g_temp_video_mode);
+ }
+}
+
+void on_view_but_clicked(GtkButton *button, gpointer user_data)
+{
+ dev_num_temp = gtk_combo_box_get_active(GTK_COMBO_BOX(combobox5));
+ v4l_dev_num = dev_num_temp;
+ check_viewbutton = 1;
+ switch (g_temp_video_mode)
+ {
+ case 1:
+ if (!g_teacher_v4lvideosender.IsInitialized())
+
+ {
+ if (!g_teacher_v4lvideosender.Init(6002))
+ Error_dia(ERROR022, ERROR_S022);
+ }
+ g_teacher_v4lvideosender.SetMode(CV4LVideoSender::ModeCapture);
+ g_teacher_v4lvideosender.Start();
+
+ g_teacher_v4lvideosender.CreateXImage(GDK_WINDOW_XID(
+ review_image->window), 170, 30, 320, 240);
+ break;
+ }
+ printf("viewbutton is %d", check_viewbutton);
+
+}
+
+void on_work_mode_activate(GtkMenuItem *menuitem, gpointer user_data)
+{
+ GtkWidget *work_dialog;
+ work_dialog = create_work_mode_dialog();
+ gtk_widget_show(work_dialog);
+}
+
+void on_rec_toolbutton_clicked(GtkToolButton *toolbutton, gpointer user_data)
+{
+ switch (record_courseware_set)
+ {
+
+ case 0:
+ GtkWidget* dialog6;
+ dialog6 = create_rec_delay_set_dialog();
+ gtk_widget_show(dialog6);
+
+ break;
+
+ case 1:
+
+ GtkWidget* dialog3;
+ dialog3 = create_exit_rec_dialog();
+ gtk_widget_show(dialog3);
+
+ break;
+ default:
+ break;
+
+ }
+}
+
+void on_radiobutton_work_clicked(GtkButton *button, gpointer user_data)
+{
+
+ switch ((int) user_data)
+ {
+ case 0:
+ g_temp_work_mode = 0;
+ break;
+ case 1:
+ g_temp_work_mode = 1;
+ break;
+ }
+ printf("%d in here!\n", g_temp_work_mode);
+
+}
+
+void on_choose_cancel_but_clicked(GtkButton *button, gpointer user_data)
+{
+ switch (g_temp_video_mode)
+ {
+ case 1:
+ g_temp_video_mode = 0;
+ g_teacher_v4lvideosender.CloseXImage();
+ g_teacher_v4lvideosender.Stop();
+
+ break;
+ }
+
+ gtk_widget_destroy(GTK_WIDGET(user_data));
+
+}
+
+void on_choose_ok_but_clicked(GtkButton *button, gpointer user_data)
+{
+ dev_num_temp = gtk_combo_box_get_active(GTK_COMBO_BOX(combobox5));
+ v4l_dev_num = dev_num_temp;
+ g_video_mode = g_temp_video_mode;
+ if (check_viewbutton == 1)
+ {
+ check_viewbutton = 0;
+ switch (g_video_mode)
+ {
+ case 1:
+ g_teacher_v4lvideosender.CloseXImage();
+ g_teacher_v4lvideosender.Stop();
+
+ break;
+
+ }
+
+ }
+ printf("check_viewbutton is %d", check_viewbutton);
+
+ gtk_widget_destroy(GTK_WIDGET(user_data));
+}
+
+void on_work_cancel_but_clicked(GtkButton *button, gpointer user_data)
+{
+ gtk_widget_destroy(GTK_WIDGET(user_data));
+
+}
+
+void on_work_ok_but_clicked(GtkButton *button, gpointer user_data)
+{
+ g_work_mode = g_temp_work_mode;
+ switch (g_work_mode)
+ {
+ case 0:
+ gtk_widget_set_sensitive(rec_toolbutton, FALSE);
+ gtk_widget_set_sensitive(set_item, TRUE);
+ gtk_widget_set_sensitive(set_toolbutton, TRUE);
+ gtk_widget_destroy(GTK_WIDGET(user_data));
+ break;
+ case 1:
+ gtk_widget_set_sensitive(rec_toolbutton, TRUE);
+ gtk_widget_set_sensitive(set_item, FALSE);
+ gtk_widget_set_sensitive(set_toolbutton, FALSE);
+ gtk_widget_destroy(GTK_WIDGET(user_data));
+ break;
+ default:
+ break;
+ }
+}
+
+gint choose_dialog_delete_event(GtkWidget *widget, GdkEvent *event,
+ gpointer user_data)
+{
+
+ switch (g_temp_video_mode)
+ {
+ case 1:
+ g_temp_video_mode = 0;
+ g_teacher_v4lvideosender.CloseXImage();
+ g_teacher_v4lvideosender.Stop();
+
+ break;
+ }
+
+ gtk_widget_destroy(GTK_WIDGET(user_data));
+
+ return TRUE;
+}
+
+void on_exit_rec_cancel_clicked(GtkButton *button, gpointer user_data)
+{
+ record_courseware_set = 0;
+ gtk_widget_destroy(GTK_WIDGET(user_data));
+}
+
+void on_exit_rec_yes_clicked(GtkButton *button, gpointer user_data)
+
+{
+ switch (g_video_mode)
+ {
+ case 1:
+ g_teacher_v4lvideosender.CloseXImage();
+ g_teacher_v4lvideosender.Stop();
+
+ break;
+ }
+ g_teacher_audiosender.Stop();
+ g_teacher_screensender.Stop();
+ printf("%d stop recording", record_courseware_set);
+
+ record_courseware_set = 0;
+
+ gtk_widget_destroy(GTK_WIDGET(user_data));
+ exit(1);
+}
+
+void on_clearchatitem_activate(GtkMenuItem *menuitem, gpointer user_data)
+{
+ gtk_text_buffer_get_start_iter(commu_buffer, &commu_start);
+ gtk_text_buffer_delete(commu_buffer, &commu_start, &commu_end);
+}
+
+void on_exit_class_cancel_clicked(GtkButton *button, gpointer user_data)
+{
+ gtk_widget_destroy(GTK_WIDGET(user_data));
+}
+
+void on_exit_class_yes_clicked(GtkButton *button, gpointer user_data)
+{
+ gtk_widget_destroy(GTK_WIDGET(user_data));
+ CRCLMSG send_mes;
+
+ TRCDestoryGroup DestoryGroup;
+ send_mes.rclType = 10010;
+ DestoryGroup.TeacherID = client_comm.TeacherID;
+ DestoryGroup.GroupID = client_comm.GroupID;
+
+ send_mes.msglen = sizeof(DestoryGroup);
+ memcpy(send_mes.msg, &DestoryGroup, sizeof(DestoryGroup));
+ if (client_comm.send_mes(send_mes, send_mes.msglen + 8) < 0)
+ {
+ Error_dia(ERROR006, ERROR_S006);
+ perror("send failed!");
+ return;
+ }
+ client_ts_communicate::studentlist_mutex.Lock();
+ gtk_clist_freeze(GTK_CLIST(student_clist));
+ gtk_clist_clear(GTK_CLIST(student_clist));
+ gtk_clist_thaw(GTK_CLIST(student_clist));
+ client_ts_communicate::studentlist_mutex.Unlock();
+ g_student_audioreceiver.Stop();
+
+ g_studet_videoreceiver.CloseXImage();
+ g_studet_videoreceiver.Stop();
+
+ switch (g_video_mode)
+ {
+
+ case 1:
+ g_teacher_v4lvideosender.CloseXImage();
+ g_teacher_v4lvideosender.Stop();
+ g_teacher_v4lvideosender.ClearDestinations();
+ break;
+ }
+ g_teacher_audiosender.Pause();
+ g_teacher_screensender.Stop();
+
+ is_focus_set = 0;
+
+ gtk_widget_set_sensitive(creatclass, TRUE);
+ gtk_widget_set_sensitive(creat_toolbutton, TRUE);
+
+ gtk_widget_set_sensitive(stopclass, FALSE);
+ gtk_widget_set_sensitive(cancel_toolbutton, FALSE);
+
+ gtk_widget_set_sensitive(modetech, FALSE);
+ gtk_widget_set_sensitive(tech_toolbutton, FALSE);
+
+ gtk_widget_set_sensitive(modecomu, FALSE);
+ gtk_widget_set_sensitive(commu_toolbutton, FALSE);
+
+ gtk_widget_set_sensitive(chat_button, FALSE);
+ if (allow_chat_set == 1)
+ gtk_tool_button_set_label((GtkToolButton*) allow_chat_toolbutton,
+ pmodeswich);
+ gtk_widget_set_sensitive(allow_chat_toolbutton, FALSE);
+
+}
+
+void on_exit_system_cancel_clicked(GtkButton *button, gpointer user_data)
+{
+ gtk_widget_destroy(GTK_WIDGET(user_data));
+}
+
+void on_exit_system_yes_clicked(GtkButton *button, gpointer user_data)
+{
+ CRCLMSG send_mes;
+ CRCLTeacherLogout Teacher_logout;
+
+ Teacher_logout.TeacherID = client_comm.TeacherID;
+
+ send_mes.rclType = 5030;
+ send_mes.msglen = sizeof(Teacher_logout);
+ memcpy(send_mes.msg, &Teacher_logout, sizeof(Teacher_logout));
+
+ if (client_comm.send_mes(send_mes, send_mes.msglen + 8) < 0)
+ {
+ perror("send logout message failed!");
+ //return ;
+ }
+
+ client_comm.close_socket(2);
+
+ switch (g_video_mode)
+ {
+
+ case 1:
+ g_teacher_v4lvideosender.Stop();
+ g_teacher_v4lvideosender.ClearDestinations();
+ break;
+ }
+
+ g_teacher_audiosender.Pause();
+ g_teacher_screensender.Stop();
+
+ gtk_widget_destroy(GTK_WIDGET(user_data));
+ gtk_main_quit();
+
+}
+
+gint window1_delete_event(GtkWidget *widget, GdkEvent *event,
+ gpointer user_data)
+{
+
+ GtkWidget *dialog5;
+ dialog5 = create_exit_system_dialog();
+ gtk_widget_show(dialog5);
+
+ return TRUE;
+}
+
+void on_rec_delay_cancel_clicked(GtkButton *button, gpointer user_data)
+{
+
+ gtk_widget_destroy(GTK_WIDGET(user_data));
+}
+
+void on_rec_delay_yes_clicked(GtkButton *button, gpointer user_data)
+{
+ delay_time = atoi(gtk_combo_box_get_active_text(GTK_COMBO_BOX(user_data)));
+ printf("record delay time is %d", delay_time);
+ if (delay_time < 0 || delay_time > 60)
+ delay_time = 5;
+
+ static char str1[255];
+ char strAudioFile[255];
+ char strVideoFile[255];
+ char strScreenFile[255];
+ char strpath[255] = "/root/kejian/";
+
+ if (record_courseware_set == 0)
+ {
+ mkdir(strpath, S_IRWXU);
+
+ time_t now;
+
+ now = time(0);
+ tm *tnow = localtime(&now);
+ sprintf(strpath + strlen(strpath), "%d_%0.2d_%0.2d_%0.2d_%0.2d", 1900
+ + tnow->tm_year, tnow->tm_mon + 1, tnow->tm_mday,
+ tnow->tm_hour, tnow->tm_min);
+ printf("%s\n", strpath);
+
+ if (mkdir(strpath, S_IRWXU) != 0)
+ {
+ printf("Warning:Create directory of %s failed!\n", strpath);
+ }
+
+ sprintf(strAudioFile, "%s/audio_CW_A.mp3", strpath);
+ sprintf(strVideoFile, "%s/video_CW_V.mpg", strpath);
+ sprintf(strScreenFile, "%s/screen_CW_S.mpg", strpath);
+
+ if (access(strAudioFile, F_OK) == 0)
+ {
+ printf("Warning:%s has exsited\n", strAudioFile);
+ }
+ if (access(strVideoFile, F_OK) == 0)
+ {
+ printf("Warning:%s has exsited\n", strVideoFile);
+ }
+ if (access(strScreenFile, F_OK) == 0)
+ {
+ printf("Warning:%s has exsited\n", strScreenFile);
+ }
+ }
+ gtk_tool_button_set_label((GtkToolButton*) rec_toolbutton, _(pextrcd));
+ if (!g_teacher_screensender.Init(6000))
+ exit(1);
+
+ if (g_teacher_screensender.Start(strScreenFile, true) < 0)
+ exit(1);
+
+ switch (g_video_mode)
+ {
+
+ case 1:
+ if (!g_teacher_v4lvideosender.IsInitialized())
+ {
+ if (!g_teacher_v4lvideosender.Init(6002))
+ Error_dia(ERROR022, ERROR_S022);
+ }
+ g_teacher_v4lvideosender.SetMode(CV4LVideoSender::ModeTransmit);
+
+ g_teacher_v4lvideosender.Start(strVideoFile, true);
+ g_teacher_v4lvideosender.Record(true);
+ break;
+ }
+ //init audio sender.
+ g_teacher_audiosender.Init(6004);
+ g_teacher_audiosender.Start(strAudioFile, true);
+
+ printf("%d recording", record_courseware_set);
+
+ record_courseware_set = 1;
+ gtk_widget_destroy(GTK_WIDGET(rec_delay_set_dialog));
+}
Added: incubator/bluesky/trunk/RealClass/Teacher/src/callbacks.hh
URL: http://svn.apache.org/viewvc/incubator/bluesky/trunk/RealClass/Teacher/src/callbacks.hh?rev=885392&view=auto
==============================================================================
--- incubator/bluesky/trunk/RealClass/Teacher/src/callbacks.hh (added)
+++ incubator/bluesky/trunk/RealClass/Teacher/src/callbacks.hh Mon Nov 30 12:01:23 2009
@@ -0,0 +1,183 @@
+/** \file callbacks.h define GUI operations
+*
+*
+*Licensed to the Apache Software Foundation (ASF) under one
+*or more contributor license agreements. See the NOTICE file
+*distributed with this work for additional information
+*regarding copyright ownership. The ASF licenses this file
+*to you under the Apache License, Version 2.0 (the
+*"License"); you may not use this file except in compliance
+*with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+*Unless required by applicable law or agreed to in writing,
+*software distributed under the License is distributed on an
+*"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+*KIND, either express or implied. See the License for the
+*specific language governing permissions and limitations
+*under the License.
+*/
+#include <gtk/gtk.h>
+#include "languagechoose.h"
+
+#ifndef _CALLBACK_H
+#define _CALLBACK_H
+//!check the GUI operation
+gboolean ncteacher_timer_callback(void *);
+//!login_activate
+void
+on_login_activate(GtkMenuItem *menuitem, gpointer user_data);
+//!exitsys_activate
+void
+on_exitsys_activate(GtkMenuItem *menuitem, gpointer user_data);
+//!creatclass_activate
+void
+on_creatclass_activate(GtkMenuItem *menuitem, gpointer user_data);
+//!stopclass_activate
+void
+on_stopclass_activate(GtkMenuItem *menuitem, gpointer user_data);
+//!modecomu_activate
+void
+on_modecomu_activate(GtkMenuItem *menuitem, gpointer user_data);
+//!modetech_activate
+void
+on_modetech_activate(GtkMenuItem *menuitem, gpointer user_data);
+//!set_activate
+void
+on_set_activate(GtkMenuItem *menuitem, gpointer user_data);
+//!stuimg_activate
+void
+on_stuimg_activate(GtkMenuItem *menuitem, gpointer user_data);
+//!techimg_activate
+void
+on_techimg_activate(GtkMenuItem *menuitem, gpointer user_data);
+//!login_cancelbutton_destroy
+void
+on_login_cancelbutton_destroy(GtkObject *object, gpointer user_data);
+//!loginokbutton_clicked
+void
+on_loginokbutton_clicked(GtkButton *button, gpointer user_data);
+//!networkokbutton_clicked
+void
+on_networkokbutton_clicked(GtkButton *button, gpointer netdialo);
+//!networkcancelbutton_clicked
+void
+on_networkcancelbutton_clicked(GtkObject *object, gpointer user_data);
+//!creat_cancelbut_clicked
+void
+on_creat_cancelbut_clicked(GtkButton *button, gpointer user_data);
+//!creat_okbutton_clicked
+void
+on_creat_okbutton_clicked(GtkButton *button, gpointer user_data);
+//!advance_button_clicked
+void
+on_advance_button_clicked(GtkButton *button, gpointer user_data);
+//!set_toolbutton_clicked
+void
+on_set_toolbutton_clicked(GtkToolButton *toolbutton, gpointer user_data);
+//!join_toolbutton_clicked
+void
+on_join_toolbutton_clicked(GtkToolButton *toolbutton, gpointer user_data);
+//!exit_toolbutton_clicked
+void
+on_exit_toolbutton_clicked(GtkToolButton *toolbutton, gpointer user_data);
+//!creat_toolbutton_clicked
+void
+on_creat_toolbutton_clicked(GtkToolButton *toolbutton, gpointer user_data);
+//!cancel_toolbutton_clicked
+void
+on_cancel_toolbutton_clicked(GtkToolButton *toolbutton, gpointer user_data);
+//!tech_toolbutton_clicked
+void
+on_tech_toolbutton_clicked(GtkToolButton *toolbutton, gpointer user_data);
+//!commu_toolbutton_clicked
+void
+on_commu_toolbutton_clicked(GtkToolButton *toolbutton, gpointer user_data);
+//!concentrate_add_button_clicked
+void
+on_concentrate_add_button_clicked(GtkButton *button, gpointer user_data);
+//!concentrate_concel_button_clicked
+void
+on_concentrate_concel_button_clicked(GtkButton *button, gpointer user_data);
+//!chat_button_clicked
+void
+on_chat_button_clicked(GtkButton *button, gpointer user_data);
+//!chat_entry_activate
+void
+on_chat_entry_activate(GtkWidget *widget, GtkWidget *entry);
+//!student_clist_select_row
+void
+on_student_clist_select_row(GtkCList *clist, gint row, gint column,
+ GdkEvent *event, gpointer user_data);
+//!allow_chat_toolbutton_clicked
+void
+on_allow_chat_toolbutton_clicked(GtkToolButton *toolbutton, gpointer user_data);
+//!choose_activate
+void
+on_choose_activate(GtkMenuItem *menuitem, gpointer user_data);
+//!radiobutton_choose_clicked
+void
+on_radiobutton_choose_clicked(GtkButton *button, gpointer user_data);
+//!view_button_clicked
+void
+on_view_but_clicked(GtkButton *button, gpointer user_data);
+//!work_mode_activate
+void
+on_work_mode_activate(GtkMenuItem *menuitem, gpointer user_data);
+//!rec_toolbutton_clicked
+void
+on_rec_toolbutton_clicked(GtkToolButton *toolbutton, gpointer user_data);
+//!radiobutton_work_clicked
+void
+on_radiobutton_work_clicked(GtkButton *button, gpointer user_data);
+//!choose_cancel_button_clicked
+void
+on_choose_cancel_but_clicked(GtkButton *button, gpointer user_data);
+//!choose_ok_button_clicked
+void
+on_choose_ok_but_clicked(GtkButton *button, gpointer user_data);
+//!work_ok_button_clicked
+void
+on_work_ok_but_clicked(GtkButton *button, gpointer user_data);
+//!work_cancel_button_clicked
+void
+on_work_cancel_but_clicked(GtkButton *button, gpointer user_data);
+//!choose_dialog_delete_event
+gint
+choose_dialog_delete_event(GtkWidget *widget, GdkEvent *event,
+ gpointer user_data);
+//!exit_rec_cancel_clicked
+void
+on_exit_rec_cancel_clicked(GtkButton *button, gpointer user_data);
+//!exit_rec_yes_clicked
+void
+on_exit_rec_yes_clicked(GtkButton *button, gpointer user_data);
+//!combo_box_choose1
+void
+on_combo_box_choose1(GtkObject *object, gpointer user_data);
+//!clearchatitem_activate
+void
+on_clearchatitem_activate(GtkMenuItem *menuitem, gpointer user_data);
+//!exit_class_cancel_clicked
+void
+on_exit_class_cancel_clicked(GtkButton *button, gpointer user_data);
+//!exit_class_yes_clicked
+void
+on_exit_class_yes_clicked(GtkButton *button, gpointer user_data);
+//!exit_system_cancel_clicked
+void
+on_exit_system_cancel_clicked(GtkButton *button, gpointer user_data);
+//!exit_system_yes_clicked
+void
+on_exit_system_yes_clicked(GtkButton *button, gpointer user_data);
+//!window1_delete_event
+gint
+window1_delete_event(GtkWidget *widget, GdkEvent *event, gpointer user_data);
+//!rec_delay_cancel_clicked
+void
+on_rec_delay_cancel_clicked(GtkButton *button, gpointer user_data);
+//!rec_delay_yes_clicked
+void
+on_rec_delay_yes_clicked(GtkButton *button, gpointer user_data);
+#endif
Added: incubator/bluesky/trunk/RealClass/Teacher/src/client_communicate.cc
URL: http://svn.apache.org/viewvc/incubator/bluesky/trunk/RealClass/Teacher/src/client_communicate.cc?rev=885392&view=auto
==============================================================================
--- incubator/bluesky/trunk/RealClass/Teacher/src/client_communicate.cc (added)
+++ incubator/bluesky/trunk/RealClass/Teacher/src/client_communicate.cc Mon Nov 30 12:01:23 2009
@@ -0,0 +1,659 @@
+/** \file client_communicate.cc implementation for the communicate with Tserver
+*
+*
+*Licensed to the Apache Software Foundation (ASF) under one
+*or more contributor license agreements. See the NOTICE file
+*distributed with this work for additional information
+*regarding copyright ownership. The ASF licenses this file
+*to you under the Apache License, Version 2.0 (the
+*"License"); you may not use this file except in compliance
+*with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+*Unless required by applicable law or agreed to in writing,
+*software distributed under the License is distributed on an
+*"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+*KIND, either express or implied. See the License for the
+*specific language governing permissions and limitations
+*under the License.
+*/
+
+#include "client_communicate.h"
+#include <iostream.h>
+#include <gtk/gtk.h>
+#include <stdio.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <unistd.h>
+
+#include "en_de_audio.h"
+#include "en_de_video.h"
+#include "en_de_screen.h"
+#include "errorinfo.h"
+#include "interface.hh"
+#include "support.hh"
+
+#include "languagechoose.h"
+
+extern GtkWidget *modetech;
+extern GtkWidget *modecomu;
+
+extern GtkWidget *tech_toolbutton;
+extern GtkWidget *commu_toolbutton;
+
+extern GtkWidget *creatclass;
+extern GtkWidget *stopclass;
+
+extern GtkWidget *creat_toolbutton;
+extern GtkWidget *cancel_toolbutton;
+extern GtkWidget *allow_chat_toolbutton;
+
+extern GtkWidget *student_clist;
+
+extern GtkWidget *concentrate_add_button;
+extern GtkWidget *concentrate_concel_button;
+
+extern GtkWidget *chat_button;
+
+extern GtkTextBuffer *commu_buffer;
+extern GtkTextIter commu_end;
+
+extern GtkWidget *join_toolbutton;
+extern GtkWidget *login;
+extern GtkWidget *exitsys;
+extern GtkWidget *exit_toolbutton;
+
+extern GtkWidget *set_item;
+extern GtkWidget *set_toolbutton;
+
+extern int get_client_clist(); //define in callback.cc
+extern int is_focus_set; //0: haven't 1:set already
+extern int clist_focusid; //record focus student
+extern int allow_chat_set;//0:stop chat;1:allow chat
+
+extern CVideoReceiver g_studet_videoreceiver;
+extern CAudioReceiver g_student_audioreceiver;
+
+extern CAudioSender g_teacher_audiosender; //define in techmm.cc
+extern CV4LVideoSender g_teacher_v4lvideosender;
+extern CScreenSender g_teacher_screensender;
+
+extern int g_work_mode;
+extern int g_video_mode;
+
+extern int error_info_no; //define in callback.cc
+
+extern GtkWidget *commu_textview;
+
+gint y_position, height;
+
+JMutex client_ts_communicate::studentlist_mutex;
+
+client_ts_communicate::client_ts_communicate()
+{
+ studentlist_mutex.Init();
+ textview_mutex.Init();
+}
+
+client_ts_communicate::~client_ts_communicate()
+{
+
+}
+
+int client_ts_communicate::close_socket(int nHow)
+{
+ if (client_socket.ShutDown(nHow) == false)
+ {
+ perror("close socket error!");
+ return -1;
+ }
+ else
+ return 0;
+}
+
+int client_ts_communicate::establish_connect(LPCTSTR ts_IP, UINT ts_Port,
+ UINT nSocketPort)
+{
+ if (client_socket.Create(nSocketPort) != true)
+ {
+ printf("Create socket failed!/n");
+ return -1;
+ }
+
+ if (client_socket.Connect(ts_IP, ts_Port) != true)
+ {
+ perror("connet error!");
+ return -1;
+ }
+
+ client_socket_thread.Attach(&client_socket);
+
+ if (client_socket_thread.Init() != true)
+ {
+ printf("Fail to initilize thread!/n");
+ return -1;
+ }
+ client_socket_thread.Start();
+
+ return 0;
+
+}
+
+int client_ts_communicate::send_mes(CRCLMSG mes, int mes_length)
+{
+
+ if (client_socket.Send(&mes, mes_length) == -1)
+ {
+ perror("Send message failed!");
+ return -1;
+ }
+ return 0;
+}
+
+int client_ts_communicate::recevie_msg(char *buf, int buf_length)
+{
+ CRCLMSG * receive_str;
+ receive_str = (CRCLMSG *) buf;
+
+ switch (receive_str->rclType)
+ {
+ case 5001:
+ //teacher login,response message
+ CRCLTeacherLoginR *TeacherLoginR;
+ TeacherLoginR = (CRCLTeacherLoginR *) receive_str->msg;
+
+ if (TeacherLoginR->ResponseType != 0)
+ {
+ error_info_no = 3;
+ perror("teacher login error!");
+ gtk_widget_set_sensitive(creatclass, FALSE);
+ gtk_widget_set_sensitive(creat_toolbutton, FALSE);
+
+ gtk_widget_set_sensitive(exitsys, FALSE);
+ gtk_widget_set_sensitive(exit_toolbutton, FALSE);
+
+ gtk_widget_set_sensitive(set_item, TRUE);
+ gtk_widget_set_sensitive(set_toolbutton, TRUE);
+
+ gtk_widget_set_sensitive(login, TRUE);
+ gtk_widget_set_sensitive(join_toolbutton, TRUE);
+
+ return -1;
+ }
+
+ TeacherID = TeacherLoginR->TeacherID;
+ cout << "teachloginr.ResponseType" << " "
+ << TeacherLoginR->ResponseType << endl;
+ cout << "teachloginr.TeacherID" << " " << TeacherLoginR->TeacherID
+ << endl;
+
+ gtk_widget_set_sensitive(set_item, FALSE);
+ gtk_widget_set_sensitive(set_toolbutton, FALSE);
+
+ break;
+
+ case 10001:
+ {
+ //teacher create class, response message A
+ CRCLCreateGroupR *CreateGroupR;
+ CreateGroupR = (CRCLCreateGroupR *) receive_str->msg;
+
+ if (CreateGroupR->ResponseType == 0)
+ {
+ GroupID = CreateGroupR->GroupID;
+ printf("create class OK!\n");
+ }
+ else
+ {
+ error_info_no = 5;
+ perror("creat class error!");
+ return -1;
+ }
+
+ printf("MCU ip is %s\n", CreateGroupR->MCUIP);
+ printf("MCU port is %d,%d\n", CreateGroupR->TVPort,
+ CreateGroupR->TSPort);
+
+ gtk_widget_set_sensitive(stopclass, TRUE);
+ gtk_widget_set_sensitive(cancel_toolbutton, TRUE);
+
+ gtk_widget_set_sensitive(creatclass, FALSE);
+ gtk_widget_set_sensitive(creat_toolbutton, FALSE);
+
+ gtk_widget_set_sensitive(modetech, FALSE);
+ gtk_widget_set_sensitive(tech_toolbutton, FALSE);
+
+ gtk_widget_set_sensitive(modecomu, TRUE);
+ gtk_widget_set_sensitive(commu_toolbutton, TRUE);
+
+ gtk_widget_set_sensitive(chat_button, TRUE);
+ allow_chat_set = 0;
+ gtk_widget_set_sensitive(allow_chat_toolbutton, TRUE);
+ allow_chat_set = 0;
+
+ //create send thread
+
+ unsigned long intIP2 = inet_addr(CreateGroupR->MCUIP);
+
+ intIP2 = ntohl(intIP2); //put in host byte order
+ RTPIPv4Address rtpAddr1(intIP2, CreateGroupR->TVPort);
+ RTPIPv4Address rtpAddr2(intIP2, CreateGroupR->TSPort);
+ RTPIPv4Address rtpAddr3(intIP2, CreateGroupR->TAPort);
+
+ /*Create directory by current time*/
+ char strAudioFile[255];
+ char strVideoFile[255];
+ char strScreenFile[255];
+ char strpath[255] = "/root/kejian/";
+
+ mkdir(strpath, S_IRWXU);
+
+ time_t now;
+
+ now = time(0);
+ tm *tnow = localtime(&now);
+ sprintf(strpath + strlen(strpath), "%d_%0.2d_%0.2d_%0.2d_%0.2d", 1900
+ + tnow->tm_year, tnow->tm_mon + 1, tnow->tm_mday,
+ tnow->tm_hour, tnow->tm_min);
+ printf("%s\n", strpath);
+
+ if (mkdir(strpath, S_IRWXU) != 0)
+ {
+ printf("Warning:Create directory of %s failed!\n", strpath);
+ }
+
+ sprintf(strAudioFile, "%s/audio_CW_A.mp3", strpath);
+ sprintf(strVideoFile, "%s/video_CW_V.mpg", strpath);
+ sprintf(strScreenFile, "%s/screen_CW_S.mpg", strpath);
+
+ if (access(strAudioFile, F_OK) == 0)
+ {
+ printf("Warning:%s has exsited\n", strAudioFile);
+ }
+ if (access(strVideoFile, F_OK) == 0)
+ {
+ printf("Warning:%s has exsited\n", strVideoFile);
+ }
+ if (access(strScreenFile, F_OK) == 0)
+ {
+ printf("Warning:%s has exsited\n", strScreenFile);
+ }
+ //init screen sender.
+ if (!g_teacher_screensender.Init(6000))
+ exit(1);
+ g_teacher_screensender.AddDestination(rtpAddr2);
+ if (g_teacher_screensender.Start(strScreenFile, true) < 0)
+ exit(1);
+
+ //init video sender.
+ switch (g_video_mode)
+ {
+
+ case 1:
+ if (!g_teacher_v4lvideosender.IsInitialized())
+ {
+ if (!g_teacher_v4lvideosender.Init(6002))
+ Error_dia(ERROR022, ERROR_S022);
+ }
+
+ g_teacher_v4lvideosender.SetMode(CV4LVideoSender::ModeTransmit);
+ g_teacher_v4lvideosender.AddDestination(rtpAddr1);
+ g_teacher_v4lvideosender.Start(strVideoFile, true);
+ g_teacher_v4lvideosender.Record(true);
+ break;
+ }
+
+ if (!g_teacher_audiosender.Init(6004))
+ {
+ printf("fdsafsfesfds\n");
+ exit(1);
+ }
+
+ g_teacher_audiosender.AddDestination(rtpAddr3);
+ if (g_teacher_audiosender.Start(strAudioFile, true) < 0)
+ {
+ printf("fdsafsfesfds\n");
+
+ }
+ break;
+ }
+
+ case 1031:
+ {
+ //text chat, broadcast to other clients
+ CRCLClientTextBroadcastR *Client_text_r;
+ Client_text_r = (CRCLClientTextBroadcastR *) receive_str->msg;
+
+ char text_Info[1045];
+
+ strcpy(text_Info, Client_text_r->ClientName);
+ strcat(text_Info, ": ");
+ strcat(text_Info, Client_text_r->Info);
+ strcat(text_Info, "\n");
+
+ gtk_text_buffer_insert(commu_buffer, &commu_end, text_Info, -1);
+ flush_scrollar();
+ }
+ break;
+
+ case 1071:
+ //teacher get students' info, response to the teachers
+ client_ts_communicate::studentlist_mutex.Lock();
+
+ gtk_clist_freeze( GTK_CLIST(student_clist));
+ CRCLTeacherGetClientListR *teacher_GetClientList;
+ teacher_GetClientList = (CRCLTeacherGetClientListR *) receive_str->msg;
+
+ int index;
+ char tmp[100];
+ memset(tmp, 0, sizeof(tmp));
+
+ char studentInfo[1024][3][limitbit];
+ char *ptr_studentInfo[1024][3];
+ memset(studentInfo, 0, sizeof(studentInfo));
+ memset(ptr_studentInfo, 0, sizeof(ptr_studentInfo));
+
+ char avmode[15];
+ char no_avmode[16];
+ memset(avmode, 0, sizeof(avmode));
+ memset(no_avmode, 0, sizeof(no_avmode));
+
+ strcpy(avmode, pYES);
+ strcpy(no_avmode, pNO);
+ if (teacher_GetClientList->ResponseType == 0)
+ {
+ printf("I get client %d\n", teacher_GetClientList->ClientNum);
+
+ gtk_clist_clear( GTK_CLIST(student_clist));
+
+ for (index = 0; index < teacher_GetClientList->ClientNum; index++)
+ {
+ printf("get STUID %d\n",
+ teacher_GetClientList->ClientList[index].ClientID);
+ printf(" student name is %s ,AVMOde is %d\n",
+ teacher_GetClientList->ClientList[index].ClientName,
+ teacher_GetClientList->ClientList[index].IsFocus);
+
+ sprintf(tmp, "%d",
+ teacher_GetClientList->ClientList[index].ClientID);
+ memcpy(studentInfo[index][0], tmp, strlen(tmp));
+ ptr_studentInfo[index][0] = studentInfo[index][0];
+
+ memcpy(
+ studentInfo[index][1],
+ teacher_GetClientList->ClientList[index].ClientName,
+ strlen(
+ teacher_GetClientList->ClientList[index].ClientName));
+ ptr_studentInfo[index][1] = studentInfo[index][1];
+
+ if (teacher_GetClientList->ClientList[index].IsFocus == 0)
+ {
+
+ memcpy(studentInfo[index][2], avmode, strlen(avmode));
+ ptr_studentInfo[index][2] = studentInfo[index][2];
+ }
+
+ else if (teacher_GetClientList->ClientList[index].IsFocus == 1)
+ {
+
+ memcpy(studentInfo[index][2], no_avmode, strlen(no_avmode));
+ ptr_studentInfo[index][2] = studentInfo[index][2];
+ }
+
+ gtk_clist_append(GTK_CLIST(student_clist),
+ ptr_studentInfo[index]);
+
+ }
+ }
+
+ gtk_clist_thaw( GTK_CLIST(student_clist));
+
+ client_ts_communicate::studentlist_mutex.Unlock();
+ printf("\n1071 finished!!!!!!!!\n");
+ break;
+
+ case 1012:
+ {
+ //student apply for focus, send message to MCU and the teacher
+ CRCLClientApplyFocusRToTM *client_apply_focus;
+ client_apply_focus = (CRCLClientApplyFocusRToTM *) receive_str->msg;
+ char text_Info[1045];
+
+ strcpy(text_Info, ptext);
+ char tmp[10];
+ sprintf(tmp, "%d", client_apply_focus->FocusClientID);
+ strcat(text_Info, tmp);
+
+ strcat(text_Info, "\n\n");
+ textview_mutex.Lock();
+ gtk_text_buffer_insert(commu_buffer, &commu_end, text_Info, -1);
+ textview_mutex.Unlock();
+ flush_scrollar();
+
+ }
+ break;
+
+ case 1022:
+ {
+ //student cancel focus, send message to MCU and the teacher
+ CRCLClientDestroyFocusRToTM *client_destroy_focus;
+ client_destroy_focus = (CRCLClientDestroyFocusRToTM *) receive_str->msg;
+ char text_Info[1045];
+
+ strcpy(text_Info, ptext01);
+ char tmp[10];
+ sprintf(tmp, "%d", client_destroy_focus->FocusClientID);
+ strcat(text_Info, tmp);
+ strcat(text_Info, "\n\n");
+ textview_mutex.Lock();
+ gtk_text_buffer_insert(commu_buffer, &commu_end, text_Info, -1);
+ textview_mutex.Unlock();
+ flush_scrollar();
+ }
+ break;
+
+ case 10022:
+ { //student join the class, response message B, send to other clients
+ client_ts_communicate::studentlist_mutex.Lock();
+ gtk_clist_freeze( GTK_CLIST(student_clist));
+ CRCLClientJoinInGroupRAll *client_join_group_response;
+ client_join_group_response
+ = (CRCLClientJoinInGroupRAll *) receive_str->msg;
+
+ char *add_student[3];
+ char comm_mode[5];
+ char no_comm_mode[6];
+ char temp[10];
+
+ strcpy(comm_mode, pYES);
+ strcpy(no_comm_mode, pNO);
+
+ sprintf(temp, "%d", client_join_group_response->ClientInfo.ClientID);
+ add_student[0] = temp;
+
+ add_student[1] = client_join_group_response->ClientInfo.ClientName;
+
+ if (client_join_group_response->ClientInfo.IsFocus == 0)
+ add_student[2] = comm_mode;
+
+ else if (client_join_group_response->ClientInfo.IsFocus == 1)
+ add_student[2] = no_comm_mode;
+
+ gtk_clist_append(GTK_CLIST(student_clist), add_student);
+
+ gtk_clist_thaw( GTK_CLIST(student_clist));
+ client_ts_communicate::studentlist_mutex.Unlock();
+ break;
+ }
+ case 1051:
+ //teacher appoint the focus srudent, response message
+ CRCLTeacherAllowClientFocusR *allow_client_response;
+ allow_client_response
+ = (CRCLTeacherAllowClientFocusR *) receive_str->msg;
+
+ if (allow_client_response->ResponseType != 0)
+ {
+ error_info_no = 10;
+ perror("failed to set focus!");
+ return -1;
+ }
+
+ if (get_client_clist() < 0)
+ {
+ perror("get client clist failed!");
+ return -1;
+ }
+
+ is_focus_set = 1;
+
+ gtk_widget_set_sensitive(concentrate_concel_button, TRUE);
+ break;
+
+ case 1061:
+ //teacher cancel the focus, response message
+ CRCLTeacherCancelClientFocusR *cancel_client_response;
+ cancel_client_response
+ = (CRCLTeacherCancelClientFocusR *) receive_str->msg;
+
+ printf("cancel client focus response is %d\n",
+ cancel_client_response->ResponseType);
+ if (cancel_client_response->ResponseType != 0)
+ {
+ error_info_no = 12;
+ perror("failed to cancel focus!");
+ return -1;
+ }
+
+ if (is_focus_set == 1)
+ {
+
+ if (get_client_clist() < 0)
+ {
+ perror("get client clist failed!");
+ return -1;
+ }
+ is_focus_set = 0;
+ }
+ break;
+
+ case 10032:
+ //student leave the class, response message B, send to other clients
+ CRCLClientLeaveGroupRAll *client_leave_group_response;
+ client_leave_group_response
+ = (CRCLClientLeaveGroupRAll *) receive_str->msg;
+
+ if (client_leave_group_response->ClientInfo.ClientID == clist_focusid)
+ {
+ if (is_focus_set == 1)
+ is_focus_set = 0;
+ gtk_widget_set_sensitive(concentrate_concel_button, FALSE);
+
+ }
+
+ if (get_client_clist() < 0)
+ {
+ perror("get client clist failed!");
+ return -1;
+ }
+
+ break;
+
+ case 10042:
+ //MCU leave the class, send message to other clients
+ CRCLMCULeaveGroupRAll *mcu_leave_group;
+ mcu_leave_group = (CRCLMCULeaveGroupRAll *) receive_str->msg;
+ g_student_audioreceiver.Stop();
+
+ g_studet_videoreceiver.CloseXImage();
+ g_studet_videoreceiver.Stop();
+
+ switch (g_video_mode)
+ {
+
+ case 1:
+ g_teacher_v4lvideosender.CloseXImage();
+ g_teacher_v4lvideosender.Stop();
+ g_teacher_v4lvideosender.ClearDestinations();
+ break;
+ }
+
+ g_teacher_audiosender.Pause();
+ g_teacher_screensender.Stop();
+
+ is_focus_set = 0;
+
+ gtk_widget_set_sensitive(creatclass, TRUE);
+ gtk_widget_set_sensitive(creat_toolbutton, TRUE);
+
+ gtk_widget_set_sensitive(stopclass, FALSE);
+ gtk_widget_set_sensitive(cancel_toolbutton, FALSE);
+
+ gtk_widget_set_sensitive(modetech, FALSE);
+ gtk_widget_set_sensitive(tech_toolbutton, FALSE);
+
+ gtk_widget_set_sensitive(modecomu, FALSE);
+ gtk_widget_set_sensitive(commu_toolbutton, FALSE);
+
+ gtk_widget_set_sensitive(chat_button, FALSE);
+
+ break;
+ case 1091:
+ //teacher send allow/forbid message
+ struct CRCLTeacherIfAllowChatR *allow_chat_response;
+ allow_chat_response = (CRCLTeacherIfAllowChatR *) receive_str->msg;
+ if (allow_chat_response->ResponseType != 0)
+ {
+
+ if (allow_chat_set == 0)
+ {
+ error_info_no = 19;
+ gtk_tool_button_set_label(
+ (GtkToolButton*) allow_chat_toolbutton, pmodeswich);
+
+ }
+ else
+ {
+ error_info_no = 20;
+ gtk_tool_button_set_label(
+ (GtkToolButton*) allow_chat_toolbutton, palwcht);
+
+ }
+ perror("failed to set chat!");
+ return -1;
+ }
+ if (allow_chat_set == 0)
+ {
+ allow_chat_set = 1;
+
+ }
+
+ else
+ {
+ allow_chat_set = 0;
+
+ }
+ break;
+ default:
+
+ break;
+ }
+
+ return 0;
+
+}
+
+void client_ts_communicate::get_text_from_msg(char *Message)
+{
+ textview_mutex.Lock();
+ gtk_text_buffer_insert(commu_buffer, &commu_end, Message, -1);
+ textview_mutex.Unlock();
+}
+
+void client_ts_communicate::flush_scrollar()
+{
+ textview_mutex.Lock();
+ error_info_no = 40;
+ textview_mutex.Unlock();
+}
Added: incubator/bluesky/trunk/RealClass/Teacher/src/client_communicate.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/trunk/RealClass/Teacher/src/client_communicate.h?rev=885392&view=auto
==============================================================================
--- incubator/bluesky/trunk/RealClass/Teacher/src/client_communicate.h (added)
+++ incubator/bluesky/trunk/RealClass/Teacher/src/client_communicate.h Mon Nov 30 12:01:23 2009
@@ -0,0 +1,72 @@
+/** \file client_communicate.h class for the communicate with Tserver
+*
+*
+*Licensed to the Apache Software Foundation (ASF) under one
+*or more contributor license agreements. See the NOTICE file
+*distributed with this work for additional information
+*regarding copyright ownership. The ASF licenses this file
+*to you under the Apache License, Version 2.0 (the
+*"License"); you may not use this file except in compliance
+*with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+*Unless required by applicable law or agreed to in writing,
+*software distributed under the License is distributed on an
+*"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+*KIND, either express or implied. See the License for the
+*specific language governing permissions and limitations
+*under the License.
+*/
+
+#ifndef CLIENT_COMMUNICATE_H
+#define CLIENT_COMMUNICATE_H
+#include <list>
+#include "stdafx.h"
+#include "clientsocket.h"
+#include "singlecomm.h"
+#include "trcclient.hh"
+//!communicate with Tserver
+class client_ts_communicate
+{
+public:
+ //!Constructor
+ client_ts_communicate();
+ //!Destructor
+ ~client_ts_communicate();
+ //!establish a connection
+ int establish_connect(LPCTSTR, UINT, UINT nSocketPort = 0);
+ //!send messages
+ /*!
+ \param CRCLMSG the message
+ \param mes_length message length
+ */
+ int send_mes(struct CRCLMSG, int mes_length);
+ //!receive messages
+ /*!
+ \param buf the buffer to store messages
+ \param buf_length buffer size
+ */
+ int recevie_msg(char *buf, int buf_length);
+ //!get text from messages
+ /*!
+ \param Message the message
+ */
+ void get_text_from_msg(char *Message);
+ //!flush scrollar
+ void flush_scrollar();
+ //!close the socket
+ int close_socket(int nHow);
+ //!Teacher ID
+ DWORD TeacherID;
+ //!Group ID
+ DWORD GroupID;
+
+ static JMutex studentlist_mutex;
+private:
+ CClientSocket client_socket;
+ CSingleComm client_socket_thread;
+ JMutex textview_mutex;
+};
+
+#endif
Added: incubator/bluesky/trunk/RealClass/Teacher/src/clientsocket.cpp
URL: http://svn.apache.org/viewvc/incubator/bluesky/trunk/RealClass/Teacher/src/clientsocket.cpp?rev=885392&view=auto
==============================================================================
--- incubator/bluesky/trunk/RealClass/Teacher/src/clientsocket.cpp (added)
+++ incubator/bluesky/trunk/RealClass/Teacher/src/clientsocket.cpp Mon Nov 30 12:01:23 2009
@@ -0,0 +1,75 @@
+/** \file clientsocket.cpp implementation of the CClientSocket class
+ *
+*Licensed to the Apache Software Foundation (ASF) under one
+*or more contributor license agreements. See the NOTICE file
+*distributed with this work for additional information
+*regarding copyright ownership. The ASF licenses this file
+*to you under the Apache License, Version 2.0 (the
+*"License"); you may not use this file except in compliance
+*with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+*Unless required by applicable law or agreed to in writing,
+*software distributed under the License is distributed on an
+*"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+*KIND, either express or implied. See the License for the
+*specific language governing permissions and limitations
+*under the License.
+*/
+
+#include "stdafx.h"
+#include "clientsocket.h"
+#include "client_communicate.h"
+
+extern client_ts_communicate client_comm;
+
+CClientSocket::CClientSocket()
+{
+
+}
+
+CClientSocket::~CClientSocket()
+{
+}
+
+void CClientSocket::OnEvent()
+{
+ unsigned long len;
+ if (m_lEvent == 0)
+ return;
+ IOCtl(FIONREAD, &len);
+ if (len == 0)
+ {
+ Close();
+ printf("\nA client disconnected.");
+ return;
+ }
+
+ char buffer[10008] =
+ { '\0' };
+ int receive_length = 0;
+
+ memset(buffer, '\0', 10008);
+ if ((receive_length = Receive(buffer, 10008)) == -1)
+ {
+ perror("Receive failed!");
+ return;
+ }
+
+ CRCLMSG* pM = (CRCLMSG*) buffer;
+ printf("message lenth is %d\n", pM->msglen);
+ int index = receive_length;
+ int to_receive_length = pM->msglen + 8 - receive_length;
+ while (to_receive_length > 0)
+ {
+ receive_length = Receive(buffer + index, to_receive_length);
+ printf("recv a message lenth is %d\n", receive_length);
+ index += receive_length;
+ to_receive_length -= receive_length;
+ }
+
+ client_comm.recevie_msg(buffer, receive_length);
+
+ return;
+}
Added: incubator/bluesky/trunk/RealClass/Teacher/src/clientsocket.h
URL: http://svn.apache.org/viewvc/incubator/bluesky/trunk/RealClass/Teacher/src/clientsocket.h?rev=885392&view=auto
==============================================================================
--- incubator/bluesky/trunk/RealClass/Teacher/src/clientsocket.h (added)
+++ incubator/bluesky/trunk/RealClass/Teacher/src/clientsocket.h Mon Nov 30 12:01:23 2009
@@ -0,0 +1,42 @@
+/** \file clientsocket.h CClientSocket extends CAsyncSocketEx and handle socket event with users
+*
+*Licensed to the Apache Software Foundation (ASF) under one
+*or more contributor license agreements. See the NOTICE file
+*distributed with this work for additional information
+*regarding copyright ownership. The ASF licenses this file
+*to you under the Apache License, Version 2.0 (the
+*"License"); you may not use this file except in compliance
+*with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+*Unless required by applicable law or agreed to in writing,
+*software distributed under the License is distributed on an
+*"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+*KIND, either express or implied. See the License for the
+*specific language governing permissions and limitations
+*under the License.
+*/
+
+
+#if !defined(CLIENTSOCKET_H)
+#define CLIENTSOCKET_H
+
+#include "asyncsocketex.h"
+
+//!Client Socket class
+class CClientSocket: public CAsyncSocketEx
+{
+public:
+ //Constructor
+ CClientSocket();
+ //!Destructor
+ virtual ~CClientSocket();
+
+protected:
+ //!listen to event and deal with corresponding events
+ virtual void OnEvent();
+
+};
+
+#endif // !defined(CLIENTSOCKET_H)