TcpServer And TcpClients has been implemented, but debugging must be needed (Because current implementation has bugs).
cmake_minimum_required(VERSION 2.6)
project(jasmine)
find_package(Qt4 4.5 REQUIRED QtCore QtGui QtNetwork)
+find_package(OpenMP)
add_definitions(${QT_DEFINITIONS})
include_directories(${CMAKE_CURRENT_BINARY_DIR} ${QT_INCLUDE_DIR})
include(${QT_USE_FILE})
qt4_wrap_ui(ui_moc ${ui})
qt4_add_resources(res_moc ${res})
if(WIN32)
- add_executable(jasmine WIN32
+ if(OPENMP_FOUND)
+ add_executable(jasmine WIN32
${main} ${ui_moc} ${ui_src} ${serverclient_moc}
${serverclient_src} ${structures} ${res_moc}
${validator} ${ported_rmd6})
- target_link_libraries(jasmine ${QT_LIBRARIES})
+ set_property(TARGET jasmine PROPERTY COMPLILE_FLAGS ${OpenMP_CXX_FLAGS} APPEND)
+ target_link_libraries(jasmine gomp ${QT_LIBRARIES})
+ else(OPENMP_FOUND)
+ add_executable(jasmine WIN32
+ ${main} ${ui_moc} ${ui_src} ${serverclient_moc}
+ ${serverclient_src} ${structures} ${res_moc}
+ ${validator} ${ported_rmd6})
+ target_link_libraries(jasmine ${QT_LIBRARIES})
+ endif(OPENMP_FOUND)
else(WIN32)
add_library(qripemd160 SHARED ${ported_rmd6})
add_library(validator SHARED ${validator})
target_link_libraries(ui resource serverclient ${QT_LIBRARIES})
target_link_libraries(jasmine ui ${QT_LIBRARIES})
+ if(OPENMP_FOUND)
+ set_property(TARGET ui PROPERTY COMPILE_FLAGS ${OpenMP_CXX_FLAGS} APPEND)
+ target_link_libraries(ui gomp)
+ endif(OPENMP_FOUND)
endif(WIN32)
#include <QDataStream>
#include <QPair>
+#ifdef _OPENMP
+#include <omp.h>
+#endif
+
using namespace structures;
using namespace network;
mainWindow::mainWindow(){
connect(this->receiveText,SIGNAL(highlighted(const QUrl &)),SLOT(selectedLink(const QUrl &)));
connect(this->sendTextEditor,SIGNAL(invalidLink(const QString &)),SLOT(invalidLink(const QString &)));
connect(this->sendTextEditor,SIGNAL(sendTriggered()),this->sendButton,SLOT(click()));
+
+ connect(this->mainServer,SIGNAL(pending(const serverSocket &)),SLOT(tcpserver_pending(const serverSocket &)));
}
mainWindow::~mainWindow(){}
void mainWindow::closeEvent(QCloseEvent *event){
this->status->showMessage("<font color=\"#ff0000\">Don't forget almost all features are not implemented!</font>",default_status_interval);
event->accept();
}
-int mainWindow::isInMember(const AddressAndPort &peer){
- for(int row=0;row<this->memberList->rowCount();row++){
- QStringList address_port=this->memberList->item(row,1)->text().split(":");
- if(peer==AddressAndPort(QHostAddress(address_port[0]),(address_port.count()==2)?address_port[1].toUShort():default_port)) return row;
+bool mainWindow::isInMember(const AddressAndPort &peer,bool matchIPOnly){
+ QList<AddressAndPort> iplist=this->memberList->addressPortList();
+ foreach(AddressAndPort addressPort,iplist){
+ if(matchIPOnly&&peer.first==addressPort.first) return true;
+ else if(peer==addressPort) return true;
}
- return -1;
+ return false;
}
+
//Client behavior
void mainWindow::on_sendButton_clicked(){
- //TODO:Make clients and make sending process.
+ QList<AddressAndPort> addressList=this->memberList->addressPortList();
+ QVector<tcpClient *> clients(addressList.size());
+ foreach(tcpClient *client,clients) client=new tcpClient(default_buffer_size,this->setting.name(),this);
+#ifdef _OMP
+#pragma omp parallel for
+#endif
+ for(int index=0;index<addressList.size();index++) (*clients[index])<<this->sendTextEditor->html();
}
void mainWindow::on_sendFileAction_triggered(){
//TODO:Send files
this->status->showMessage(link.toString(QUrl::None));
}
settings mainWindow::app_setting() const{return this->setting;}
+
+//Implementations for main server.
+bool mainWindow::tcpserver_pending(const serverSocket &socket){
+ if(!this->isInMember(AddressAndPort(socket.peerAddress(),0),true)) return false;
+ connect(&socket,
+ SIGNAL(msg_received(const serverSocket &,const QString &)),
+ SLOT(tcpserver_msg_received(const serverSocket &,const QString &)));
+ return true;
+}
+void mainWindow::tcpserver_msg_received(const serverSocket &socket,const QString &msg){
+ this->receiveText->append(socket.header_data().senderName()+tr(" says:")+"<br />");
+ this->receiveText->append(msg);
+ this->receiveText->append("<br />");
+}
#include "../settings.h"
#include "../validator/ipaddressvalidator.h"
#include "../server/tcpserver.h"
+#include "../client/tcpclient.h"
using namespace structures;
using namespace network;
//These slots are for receiveText.
void invalidLink(const QString &);
void selectedLink(const QUrl &);
+ //These functions are for tcpclient.
+ //These functions are for tcpserver.
+ bool tcpserver_pending(const serverSocket &);
+ void tcpserver_msg_received(const serverSocket &,const QString &);
public slots:
//These are for opening stuff.
void openConfig(const QString &);
SettingDialog *settingdialog;
settings setting;
- int isInMember(const AddressAndPort &);
+ bool isInMember(const AddressAndPort &,bool matchIPOnly);
void configAndShowSettingDialog(const SettingDialog::tab);
public:
settings app_setting() const;
#include "editdelegate.h"
#include "memberlist.h"
+#define AddressIndex 1
+#define NameIndex 0
+
MemberList::MemberList(QWidget *parent):QTableWidget(parent){
this->verticalHeader()->setVisible(false);
this->verticalHeader()->setDefaultSectionSize(15);
this->horizontalHeader()->setVisible(true);
this->setItemDelegateForColumn(1,new MemberListEditDelegate(this));
}
+QList<AddressAndPort> MemberList::addressPortList() const{
+ QList<AddressAndPort> ret;
+ for(int row=0;row<this->rowCount();row++){
+ QStringList address_port_str=this->item(row,AddressIndex)->text().split(":");
+ if(address_port_str.size()<2||address_port_str[1].isEmpty()) address_port_str[1]=QString("%1").arg(default_port);
+ AddressAndPort address_port(QHostAddress(address_port_str[0]),address_port_str[1].isEmpty()?default_port:address_port_str[1].toUShort());
+ ret<<address_port;
+ }
+ return ret;
+}
+QStringList MemberList::name() const{
+ QStringList ret;
+ for(int row=0;row<this->rowCount();row++) ret<<this->item(row,NameIndex)->text();
+ return ret;
+}
void MemberList::remove_selected(){
while(this->selectedItems().size()>0&&this->selectedRanges()[0].rowCount()>0)
this->removeRow(this->selectedRanges()[0].topRow());
public slots:
void remove_selected();
void remove_all_contents();
+ QList<AddressAndPort> addressPortList() const;
+ QStringList name() const;
friend QDataStream &operator<<(QDataStream &out,const MemberList &value){
QHash<QString,AddressAndPort> AddressList;
for(int row=0;row<value.rowCount();row++){