From d0e66e7a64eb7fb8f379d8c911105b72b1769519 Mon Sep 17 00:00:00 2001 From: Hiroaki Yamamoto Date: Sun, 9 Jun 2013 18:47:39 +0900 Subject: [PATCH] Removed TcpSocketThread. Sorry, Implementing threaded socket will not be implemented. --- .directory | 2 + CMakeLists.txt | 13 +- codecounter | 2 +- definition.h | 10 +- jasmine.pro | 16 +-- jasmine.pro.user | 297 +++++++++++++++++++++++++++++++------------ jasmine.pro.user.1.3 | 311 ---------------------------------------------- jasmine.pro.user.2.1pre1 | 79 ------------ jasmine.pro.user.2.2pre5 | 167 +++++++++++++++++++++++++ jasmine.pro.user.2.5pre1 | 300 ++++++++++++++++++++++++++++++++++++++++++++ jasmine.pro.user.2.6pre1 | 242 ++++++++++++++++++++++++++++++++++++ main.cxx | 58 ++++++++- network/client.cxx | 161 +++++++++++------------- network/server.cxx | 168 +++++++++++-------------- network/tcpnetwork.cxx | 166 +------------------------ network/tcpnetwork.h | 117 ++++------------- ported_rmd6/basis.cxx | 2 +- ui/editdelegate.h | 2 +- ui/jasmine_mainwindow.cxx | 65 +++++----- ui/jasmine_mainwindow.h | 8 +- ui/memberlist.cxx | 15 +++ ui/memberlist.h | 23 +--- ui/rtfeditor.h | 2 +- ui/settingdialog.h | 2 +- 24 files changed, 1239 insertions(+), 989 deletions(-) create mode 100644 .directory delete mode 100644 jasmine.pro.user.1.3 delete mode 100644 jasmine.pro.user.2.1pre1 create mode 100644 jasmine.pro.user.2.2pre5 create mode 100644 jasmine.pro.user.2.5pre1 create mode 100644 jasmine.pro.user.2.6pre1 diff --git a/.directory b/.directory new file mode 100644 index 0000000..b0db506 --- /dev/null +++ b/.directory @@ -0,0 +1,2 @@ +[Dolphin] +Timestamp=2012,2,7,12,10,52 diff --git a/CMakeLists.txt b/CMakeLists.txt index ee3c6c5..6a61286 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,18 @@ cmake_minimum_required(VERSION 2.8) 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}) + if(CMAKE_BUILD_TYPE STREQUAL Debug) message(STATUS "Debugging mode is being enabled. This is not recommended for normal use.") add_definitions(-DDEBUG) set(CMAKE_CXX_FLAGS ${CMAKE_CXX_FLAGS} -Wall) +else(CMAKE_BUILD_TYPE STREQUAL Debug) + message(STATUS "Normal mode") endif(CMAKE_BUILD_TYPE STREQUAL Debug) +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}) #No mocs set(main main.cxx settings.cxx) set(validator diff --git a/codecounter b/codecounter index f4329f0..874bec9 100755 --- a/codecounter +++ b/codecounter @@ -1,2 +1,2 @@ #!/bin/bash -wc -l $(find . -name \*.cxx&&find . -name \*.h&&find . -name \*.res&&find . -name \*.ui&&find . -name \*.cpp&&find . -name \*.hxx&&find . -name \*.hpp&&find . -name \*.C&&find . -name \*.txt) +wc -l $(find . -path ./build -prune -o -name \*.cxx -print -o -name \*.h -print -name \*.res -print -o -name \*.ui -print -o -name \*.cpp -print -o -name \*.hxx -print -o -name \*.hpp -print -o -name \*.C -print -o -name \*.txt -print) diff --git a/definition.h b/definition.h index 4e126d0..46008f9 100644 --- a/definition.h +++ b/definition.h @@ -7,7 +7,13 @@ #define default_setting qApp->applicationDirPath().append("/setting.jst") #define default_status_interval 3000 #define default_buffer_size 1024 -#define server_msg qDebug()<<"Server:" -#define client_msg qDebug()<<"Client:" +#ifdef DEBUG + #define server_msg qDebug()<<"Server:" + #define client_msg qDebug()<<"Client:" + #define main_msg qDebug()<<"Load:" +#endif +#define jasmine_setting_extension "jst" +#define jasmine_memberlist_extension "jsm" +#define jasmine_log_plain "txt" typedef QPair AddressAndPort; typedef QPair NameAndAddrPort; diff --git a/jasmine.pro b/jasmine.pro index 7c4479e..43cc4b8 100644 --- a/jasmine.pro +++ b/jasmine.pro @@ -4,9 +4,9 @@ DEPENDPATH += . \ ui \ ui/uifiles \ res \ - network \ + network \ ported_rmd6 \ - file \ + file \ INCLUDEPATH \ += \ . @@ -23,12 +23,12 @@ HEADERS += ported_rmd6/basis.h \ ui/rtfeditor.h \ validator/ipaddressvalidator.h \ structures/header.h \ - network/tcpnetwork.h \ + network/tcpnetwork.h \ app_version.h \ settings.h \ - definition.h \ - file/QtLockedFile \ - file/qtlockedfile.h + definition.h \ + file/QtLockedFile \ + file/qtlockedfile.h FORMS += ui/uifiles/about.ui \ ui/uifiles/jasmine_main.ui \ ui/uifiles/settings.ui @@ -47,10 +47,10 @@ SOURCES += ported_rmd6/basis.cxx \ ui/rtfeditor.cxx \ validator/ipaddressvalidator.cxx \ structures/header.cxx \ - network/tcpnetwork.cxx \ + network/tcpnetwork.cxx \ network/server.cxx \ network/client.cxx \ - file/qtlockedfile.cxx \ + file/qtlockedfile.cxx \ settings.cxx \ main.cxx diff --git a/jasmine.pro.user b/jasmine.pro.user index 6f15cbe..5dbc2cb 100644 --- a/jasmine.pro.user +++ b/jasmine.pro.user @@ -1,4 +1,6 @@ + + ProjectExplorer.Project.ActiveTarget @@ -7,99 +9,236 @@ ProjectExplorer.Project.EditorSettings - System + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + true + 1 + false + 0 + true + 0 + 8 + true + 2 + true + true + false + false + ProjectExplorer.Project.PluginSettings + + + ProjectExplorer.Project.Target.0 - Desktop - Desktop - Qt4ProjectManager.Target.DesktopTarget - 0 - 0 - 0 - - - - - - QtProjectManager.QMakeBuildStep - - false + Desktop + Desktop + {26696080-ef83-42f7-9ec5-703824b15e70} + 0 + 0 + 0 + + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + false + + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + -r -w + - - - - Qt4ProjectManager.MakeStep - false - - + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + -r -w clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + /backup/hyamamoto/Documents/Workspace/jasmine-build-desktop + true + + + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + false + + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + -r -w + - 2 - Build - Build - ProjectExplorer.BuildSteps.Build + 2 + Build + + ProjectExplorer.BuildSteps.Build - - - - - Qt4ProjectManager.MakeStep - true - - clean + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r - + true + -r -w clean + - 1 - Clean - Clean - ProjectExplorer.BuildSteps.Clean + 1 + Clean + + ProjectExplorer.BuildSteps.Clean - 2 - false - - Release - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - /home/hyamamoto/Documents/Workspace/jasmine-build-desktop - 2 - 0 - true + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + /backup/hyamamoto/Documents/Workspace/jasmine-build-desktop + true - 1 - - - 0 - Deploy - Deploy - ProjectExplorer.BuildSteps.Deploy + 2 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy - 1 - No deployment - No deployment - ProjectExplorer.DefaultDeployConfiguration + 1 + No deployment + + ProjectExplorer.DefaultDeployConfiguration - 1 - - jasmine - jasmine - Qt4ProjectManager.Qt4RunConfiguration - 2 - - jasmine.pro - false - false - - false - - 3768 - true - false + 1 + + + true + + false + false + false + false + true + 0.01 + 10 + true + 25 + + true + /usr/bin/valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + jasmine + + Qt4ProjectManager.Qt4RunConfiguration:/home/hyamamoto/Documents/Workspace/jasmine/jasmine.pro + 2 + + jasmine.pro + false + false + + + 3768 + true + false + false + false - 1 + 1 @@ -112,6 +251,6 @@ ProjectExplorer.Project.Updater.FileVersion - 8 + 12 diff --git a/jasmine.pro.user.1.3 b/jasmine.pro.user.1.3 deleted file mode 100644 index 50e5f3d..0000000 --- a/jasmine.pro.user.1.3 +++ /dev/null @@ -1,311 +0,0 @@ - - - - RunConfiguration0-BaseEnvironmentBase - 2 - - - RunConfiguration0-CommandLineArguments - - - - RunConfiguration0-ProFile - jasmine.pro - - - RunConfiguration0-RunConfiguration.name - jasmine - - - RunConfiguration0-UseDyldImageSuffix - false - - - RunConfiguration0-UseTerminal - false - - - RunConfiguration0-UserEnvironmentChanges - - - - RunConfiguration0-UserSetName - false - - - RunConfiguration0-UserSetWorkingDirectory - false - - - RunConfiguration0-UserWorkingDirectory - - - - RunConfiguration0-type - Qt4ProjectManager.Qt4RunConfiguration - - - activeRunConfiguration - 0 - - - activebuildconfiguration - Release - - - buildConfiguration-Release - - Release - 2 - 0 - - 0 - - - - buildconfiguration-Release-buildstep0 - - Release - - DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-wgDBvzCe3u,guid=4c56e712291a8f6fcf95c62a0000002e - DESKTOP_SESSION=default - DISPLAY=:0.0 - DM_CONTROL=/var/run/xdmctl - GPG_AGENT_INFO=/tmp/gpg-MCQppK/S.gpg-agent:1871:1 - GS_LIB=/home/hyamamoto/.fonts - GTK2_RC_FILES=/etc/gtk-2.0/gtkrc:/home/hyamamoto/.gtkrc-2.0:/home/hyamamoto/.gtkrc-2.0-kde4:/home/hyamamoto/.kde4/share/config/gtkrc-2.0 - GTK_IM_MODULE=uim - GTK_RC_FILES=/etc/gtk/gtkrc:/home/hyamamoto/.gtkrc::/home/hyamamoto/.kde4/share/config/gtkrc - G_BROKEN_FILENAMES=1 - HISTCONTROL=erasedups - HISTSIZE=1000 - HOME=/home/hyamamoto - INPUTRC=/etc/inputrc - KDE_FULL_SESSION=true - KDE_MULTIHEAD=false - KDE_SESSION_UID=500 - KDE_SESSION_VERSION=4 - LANG=en_US.UTF-8 - LD_LIBRARY_PATH=/usr/lib/qtcreator: - LESS=-R - LOGNAME=hyamamoto - MOZ_PLUGIN_PATH=/usr/lib/mozilla/plugins - OOO_FORCE_DESKTOP=gnome - PATH=/usr/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/lib/perl5/core_perl/bin:/opt/qt/bin - PKG_CONFIG_PATH=/usr/lib/pkgconfig:/opt/qt/lib/pkgconfig - PS3=> - PS4=+ - PWD=/home/hyamamoto/Documents - QTDIR=/usr/share/qt - QT_IM_MODULE=uim - QT_PLUGIN_PATH=/home/hyamamoto/.kde4/lib/kde4/plugins/:/usr/lib/kde4/plugins/ - QT_XFT=true - SESSION_MANAGER=local/localhost:@/tmp/.ICE-unix/1912,unix/localhost:/tmp/.ICE-unix/1912 - SHELL=/bin/bash - SHLVL=1 - SSH_AGENT_PID=1874 - SSH_AUTH_SOCK=/tmp/ssh-SeeMhG1873/agent.1873 - USER=hyamamoto - WINDOWPATH=7 - XCURSOR_THEME=Oxygen_Black - XDG_CACHE_HOME=/home/hyamamoto/.cache - XDG_CONFIG_DIRS=/etc/xdg - XDG_CONFIG_HOME=/home/hyamamoto/.config - XDG_DATA_DIRS=/usr/share:/usr/local/share - XDG_DATA_HOME=/home/hyamamoto/.local/share - XDG_SESSION_COOKIE=1bbef3181df319a5eeb3839a00000393-1283300523.896579-1238674667 - XDM_MANAGED=method=classic - XMODIFIERS=@im=uim - - - /home/hyamamoto/Documents/Workspace/jasmine/jasmine.pro - -spec - linux-g++-64 - -r - - /usr/bin/qmake - false - /home/hyamamoto/Documents/Workspace/jasmine - - - - buildconfiguration-Release-buildstep1 - - Release - - DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-wgDBvzCe3u,guid=4c56e712291a8f6fcf95c62a0000002e - DESKTOP_SESSION=default - DISPLAY=:0.0 - DM_CONTROL=/var/run/xdmctl - GPG_AGENT_INFO=/tmp/gpg-MCQppK/S.gpg-agent:1871:1 - GS_LIB=/home/hyamamoto/.fonts - GTK2_RC_FILES=/etc/gtk-2.0/gtkrc:/home/hyamamoto/.gtkrc-2.0:/home/hyamamoto/.gtkrc-2.0-kde4:/home/hyamamoto/.kde4/share/config/gtkrc-2.0 - GTK_IM_MODULE=uim - GTK_RC_FILES=/etc/gtk/gtkrc:/home/hyamamoto/.gtkrc::/home/hyamamoto/.kde4/share/config/gtkrc - G_BROKEN_FILENAMES=1 - HISTCONTROL=erasedups - HISTSIZE=1000 - HOME=/home/hyamamoto - INPUTRC=/etc/inputrc - KDE_FULL_SESSION=true - KDE_MULTIHEAD=false - KDE_SESSION_UID=500 - KDE_SESSION_VERSION=4 - LANG=en_US.UTF-8 - LD_LIBRARY_PATH=/usr/lib/qtcreator: - LESS=-R - LOGNAME=hyamamoto - MOZ_PLUGIN_PATH=/usr/lib/mozilla/plugins - OOO_FORCE_DESKTOP=gnome - PATH=/usr/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/lib/perl5/core_perl/bin:/opt/qt/bin - PKG_CONFIG_PATH=/usr/lib/pkgconfig:/opt/qt/lib/pkgconfig - PS3=> - PS4=+ - PWD=/home/hyamamoto/Documents - QTDIR=/usr/share/qt - QT_IM_MODULE=uim - QT_PLUGIN_PATH=/home/hyamamoto/.kde4/lib/kde4/plugins/:/usr/lib/kde4/plugins/ - QT_XFT=true - SESSION_MANAGER=local/localhost:@/tmp/.ICE-unix/1912,unix/localhost:/tmp/.ICE-unix/1912 - SHELL=/bin/bash - SHLVL=1 - SSH_AGENT_PID=1874 - SSH_AUTH_SOCK=/tmp/ssh-SeeMhG1873/agent.1873 - USER=hyamamoto - WINDOWPATH=7 - XCURSOR_THEME=Oxygen_Black - XDG_CACHE_HOME=/home/hyamamoto/.cache - XDG_CONFIG_DIRS=/etc/xdg - XDG_CONFIG_HOME=/home/hyamamoto/.config - XDG_DATA_DIRS=/usr/share:/usr/local/share - XDG_DATA_HOME=/home/hyamamoto/.local/share - XDG_SESSION_COOKIE=1bbef3181df319a5eeb3839a00000393-1283300523.896579-1238674667 - XDM_MANAGED=method=classic - XMODIFIERS=@im=uim - - false - - -w - - /usr/bin/make - true - /home/hyamamoto/Documents/Workspace/jasmine - - - - buildconfiguration-Release-cleanstep0 - - Release - - DBUS_SESSION_BUS_ADDRESS=unix:abstract=/tmp/dbus-j0qHTciaiV,guid=79c313af903c5a3357a12e9a0000001e - DESKTOP_SESSION=default - DISPLAY=:0.0 - DM_CONTROL=/var/run/xdmctl - GPG_AGENT_INFO=/tmp/gpg-WoUHSX/S.gpg-agent:1860:1 - GS_LIB=/home/hyamamoto/.fonts - GTK2_RC_FILES=/etc/gtk-2.0/gtkrc:/home/hyamamoto/.gtkrc-2.0:/home/hyamamoto/.gtkrc-2.0-kde4:/home/hyamamoto/.kde4/share/config/gtkrc-2.0 - GTK_IM_MODULE=uim - GTK_RC_FILES=/etc/gtk/gtkrc:/home/hyamamoto/.gtkrc::/home/hyamamoto/.kde4/share/config/gtkrc - G_BROKEN_FILENAMES=1 - HISTCONTROL=erasedups - HISTSIZE=1000 - HOME=/home/hyamamoto - INPUTRC=/etc/inputrc - KDE_FULL_SESSION=true - KDE_MULTIHEAD=false - KDE_SESSION_UID=500 - KDE_SESSION_VERSION=4 - LANG=en_US.UTF-8 - LD_LIBRARY_PATH=/usr/lib/qtcreator: - LESS=-R - LOGNAME=hyamamoto - MOZ_PLUGIN_PATH=/usr/lib/mozilla/plugins - OOO_FORCE_DESKTOP=gnome - PATH=/usr/bin:/bin:/usr/bin:/sbin:/usr/sbin:/usr/lib/perl5/core_perl/bin:/opt/qt/bin - PKG_CONFIG_PATH=/usr/lib/pkgconfig:/opt/qt/lib/pkgconfig - PS3=> - PS4=+ - PWD=/home/hyamamoto/Documents - QTDIR=/usr/share/qt - QT_IM_MODULE=uim - QT_PLUGIN_PATH=/home/hyamamoto/.kde4/lib/kde4/plugins/:/usr/lib/kde4/plugins/ - QT_XFT=true - SESSION_MANAGER=local/localhost:@/tmp/.ICE-unix/1904,unix/localhost:/tmp/.ICE-unix/1904 - SHELL=/bin/bash - SHLVL=1 - SSH_AGENT_PID=1865 - SSH_AUTH_SOCK=/tmp/ssh-MOqihy1862/agent.1862 - USER=hyamamoto - WINDOWPATH=7 - XCURSOR_THEME=Oxygen_Black - XDG_CACHE_HOME=/home/hyamamoto/.cache - XDG_CONFIG_DIRS=/etc/xdg - XDG_CONFIG_HOME=/home/hyamamoto/.config - XDG_DATA_DIRS=/usr/share:/usr/local/share - XDG_DATA_HOME=/home/hyamamoto/.local/share - XDG_SESSION_COOKIE=1bbef3181df319a5eeb3839a00000393-1282952255.881690-2042795028 - XDM_MANAGED=method=classic - XMODIFIERS=@im=uim - - true - - clean - -w - - /usr/bin/make - true - /home/hyamamoto/Documents/Workspace/jasmine - true - - clean - - - - - buildconfigurations - - Release - - - - buildstep0 - - - - - - - buildstep1 - - - - - - buildsteps - - trolltech.qt4projectmanager.qmake - trolltech.qt4projectmanager.make - - - - cleanstep0 - - - true - - - - cleansteps - - trolltech.qt4projectmanager.make - - - - defaultFileEncoding - System - - - project - - - diff --git a/jasmine.pro.user.2.1pre1 b/jasmine.pro.user.2.1pre1 deleted file mode 100644 index 3fc79ee..0000000 --- a/jasmine.pro.user.2.1pre1 +++ /dev/null @@ -1,79 +0,0 @@ - - - - ProjectExplorer.Project.ActiveTarget - 0 - - - ProjectExplorer.Project.EditorSettings - - System - - - - ProjectExplorer.Project.Target.0 - - Desktop - Qt4ProjectManager.Target.DesktopTarget - 0 - 0 - - - - QtProjectManager.QMakeBuildStep - - - - - Qt4ProjectManager.MakeStep - false - - - - 2 - - - Qt4ProjectManager.MakeStep - true - - clean - - - - 1 - false - - Release - Qt4ProjectManager.Qt4BuildConfiguration - 0 - /home/hyamamoto/Documents/Workspace/jasmine-build-desktop - 2 - 0 - true - - 1 - - jasmine - Qt4ProjectManager.Qt4RunConfiguration - 2 - - jasmine.pro - false - false - - false - false - - - 1 - - - - ProjectExplorer.Project.TargetCount - 1 - - - ProjectExplorer.Project.Updater.FileVersion - 4 - - diff --git a/jasmine.pro.user.2.2pre5 b/jasmine.pro.user.2.2pre5 new file mode 100644 index 0000000..6448913 --- /dev/null +++ b/jasmine.pro.user.2.2pre5 @@ -0,0 +1,167 @@ + + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + Default + + + + ProjectExplorer.Project.Target.0 + + Desktop + + Qt4ProjectManager.Target.DesktopTarget + 0 + 0 + 0 + + + + qmake + + QtProjectManager.QMakeBuildStep + + false + + + Make + + Qt4ProjectManager.MakeStep + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + Make + + Qt4ProjectManager.MakeStep + true + + clean + + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + /backup/hyamamoto/Documents/Workspace/jasmine-build-desktop + 2 + 0 + true + + + + + qmake + + QtProjectManager.QMakeBuildStep + + false + + + Make + + Qt4ProjectManager.MakeStep + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + Make + + Qt4ProjectManager.MakeStep + true + + clean + + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + /backup/hyamamoto/Documents/Workspace/jasmine-build-desktop + 2 + 0 + true + + 2 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + No deployment + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + jasmine + + Qt4ProjectManager.Qt4RunConfiguration + 2 + + jasmine.pro + false + false + + false + + 3768 + true + false + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.EnvironmentId + {a39c6477-68bd-42e2-b34e-5002bf17ed02} + + + ProjectExplorer.Project.Updater.FileVersion + 8 + + diff --git a/jasmine.pro.user.2.5pre1 b/jasmine.pro.user.2.5pre1 new file mode 100644 index 0000000..5385c57 --- /dev/null +++ b/jasmine.pro.user.2.5pre1 @@ -0,0 +1,300 @@ + + + + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + + Cpp + + false + CppGlobal + true + false + true + false + false + false + true + true + false + true + false + false + false + true + false + + + 1 + UTF-8 + Global + 4 + true + 1 + false + false + true + + Cpp + + true + false + CppGlobal + 4 + 1 + false + true + 0 + 8 + + + + QmlJS + + true + false + QmlJSGlobal + 4 + 1 + false + true + 0 + 8 + + + 2 + 0 + 8 + true + 2 + true + true + false + false + + + + ProjectExplorer.Project.Target.0 + + Desktop + + Qt4ProjectManager.Target.DesktopTarget + 0 + 0 + 0 + + ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit./usr/bin/gdb + + + qmake + + QtProjectManager.QMakeBuildStep + false + false + + false + + + Make + + Qt4ProjectManager.MakeStep + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + Make + + Qt4ProjectManager.MakeStep + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + /backup/hyamamoto/Documents/Workspace/jasmine-build-desktop + 2 + true + + + ProjectExplorer.ToolChain.Gcc:/usr/bin/g++.x86-linux-generic-elf-64bit./usr/bin/gdb + + + qmake + + QtProjectManager.QMakeBuildStep + false + false + + false + + + Make + + Qt4ProjectManager.MakeStep + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + Make + + Qt4ProjectManager.MakeStep + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + /backup/hyamamoto/Documents/Workspace/jasmine-build-desktop + 2 + true + + 2 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + No deployment + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + true + + + false + false + false + false + false + false + false + false + true + true + 0.01 + 0.01 + 10 + 10 + true + true + 25 + 25 + + + true + true + /usr/bin/valgrind + /usr/bin/valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + jasmine + + Qt4ProjectManager.Qt4RunConfiguration + 2 + + jasmine.pro + false + false + + + 3768 + true + false + false + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.EnvironmentId + {a39c6477-68bd-42e2-b34e-5002bf17ed02} + + + ProjectExplorer.Project.Updater.FileVersion + 10 + + diff --git a/jasmine.pro.user.2.6pre1 b/jasmine.pro.user.2.6pre1 new file mode 100644 index 0000000..849b988 --- /dev/null +++ b/jasmine.pro.user.2.6pre1 @@ -0,0 +1,242 @@ + + + + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + CppGlobal + + + + QmlJS + + QmlJSGlobal + + + 2 + UTF-8 + false + 4 + false + true + 1 + false + 0 + true + 0 + 8 + true + 2 + true + true + false + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop + + Qt4ProjectManager.Target.DesktopTarget + 0 + 0 + 0 + + ProjectExplorer.ToolChain.Gcc:{f873b002-c9ab-4fa2-b8c4-03fea472d076} + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + false + + false + + + true + Make + + Qt4ProjectManager.MakeStep + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + /backup/hyamamoto/Documents/Workspace/jasmine-build-desktop + 2 + true + + + ProjectExplorer.ToolChain.Gcc:{f873b002-c9ab-4fa2-b8c4-03fea472d076} + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + false + + false + + + true + Make + + Qt4ProjectManager.MakeStep + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + /backup/hyamamoto/Documents/Workspace/jasmine-build-desktop + 2 + true + + 2 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + No deployment + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + + false + false + false + false + true + 0.01 + 10 + true + 25 + + true + /usr/bin/valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + jasmine + + Qt4ProjectManager.Qt4RunConfiguration + 2 + + jasmine.pro + false + false + + + 3768 + true + false + false + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.EnvironmentId + {a39c6477-68bd-42e2-b34e-5002bf17ed02} + + + ProjectExplorer.Project.Updater.FileVersion + 11 + + diff --git a/main.cxx b/main.cxx index 068e6f3..8793339 100644 --- a/main.cxx +++ b/main.cxx @@ -6,7 +6,10 @@ #include "definition.h" QString Non_public_title(QObject::tr("Warning! This software is not public version!")), - Non_public_body(QObject::tr("This software is not public version. So, please note that many bugs may exist and many features are not implemented.")); + Non_public_body(QObject::tr("This software is not public version. So, please note that many bugs may exist and many features are not implemented.")), + readingError_title(QObject::tr("Reading Error")), + readingError_body(QObject::tr("File %1 couldn't be read. Instead, this software reads a normal file if it exists.")); +enum ExtType{none,jsm,jst,both} loaded_ext=none,ext_type=none; int main(int argc,char* argv[]){ QApplication app(argc,argv); @@ -16,11 +19,56 @@ int main(int argc,char* argv[]){ translator.load(app.applicationName()+"-"+QLocale::system().name(),qApp->applicationDirPath()+"/translators"); app.installTranslator(&translator); mainWindow window; + + QFileInfo settingInfo(default_setting),listInfo(default_memberlist); if(rev==0) QMessageBox::warning(NULL,Non_public_title,Non_public_body); - QFileInfo memberlist(default_memberlist),setting(default_setting); - if(setting.exists()){ - window.openConfig(default_setting); - if(memberlist.exists()&&!window.app_setting().noloadMemberList()) window.openMember(default_memberlist); + for(char **arg=argv+1;arg3)?3:argc);arg++){ + QString filePath(*arg); + QFileInfo file(filePath); +#ifdef DEBUG + main_msg<<"A file argument is recognized. The extension is:"<event=tcpSocket::Header; break; case tcpSocket::Header: - this->event=(this->head_data.fileName().isNull()?tcpSocket::Msg:tcpSocket::File); + this->event=tcpSocket::Data; break; default: this->event=tcpSocket::End; @@ -48,11 +48,9 @@ bool tcpSocket::client_process_event(){ case tcpSocket::Header: result=this->client_send_header(); break; - case tcpSocket::Msg: - result=this->client_send_msg(); + case tcpSocket::Data: + result=this->client_send_data(); break; - case tcpSocket::File: - result=this->client_send_file(); case tcpSocket::End: emit this->sentData(); result=true; @@ -70,22 +68,42 @@ bool tcpSocket::client_flush(){ } bool tcpSocket::client_send_size(){ - this->head_data=header(this->senderName,this->msg); + switch(this->_mode){ + case tcpSocket::Msg: + this->head_data=header(this->senderName,this->msg); + break; + case tcpSocket::File: + this->head_data=header(this->senderName,this->src_file); + break; + default: + this->setErrorString(tr("No such mode:%1").arg(this->_mode)); + emit this->error(QAbstractSocket::UnknownSocketError); + this->abort(); + return false; + } + QDataStream datastream(&this->tmp_buffer,QIODevice::WriteOnly); datastream<head_data; quint16 size=(quint16)this->tmp_buffer.size(); this->write((char*)&size,sizeof(size)); - if(!this->client_flush()) return false; + if(!this->client_flush()){ + this->abort(); + return false; + } #ifdef DEBUG client_msg<<"size of header has been sent successfully. The size is:"<sentHeader(); this->client_move_section(); return true; } bool tcpSocket::client_send_header(){ this->write(this->tmp_buffer); - if(!this->client_flush()) return false; + if(!this->client_flush()){ + this->abort(); + return false; + } #ifdef DEBUG client_msg<<"header has been sent successfully."; #endif @@ -93,30 +111,54 @@ bool tcpSocket::client_send_header(){ return true; } -bool tcpSocket::client_send_msg(){ - QBuffer memoryStream(&this->msg); - if(!memoryStream.open(QIODevice::ReadOnly)){ - this->setErrorString(tr("Memory Stream couldn't open.")); - emit this->error(QAbstractSocket::UnknownSocketError); - return false; - } - while(this->write(memoryStream.read(this->buffer_size))>0) - if(!this->client_flush()){ +bool tcpSocket::client_send_data(){ + QBuffer memoryStream(&this->msg); + QtLockedFile file(this->src_file.fileName()); + switch(this->_mode){ + case tcpSocket::Msg: + file.deleteLater(); + if(!memoryStream.open(QIODevice::ReadOnly)){ + this->setErrorString(tr("Memory Stream couldn't open.")); + emit this->error(QAbstractSocket::UnknownSocketError); + this->abort(); + return false; + } + while(this->write(memoryStream.read(this->buffer_size))>0) + if(!this->client_flush()){ + memoryStream.close(); + this->abort(); + return false; + } memoryStream.close(); + #ifdef DEBUG + client_msg<<"data has been sent successfully."; + #endif + break; + case tcpSocket::File: + memoryStream.deleteLater(); + if(!file.open(QIODevice::ReadOnly)){ + this->setErrorString(tr("The file stream couldn't open.")); + emit this->error(QAbstractSocket::UnknownSocketError); + this->abort(); + return false; + } + file.lock(QtLockedFile::ReadLock); + while(this->write(file.read(this->buffer_size))>0&&!this->check_canceled()){ + if(!this->client_flush())break; + emit this->sending_file_progress(file.pos()); + } + file.unlock(); + file.close(); + break; + default: + this->setErrorString(tr("No such mode:%1").arg(this->_mode)); + this->abort(); return false; } - memoryStream.close(); -#ifdef DEBUG - client_msg<<"data has been sent successfully."; -#endif this->client_move_section(); return true; } -bool tcpSocket::client_send_file(){ -return false; -} - void tcpSocket::client_receive_flag(){ if(this->bytesAvailable()<4) return; QByteArray data=this->readAll(); @@ -141,74 +183,21 @@ tcpSocket &tcpSocket::operator<<(const QString &msg){ return (*this); } this->msg=msg.toUtf8(); + this->_mode=tcpSocket::Msg; this->event=tcpSocket::Size; this->client_process_event(); return (*this); } tcpSocket &tcpSocket::operator<<(const QFileInfo &src_file){ - this->src_file=src_file; - QtLockedFile file(src_file.fileName()); - if(!this->state()!=QAbstractSocket::ConnectedState)return (*this); - this->head_data=header(this->senderName,QFileInfo(file)); - QByteArray tmp_buffer; - QDataStream datastream(tmp_buffer); - quint16 size=(quint16)tmp_buffer.size(); - datastream<head_data; - this->write((char*)&size,sizeof(size)/sizeof(char)); - if(!this->flush())return (*this); - this->write(tmp_buffer); - if(!this->flush())return (*this); - tmp_buffer.clear(); - emit this->file_header_sent(); - if(!file.open(QIODevice::ReadOnly)){ - this->setErrorString(tr("The file stream couldn't open.")); - emit this->error(QAbstractSocket::UnknownSocketError); + if(this->state()!=QAbstractSocket::ConnectedState){ + this->setErrorString(tr("Haven't been connecting yet.")); + emit this->error(QAbstractSocket::NetworkError); return (*this); } - file.lock(QtLockedFile::ReadLock); - while(this->write(file.read(this->buffer_size))>0&&!this->check_canceled()){ - if(!this->flush())return (*this); - emit this->sending_file_progress(file.pos()); - } - file.unlock(); - file.close(); - emit this->sentData(); - return (*this); -} - -//Threaded TCP socket (for client) implementation -threadedTcpSocket::threadedTcpSocket(const AddressAndPort &to,const QString &senderName, const quint64 buffersize, QObject *parent):QThread(parent){ - connect(this,SIGNAL(finished()),SLOT(deleteLater())); - connect(this,SIGNAL(terminated()),SLOT(deleteLater())); - this->locks[threadedTcpSocket::Mode].lockForWrite(); - this->locks[threadedTcpSocket::SenderName].lockForWrite(); - this->locks[threadedTcpSocket::BufferSize].lockForWrite(); - this->locks[threadedTcpSocket::RWMode].lockForWrite(); - this->locks[threadedTcpSocket::AddrAndPort].lockForWrite(); - this->_addrPort=to; - this->mode=threadedTcpSocket::Client; - this->_senderName=senderName; - this->_buffersize=buffersize; - this->open_mode=QAbstractSocket::ReadWrite; - this->locks[threadedTcpSocket::Mode].unlock(); - this->locks[threadedTcpSocket::SenderName].unlock(); - this->locks[threadedTcpSocket::BufferSize].unlock(); - this->locks[threadedTcpSocket::RWMode].unlock(); - this->locks[threadedTcpSocket::AddrAndPort].unlock(); -} -//Implementation of threadedTcpSocket -threadedTcpSocket &threadedTcpSocket::operator<<(const QString &msg){ - this->locks[threadedTcpSocket::Msg].lockForWrite(); - this->_msg=msg; - this->locks[threadedTcpSocket::Msg].unlock(); - this->start(); - return (*this); -} -threadedTcpSocket &threadedTcpSocket::operator<<(const QFileInfo &file){ - this->locks[threadedTcpSocket::File].lockForWrite(); - this->_file=file; - this->locks[threadedTcpSocket::File].unlock(); - this->start(); + this->src_file=src_file; + this->_mode=tcpSocket::File; + this->event=tcpSocket::Size; + this->client_process_event(); return (*this); } diff --git a/network/server.cxx b/network/server.cxx index 30c738e..7f28e2d 100644 --- a/network/server.cxx +++ b/network/server.cxx @@ -11,25 +11,16 @@ using namespace std; tcpServer::tcpServer(quint64 buffersize, QObject *parent):QTcpServer(parent){this->buffersize=buffersize;} void tcpServer::incomingConnection(int handle){ - threadedTcpSocket *socket=new threadedTcpSocket(this->buffersize,this); - connect(socket,SIGNAL(pending()),SLOT(socket_pending())); - socket->socketDescriptor(handle); - socket->start(); - emit this->newConnection(); -} -bool tcpServer::socket_pending(){ -#ifdef DEBUG - server_msg<<"CALL:socket_pending"; -#endif - threadedTcpSocket *socket=qobject_cast(this->sender()); - if(!emit this->pending(AddressAndPort(socket->peerAddr().first,socket->peerAddr().second))){ + tcpSocket *socket=new tcpSocket(this->buffersize,this); + socket->setSocketDescriptor(handle); + if(!emit this->pending(*socket)){ #ifdef DEBUG - server_msg<<"A client accessed, but refused because user didn't accept."; + server_msg<<"A client connected to this server, however it was rejected because the client was not listed on memberlist."; #endif - return false; + socket->abort(); + return; } - emit this->socket_accepted(*socket); - return true; + emit this->newConnection(); } //Tcp socket implementation @@ -57,8 +48,7 @@ void tcpSocket::read_data(){ switch(this->event){ case tcpSocket::Size: this->size_event(); break; case tcpSocket::Header: this->header_event(); break; - case tcpSocket::Msg: this->msg_event(); break; - case tcpSocket::File: this->file_event(); break; + case tcpSocket::Data: this->data_event(); break; default: this->disconnectFromHost(); return; } } @@ -68,7 +58,7 @@ void tcpSocket::move_next_section(const qint64 size){ switch(this->event){ case tcpSocket::Size: this->event=tcpSocket::Header; break; case tcpSocket::Header: - this->event=(this->head_data.fileName().isEmpty()?tcpSocket::Msg:tcpSocket::File); + this->event=tcpSocket::Data; break; default: this->event=tcpSocket::End; @@ -82,6 +72,7 @@ void tcpSocket::send_flag(const Flag flag){ if(!this->flush()){ this->setErrorString(tr("Accept signal couldn't be sent.")); emit this->error(QAbstractSocket::UnknownSocketError); + this->abort(); return; } #ifdef DEBUG @@ -108,7 +99,7 @@ void tcpSocket::header_event(){ if(this->head_data==structures::header()){ this->setErrorString(tr("The header is empty.")); emit this->error(QAbstractSocket::UnknownSocketError); - this->disconnectFromHost(); + this->abort(); return; } if(!this->head_data.fileName().isEmpty()){ @@ -119,97 +110,78 @@ void tcpSocket::header_event(){ this->setErrorString(tr("The filename is empty.")); emit this->error(QAbstractSocket::UnknownSocketError); - this->disconnectFromHost(); + this->abort(); return; } - } + this->_mode=tcpSocket::File; + }else this->_mode=tcpSocket::Msg; emit this->header_received(); } //this->send_flag(tcpSocket::accepted); this->move_next_section(0); } -void tcpSocket::msg_event(){ - if((quint64)this->bytesAvailable()header_data().datasize()) return; - quint64 final_readsize=this->head_data.datasize()%this->buffer_size, - read_count=(this->head_data.datasize()-final_readsize)/this->buffer_size; - QByteArray msg; - for(quint64 count=0;countcheck_canceled())return; - msg+=this->read(this->buffer_size); - } - if(this->check_canceled())return; - msg+=this->read(final_readsize); - - rmd6 generator; - if(this->head_data.ripemd160()==generator.compute_hash(msg)){ - emit this->msg_received(QString::fromUtf8(msg.data())); - } - else{ -#ifdef DEBUG - qDebug()<<"Hash digest error. the received message may be broken or modified."; - qDebug()<<"this->head_date.ripemd160():"<head_data.ripemd160(); - qDebug()<<"RIPEMD160-Hash"<setErrorString(tr("The data has been broken.")); - emit this->error(QAbstractSocket::UnknownSocketError); - } - //this->send_flag(tcpSocket::accepted); - this->move_next_section(0); -} -void tcpSocket::file_event(){ +void tcpSocket::data_event(){ if((quint64)this->bytesAvailable()header_data().datasize()) return; quint64 final_readsize=this->head_data.datasize()%this->buffer_size, read_count=(this->head_data.datasize()-final_readsize)/this->buffer_size; - streamopen: - if(this->where_to_save.isEmpty()){ - this->setErrorString(tr("The filename is empty.")); - emit this->error(QAbstractSocket::UnknownSocketError); - this->disconnectFromHost(); - return; - } QFile file(this->where_to_save,this); - if(!file.open(QIODevice::Truncate|QIODevice::WriteOnly)){ - this->where_to_save=emit this->fileStream_openFailed(file.error(),file.errorString()); - goto streamopen; - } - for(quint64 count=0;countcheck_canceled();count++){ - if(this->check_canceled())return; - file.write(this->read(this->buffer_size)); - emit this->file_receive_progress(file.pos()); - } - if(this->check_canceled())return; - file.write(this->read(final_readsize)); - emit this->file_receive_progress(file.pos()); - file.close(); - rmd6 generator; - if(this->head_data.ripemd160()==generator.compute_hash(file)) - emit this->file_saved(); - else{ - this->setErrorString(tr("The file has been broken.")); - emit this->error(QAbstractSocket::UnknownSocketError); + switch(this->_mode){ + case tcpSocket::Msg: + file.deleteLater(); + for(quint64 count=0;countcheck_canceled()) goto end; + this->msg+=this->read(this->buffer_size); + emit this->data_receive_progress(this->msg.size()); + } + if(this->check_canceled()) goto end; + this->msg+=this->read(final_readsize); + emit this->data_receive_progress(this->msg.size()); + + if(this->head_data.ripemd160()==generator.compute_hash(this->msg)){ + emit this->data_received(); + } + else{ + #ifdef DEBUG + qDebug()<<"Hash digest error. the received message may be broken or modified."; + qDebug()<<"this->head_date.ripemd160():"<head_data.ripemd160(); + qDebug()<<"RIPEMD160-Hash"<setErrorString(tr("The data mey be broken.")); + emit this->error(QAbstractSocket::UnknownSocketError); + } + break; + case tcpSocket::File: + streamopen: + if(this->where_to_save.isEmpty()){ + this->setErrorString(tr("The filename is empty.")); + emit this->error(QAbstractSocket::UnknownSocketError); + this->abort(); + return; + } + if(!file.open(QIODevice::Truncate|QIODevice::WriteOnly)){ + this->where_to_save=emit this->fileStream_openFailed(file.error(),file.errorString()); + goto streamopen; + } + for(quint64 count=0;countcheck_canceled();count++){ + if(this->check_canceled()) goto end; + file.write(this->read(this->buffer_size)); + emit this->data_receive_progress(file.pos()); + } + if(this->check_canceled()) goto end; + file.write(this->read(final_readsize)); + emit this->data_receive_progress(file.pos()); + file.close(); + + if(this->head_data.ripemd160()==generator.compute_hash(file)) + emit this->data_received(); + else{ + this->setErrorString(tr("The file has been broken.")); + emit this->error(QAbstractSocket::UnknownSocketError); + } + break; } + end: //this->send_flag(tcpSocket::accepted); this->move_next_section(0); } -void threadedTcpSocket::header_received(){ - tcpSocket *socket=qobject_cast(this->sender()); - this->locks[threadedTcpSocket::HeaderData].lockForWrite(); - this->_header=socket->header_data(); - this->locks[threadedTcpSocket::HeaderData].unlock(); -} - -//Threaded TCP socket (for server) implemantation -threadedTcpSocket::threadedTcpSocket(const quint64 buffersize, QObject *parent):QThread(parent){ - connect(this,SIGNAL(finished()),SLOT(deleteLater())); - connect(this,SIGNAL(terminated()),SLOT(deleteLater())); - this->locks[threadedTcpSocket::Mode].lockForWrite(); - this->locks[threadedTcpSocket::BufferSize].lockForWrite(); - this->locks[threadedTcpSocket::RWMode].lockForWrite(); - this->mode=threadedTcpSocket::Session; - this->_buffersize=buffersize; - this->open_mode=QAbstractSocket::ReadWrite; - this->locks[threadedTcpSocket::Mode].unlock(); - this->locks[threadedTcpSocket::BufferSize].unlock(); - this->locks[threadedTcpSocket::RWMode].unlock();; -} diff --git a/network/tcpnetwork.cxx b/network/tcpnetwork.cxx index 4ae3d78..ad309d1 100644 --- a/network/tcpnetwork.cxx +++ b/network/tcpnetwork.cxx @@ -7,7 +7,6 @@ using namespace enc_hash; using namespace structures; using namespace std; - void tcpSocket::disconnectFromHostImplementation(){ this->canceled=true; QTcpSocket::disconnectFromHost(); @@ -24,170 +23,9 @@ void tcpSocket::error_occured(const QAbstractSocket::SocketError err){ Q_UNUSED(err) qDebug()<<"Error("<errorString(); this->abort(); - } void tcpSocket::cancel(){this->canceled=true;} QString tcpSocket::path_to_save() const{return this->where_to_save;} +QString tcpSocket::message() const{return QString::fromUtf8(this->msg);} header tcpSocket::header_data() const{return this->head_data;} - -/* Threaded TCP socket implementation. */ -QString threadedTcpSocket::senderName(){ - QString senderName; - this->locks[threadedTcpSocket::SenderName].lockForRead();; - senderName=this->_senderName; - this->locks[threadedTcpSocket::SenderName].unlock(); - return senderName; -} -quint64 threadedTcpSocket::buffersize(){ - quint64 size; - this->locks[threadedTcpSocket::BufferSize].lockForRead(); - size=this->_buffersize; - this->locks[threadedTcpSocket::BufferSize].unlock(); - return size; -} -AddressAndPort threadedTcpSocket::peerAddr(){ - this->locks[threadedTcpSocket::AddrAndPort].lockForRead(); - AddressAndPort r=this->_addrPort; - this->locks[threadedTcpSocket::AddrAndPort].unlock(); - return r; -} -void threadedTcpSocket::to(const AddressAndPort &to){ - this->locks[threadedTcpSocket::AddrAndPort].lockForWrite(); - this->_addrPort=to; - this->locks[threadedTcpSocket::AddrAndPort].unlock(); -} - -int threadedTcpSocket::socketDescriptor(){ - int desc; - this->locks[threadedTcpSocket::Descriptor].lockForRead(); - desc=this->_descriptor; - this->locks[threadedTcpSocket::Descriptor].unlock(); - return desc; -} - -void threadedTcpSocket::senderName(const QString &name){ - this->locks[threadedTcpSocket::SenderName].lockForWrite(); - this->_senderName=name; - this->locks[threadedTcpSocket::SenderName].unlock(); -} -void threadedTcpSocket::buffersize(const quint64 size){ - this->locks[threadedTcpSocket::BufferSize].lockForWrite();; - this->_buffersize=size; - this->locks[threadedTcpSocket::BufferSize].unlock(); -} -void threadedTcpSocket::socketDescriptor(const int descriptor){ - this->locks[threadedTcpSocket::Descriptor].lockForWrite(); - this->_descriptor=descriptor; - this->locks[threadedTcpSocket::Descriptor].unlock(); -} -QIODevice::OpenMode threadedTcpSocket::readWriteMode(){ - QIODevice::OpenMode mode; - this->locks[threadedTcpSocket::RWMode].lockForRead(); - mode=this->open_mode; - this->locks[threadedTcpSocket::RWMode].unlock(); - return mode; -} -void threadedTcpSocket::readWriteMode(const QIODevice::OpenMode openMode){ - this->locks[threadedTcpSocket::RWMode].lockForWrite(); - this->open_mode=openMode; - this->locks[threadedTcpSocket::RWMode].unlock(); -} -header threadedTcpSocket::head_data(){ - this->locks[threadedTcpSocket::HeaderData].lockForRead(); - header head=this->_header; - this->locks[threadedTcpSocket::HeaderData].unlock(); - return head; -} - -void threadedTcpSocket::run(){ -#ifdef DEBUG - qDebug()<<"threadedTcpSocket has been created and running."; -#endif - qRegisterMetaType("SocketState"); - qRegisterMetaType("SocketError"); - - this->locks[threadedTcpSocket::BufferSize].lockForRead(); - this->locks[threadedTcpSocket::SenderName].lockForRead(); - tcpSocket *socket= - (this->mode==threadedTcpSocket::Client)? - new tcpSocket(this->_senderName,this->_buffersize): - new tcpSocket(this->_buffersize); - this->locks[threadedTcpSocket::BufferSize].unlock(); - this->locks[threadedTcpSocket::SenderName].unlock(); - /*Common signals*/ - connect(socket,SIGNAL(connected()),SLOT(host_connected()),Qt::BlockingQueuedConnection); - connect(socket,SIGNAL(connected()),SIGNAL(connected())); -#ifdef DEBUG - connect(socket,SIGNAL(disconnected()),SLOT(host_disconnected())); -#endif - connect(socket,SIGNAL(disconnected()),SIGNAL(disconnected())); - - connect(socket,SIGNAL(hostFound()),SIGNAL(hostFound())); - connect(socket,SIGNAL(proxyAuthenticationRequired(const QNetworkProxy &,QAuthenticator*)), - SIGNAL(proxyAuthenticationRequired(const QNetworkProxy &,QAuthenticator*))); - connect(socket,SIGNAL(stateChanged(QAbstractSocket::SocketState)), - SIGNAL(stateChanged(QAbstractSocket::SocketState))); - - int descriptor; - this->locks[threadedTcpSocket::Mode].lockForRead(); - switch(this->mode){ - case threadedTcpSocket::Client: - connect(socket,SIGNAL(sentData()),SIGNAL(sentData())); - connect(socket,SIGNAL(sentData()),SLOT(quit())); - connect(socket,SIGNAL(file_header_sent()),SIGNAL(file_header_sent())); - connect(socket,SIGNAL(sending_file_progress(quint64)),SIGNAL(sending_file_progress(quint64))); - this->locks[threadedTcpSocket::AddrAndPort].lockForRead(); - socket->connectToHost(this->_addrPort.first,this->_addrPort.second); - this->locks[threadedTcpSocket::AddrAndPort].unlock(); - break; - case threadedTcpSocket::Session: - this->locks[threadedTcpSocket::Descriptor].lockForRead(); - descriptor=this->_descriptor; - this->locks[threadedTcpSocket::Descriptor].unlock(); - connect(socket,SIGNAL(msg_received(const QString &)),SIGNAL(msg_received(const QString &))); - connect(socket,SIGNAL(msg_received(const QString &)),SLOT(quit())); - - connect(socket,SIGNAL(file_receive_progress(const quint64)),SIGNAL(file_receive_progress(const quint64))); - connect(socket,SIGNAL(file_saved()),SIGNAL(file_saved())); - connect(socket,SIGNAL(file_saved()),SLOT(quit())); - connect(socket,SIGNAL(header_received()),SLOT(header_received())); - socket->setSocketDescriptor(descriptor); - this->_addrPort.first=socket->peerAddress(); - this->_addrPort.second=socket->peerPort(); - if(!emit this->pending()) socket->disconnectFromHost(); - break; - } - this->locks[threadedTcpSocket::Mode].unlock(); - if(this->exec()==0){ - socket->disconnectFromHost(); - return; - } - //Cleanup - socket->abort(); -} - -void threadedTcpSocket::host_connected(){ - tcpSocket *socket=qobject_cast(this->sender()); -#ifdef DEBUG - qDebug()<<"Client:"<peerAddress().toString()<<"has been connected properly."; -#endif - this->locks[threadedTcpSocket::Msg].lockForRead(); - if(this->_msg.isNull()){ - this->locks[threadedTcpSocket::File].lockForRead(); - (*socket)<_file; - this->locks[threadedTcpSocket::File].unlock(); - }else{ - this->locks[threadedTcpSocket::Msg].lockForRead(); - (*socket)<_msg; - this->locks[threadedTcpSocket::Msg].unlock(); - } - this->locks[threadedTcpSocket::Msg].unlock(); -} - -#ifdef DEBUG -void threadedTcpSocket::host_disconnected(){ - this->locks[threadedTcpSocket::Mode].lockForRead(); - qDebug()<<"Socket("<<((this->mode==threadedTcpSocket::Session)?"Session":"Client")<<"):Connection closed successful."; - this->locks[threadedTcpSocket::Mode].unlock(); -} -#endif +tcpSocket::Mode tcpSocket::mode() const{return this->_mode;} diff --git a/network/tcpnetwork.h b/network/tcpnetwork.h index abff1ac..0b3b10a 100644 --- a/network/tcpnetwork.h +++ b/network/tcpnetwork.h @@ -10,137 +10,64 @@ const quint64 default_bandwidth = 0x400; using namespace structures; namespace network{ class tcpSocket; - class threadedTcpSocket; + class socketThread; - class tcpServer:virtual public QTcpServer{ + class tcpServer:public QTcpServer{ Q_OBJECT public: tcpServer(quint64 buffersize=default_bandwidth,QObject *parent=NULL); signals: - bool pending(const AddressAndPort &) const; - void socket_error(const threadedTcpSocket &) const; - void socket_accepted(const threadedTcpSocket &) const; + bool pending(const tcpSocket &) const; protected: void incomingConnection(int handle); private: quint64 buffersize; - private slots: - bool socket_pending(); - }; - - class threadedTcpSocket:public QThread{ - Q_OBJECT - public: - //This constructor is for server. it works as a session. - threadedTcpSocket(const quint64 buffersize=default_bandwidth,QObject *parent=NULL); - //This constructor is for client. it works as a client. - threadedTcpSocket(const AddressAndPort &,const QString &senderName,const quint64 buffersize=default_buffer_size,QObject *parent=NULL); - /* - To access these member, accessing critical sections must be needed. - Hence, these member uses QReadWriteLock to lock them; Making constant functions is not possible. - */ - quint64 buffersize(); - QString senderName(); - AddressAndPort peerAddr(); - header head_data(); - int socketDescriptor(); - void socketDescriptor(const int); - void buffersize(const quint64); - void senderName(const QString &); - void readWriteMode(const QIODevice::OpenMode); - void to(const AddressAndPort &); - QIODevice::OpenMode readWriteMode(); - threadedTcpSocket &operator<<(const QString &); - threadedTcpSocket &operator<<(const QFileInfo &); - private: - enum Mode{Session,Client} mode; - enum lockID{ - Mode =0, - BufferSize =1, - SenderName =2, - Msg =3, - File =4, - Descriptor =5, - RWMode =6, - AddrAndPort =7, - HeaderData =8, - }; - void run(); - QIODevice::OpenMode open_mode; - QReadWriteLock locks[9]; - int _descriptor; - quint64 _buffersize; - QString _senderName,_msg; - QFileInfo _file; - AddressAndPort _addrPort; - header _header; - private slots: - void header_received(); - void host_connected(); -#ifdef DEBUG - void host_disconnected(); -#endif - signals: - QString file_pending() const; - QString fileStream_openFailed(const QFile::FileError &,const QString &) const; - - void msg_received(const QString &) const; - - void file_receive_progress(const quint64 streamPos) const; - void file_saved() const; - bool pending() const; - - void sentData(); - void file_header_sent(); - void sending_file_progress(const quint64 pos); + } typedef TcpServer; - void connected(); - void disconnected(); - void hostFound(); - void proxyAuthenticationRequired(const QNetworkProxy &,QAuthenticator *); - void stateChanged(QAbstractSocket::SocketState); - }; class tcpSocket:public QTcpSocket{ Q_OBJECT public: - //This constructor is for server. it works as a session. + //This constructor is for servers. it works as a session. tcpSocket(const quint64 buffersize=default_bandwidth,QObject *parent=NULL); - //This constructor is for client. it works as a client. + //This constructor is for clients. it works as a client. tcpSocket(const QString &senderName,const quint64 buffersize=default_buffer_size,QObject *parent=NULL); + enum Mode{Msg,File}; + + Mode mode() const; QString path_to_save() const; + QString message() const; structures::header header_data() const; tcpSocket &operator<<(const QString &), &operator<<(const QFileInfo &); + public slots: + void cancel(); signals: QString file_pending() const; QString fileStream_openFailed(const QFile::FileError &,const QString &) const; void header_received() const; - void msg_received(const QString &) const; - - void file_receive_progress(const quint64 streamPos) const; - void file_saved() const; + void data_receive_progress(const quint64 streamPos) const; + void data_received() const; void sentData() const; - void file_header_sent() const; + void sentHeader() const; void sending_file_progress(const quint64 pos) const; protected: void disconnectFromHostImplementation(); private: + enum Mode _mode; enum section { Size, Header, - Msg, - File, + Data, End } event; enum Flag {accepted=0,refused=1}; void size_event(); void header_event(); - void msg_event(); - void file_event(); + void data_event(); bool check_canceled(); void client_move_section(); @@ -148,12 +75,11 @@ namespace network{ bool client_flush(); bool client_send_size(); bool client_send_header(); - bool client_send_msg(); - bool client_send_file(); + bool client_send_data(); //The size of header needs to be larger than 0, and smaller than or equal to 0xFFFF. quint16 header_size,buffer_size,timeout_time; - structures::header head_data; + header head_data; bool canceled; QString where_to_save, senderName; //These classes are only used for client to store serialized header data. @@ -163,11 +89,10 @@ namespace network{ void read_data(); void move_next_section(const qint64); void send_flag(const Flag flag); - void cancel(); void error_occured(const QAbstractSocket::SocketError); void client_receive_flag(); - }; + } typedef TcpSocket; } Q_DECLARE_METATYPE(QAbstractSocket::SocketState) Q_DECLARE_METATYPE(QAbstractSocket::SocketError) diff --git a/ported_rmd6/basis.cxx b/ported_rmd6/basis.cxx index 2807e8a..a52fdc3 100644 --- a/ported_rmd6/basis.cxx +++ b/ported_rmd6/basis.cxx @@ -20,7 +20,7 @@ QVector hash_basis::__compute_hash(context_basis &context,QIODevice &st QByteArray data; while(!stream.atEnd()){ data=stream.read(0x100); - for(quint32 i=0;i<(data.size()>>6);i++){ + for(int i=0;i<(data.size()>>6);i++){ memcpy(context.X,((quint32*)data.data())+(16*i),sizeof(context.X)); this->compress(context); } diff --git a/ui/editdelegate.h b/ui/editdelegate.h index d402cdc..6f20ea5 100644 --- a/ui/editdelegate.h +++ b/ui/editdelegate.h @@ -3,7 +3,7 @@ #include #include"../validator/ipaddressvalidator.h" -class MemberListEditDelegate:virtual public QItemDelegate{ +class MemberListEditDelegate:public QItemDelegate{ Q_OBJECT public: MemberListEditDelegate(QObject *parent=NULL); diff --git a/ui/jasmine_mainwindow.cxx b/ui/jasmine_mainwindow.cxx index fbd95dd..2968aa5 100644 --- a/ui/jasmine_mainwindow.cxx +++ b/ui/jasmine_mainwindow.cxx @@ -37,8 +37,9 @@ mainWindow::mainWindow(){ //I'll reimpletemt the format of this memberlist file... connect(this->sendFileButton,SIGNAL(clicked()),SLOT(on_sendFileAction_triggered())); - memberFilters<sendButton->setEnabled(false); @@ -53,10 +54,8 @@ mainWindow::mainWindow(){ 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 AddressAndPort &)), - SLOT(tcpserver_pending(const AddressAndPort &))); - connect(this->mainServer,SIGNAL(socket_accepted(const threadedTcpSocket &)), - SLOT(tcpserver_accepted(const threadedTcpSocket &))); + connect(this->mainServer,SIGNAL(pending(const tcpSocket &)), + SLOT(tcpserver_pending(const tcpSocket &))); } mainWindow::~mainWindow(){} void mainWindow::closeEvent(QCloseEvent *event){ @@ -77,17 +76,23 @@ void mainWindow::on_sendButton_clicked(){ #pragma omp parallel for #endif for(int index=0;indexsetting.name(),default_buffer_size,this); + tcpSocket *client=new tcpSocket(this->setting.name(),default_buffer_size,this); connect(client,SIGNAL(sentData()),SLOT(sentData())); - (*client)<sendTextEditor->html(); + connect(client,SIGNAL(connected()),SLOT(connected())); + client->connectToHost(addressList[index].first,addressList[index].second); } } +void mainWindow::connected(){ + tcpSocket *client=qobject_cast(this->sender()); + (*client)<sendTextEditor->html(); +} void mainWindow::on_sendFileAction_triggered(){ //TODO:Send files } void mainWindow::sentData(){ + tcpSocket *socket=qobject_cast(this->sender()); + socket->disconnectFromHost(); this->receiveText->append(setting.name()+"("+tr("me")+")"+tr(" says:")); this->receiveText->append(this->sendTextEditor->html()); this->receiveText->append("
"); @@ -134,29 +139,32 @@ void mainWindow::on_miscAction_triggered(){configAndShowSettingDialog(SettingDia void mainWindow::on_saveConfigAction_triggered(){ QFileDialog dialog(this,Qt::Dialog); dialog.setWindowTitle(save_setting_title); - dialog.setNameFilter("Jasmine setting file (*.jst)"); + dialog.setFilters(this->settingFilters); dialog.setAcceptMode(QFileDialog::AcceptSave); connect(&dialog,SIGNAL(fileSelected(const QString &)),SLOT(saveConfig(const QString &))); dialog.exec(); + dialog.deleteLater(); } void mainWindow::on_openConfigAction_triggered(){ QFileDialog dialog(this,Qt::Dialog); dialog.setWindowTitle(open_setting_title); - dialog.setNameFilter("Jasmine setting file (*.jst)"); + dialog.setFilters(this->settingFilters); dialog.setAcceptMode(QFileDialog::AcceptOpen); connect(&dialog,SIGNAL(fileSelected(const QString &)),SLOT(openConfig(const QString &))); dialog.exec(); + dialog.deleteLater(); } void mainWindow::on_openMemberListAction_triggered(){ - QFileDialog *dialog=new QFileDialog(this,open_memberlist_title,"",this->memberFilters.join(";;")); - dialog->setAcceptMode(QFileDialog::AcceptOpen); - connect(dialog,SIGNAL(fileSelected(const QString &)),SLOT(openMember(const QString &))); - dialog->exec(); - delete dialog; + QFileDialog dialog(this,open_memberlist_title,""); + dialog.setFilters(this->memberFilters); + dialog.setAcceptMode(QFileDialog::AcceptOpen); + connect(&dialog,SIGNAL(fileSelected(const QString &)),SLOT(openMember(const QString &))); + dialog.exec(); + dialog.deleteLater(); } void mainWindow::on_saveMemberListAction_triggered(){ @@ -167,6 +175,7 @@ void mainWindow::on_saveMemberListAction_triggered(){ connect(&dialog,SIGNAL(fileSelected(const QString &)),SLOT(saveMember(const QString &))); dialog.exec(); + dialog.deleteLater(); } void mainWindow::on_saveLogAction_triggered(){ @@ -177,6 +186,7 @@ void mainWindow::on_saveLogAction_triggered(){ connect(&dialog,SIGNAL(fileSelected(const QString &)),SLOT(saveLog(const QString &))); dialog.exec(); + dialog.deleteLater(); } void mainWindow::on_aboutAction_triggered(){ about aboutDialog(this); @@ -280,23 +290,20 @@ void mainWindow::selectedLink(const QUrl &link){ settings mainWindow::app_setting() const{return this->setting;} //Main server -bool mainWindow::tcpserver_pending(const AddressAndPort &addr){ +bool mainWindow::tcpserver_pending(const tcpSocket &socket){ #ifdef DEBUG - qDebug()<<"Pending:"<memberList->isInMember(addr,true)>=0; -} -void mainWindow::tcpserver_accepted(const threadedTcpSocket &socket){ connect(&socket, - SIGNAL(msg_received(const QString &)), - SLOT(tcpserver_msg_received(const QString &))); + SIGNAL(data_received()), + SLOT(tcpserver_data_received())); + return this->memberList->isInMember(AddressAndPort(socket.peerAddress(),socket.peerPort()),true)>=0; } -void mainWindow::tcpserver_msg_received(const QString &msg){ - threadedTcpSocket *sender=qobject_cast(this->sender()); - this->receiveText->append(sender->head_data().senderName()+ - "("+this->memberList->name(AddressAndPort(sender->peerAddr().first,0),true)+", "+sender->peerAddr().first.toString()+")"+tr(" says:")); - this->receiveText->append(msg); +void mainWindow::tcpserver_data_received(){ + tcpSocket *socket=qobject_cast(this->sender()); + this->receiveText->append(socket->header_data().senderName()+ + "("+this->memberList->name(AddressAndPort(socket->peerAddress(),0),true)+", "+socket->peerAddress().toString()+")"+tr(" says:")); + this->receiveText->append(socket->message()); this->receiveText->append("
"); - sender->quit(); } diff --git a/ui/jasmine_mainwindow.h b/ui/jasmine_mainwindow.h index 5332c5a..0c963df 100644 --- a/ui/jasmine_mainwindow.h +++ b/ui/jasmine_mainwindow.h @@ -46,10 +46,10 @@ private slots: void selectedLink(const QUrl &); //These functions are for tcpclient. void sentData(); + void connected(); //These functions are for tcpserver. - bool tcpserver_pending(const AddressAndPort &); - void tcpserver_accepted(const threadedTcpSocket &); - void tcpserver_msg_received(const QString &); + bool tcpserver_pending(const tcpSocket &); + void tcpserver_data_received(); public slots: //These are for opening stuff. void openConfig(const QString &); @@ -60,7 +60,7 @@ protected: void showEvent(QShowEvent *); private: QObject *beforesender; - QStringList memberFilters,logFilters; + QStringList memberFilters,logFilters,settingFilters; MemberList *memberList; RtfEditor *sendTextEditor; diff --git a/ui/memberlist.cxx b/ui/memberlist.cxx index 2638d99..8d31a0a 100644 --- a/ui/memberlist.cxx +++ b/ui/memberlist.cxx @@ -54,3 +54,18 @@ void MemberList::keyReleaseEvent(QKeyEvent *event){ event->ignore(); }else event->accept(); } +QDataStream &operator>>(QDataStream &in, MemberList &value){ + QList AddressList; + in>>AddressList; + value.remove_all_contents(); + foreach(NameAndAddrPort addressList,AddressList){ + QTableWidgetItem *name=new QTableWidgetItem(addressList.first), + *AddressPort=new QTableWidgetItem(QString("%1:%2"). + arg(addressList.second.first.toString()). + arg(addressList.second.second)); + value.insertRow(value.rowCount()); + value.setItem(value.rowCount()-1,NameIndex,name); + value.setItem(value.rowCount()-1,AddressIndex,AddressPort); + } + return in; +} diff --git a/ui/memberlist.h b/ui/memberlist.h index 5c469d4..3637471 100644 --- a/ui/memberlist.h +++ b/ui/memberlist.h @@ -3,9 +3,9 @@ #include #include "../definition.h" -#define AddressIndex 1 -#define NameIndex 0 -class MemberList:virtual public QTableWidget{ +const int AddressIndex=1; +const int NameIndex=0; +class MemberList:public QTableWidget{ Q_OBJECT public: MemberList(QWidget *parent=NULL); @@ -25,22 +25,9 @@ public slots: return out; } - friend QDataStream &operator>>(QDataStream &in, MemberList &value){ - QList AddressList; - in>>AddressList; - value.remove_all_contents(); - foreach(NameAndAddrPort addressList,AddressList){ - QTableWidgetItem *name=new QTableWidgetItem(addressList.first), - *AddressPort=new QTableWidgetItem(QString("%1:%2"). - arg(addressList.second.first.toString()). - arg(addressList.second.second)); - value.insertRow(value.rowCount()); - value.setItem(value.rowCount()-1,NameIndex,name); - value.setItem(value.rowCount()-1,AddressIndex,AddressPort); - } - return in; - } + friend QDataStream &operator>>(QDataStream &in, MemberList &value); private: void keyReleaseEvent(QKeyEvent *); }; +QDataStream &operator>>(QDataStream &in, MemberList &value); diff --git a/ui/rtfeditor.h b/ui/rtfeditor.h index 21df136..b756830 100644 --- a/ui/rtfeditor.h +++ b/ui/rtfeditor.h @@ -1,6 +1,6 @@ #pragma once #include -class RtfEditor:virtual public QWidget{ +class RtfEditor:public QWidget{ Q_OBJECT Q_PROPERTY(QString html READ html WRITE html) Q_PROPERTY(QString plain READ plain WRITE plain) diff --git a/ui/settingdialog.h b/ui/settingdialog.h index 6656858..07d9eff 100644 --- a/ui/settingdialog.h +++ b/ui/settingdialog.h @@ -3,7 +3,7 @@ #include #include "ui_settings.h" #include "../definition.h" -class SettingDialog:virtual public QDialog,virtual private Ui::settingDialogBase{ +class SettingDialog:public QDialog,virtual private Ui::settingDialogBase{ Q_OBJECT public: enum tab{server,client,misc}; -- 2.11.0