Changeset 99 in pacpussensors for trunk/PacpusSocket


Ignore:
Timestamp:
Oct 15, 2015, 2:47:01 PM (9 years ago)
Author:
nguyenhu
Message:

compilation under linux with 0.2.X framework

Location:
trunk/PacpusSocket
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/PacpusSocket/CMakeLists.txt

    r85 r99  
     1#########################quick start############################################
     2#cmake ../ -G "CodeBlocks - Unix Makefiles"
     3#make
     4#make install
     5#make clean
     6################################################################################
    17project(PacpusSocket)
     8set(${PROJECT_NAME}_VERSION_MAJOR 0)
     9set(${PROJECT_NAME}_VERSION_MINOR 1)
     10add_definitions( -DPACPUSSOCKET_EXPORTS )
    211################################################################################
    3 add_definitions(-DPACPUSSOCKET_EXPORTS)
     12create_export(EXPORT_HDR ${PROJECT_NAME})
     13pacpus_plugin(PLUGIN_CPP PLUGIN_HDR ${PROJECT_NAME})
     14add_definitions (${QT_DEFINITIONS})
    415
    5 # ========================================
    6 # Configure qt4
    7 # ========================================
    8 if(QT4_FOUND)
    9         set(QT_USE_QTXML true)
    10         set(QT_USE_QTNETWORK true)
    11         include(${QT_USE_FILE})
    12 else()
    13         message(ERROR "Qt4 needed")
    14 endif()
    15 
    16 # ========================================
    17 # Compiler definitions
    18 # ========================================
    19 add_definitions(
    20         ${QT_DEFINITIONS}
    21 )
    22 
    23 # ========================================
    24 # Include directories
    25 # ========================================
    26 include_directories(
    27         ${PROJECT_BINARY_DIR}
    28         ${QT_INCLUDE_DIR}
     16find_package(Qt5Network REQUIRED)
     17################################################################################
     18# DIRECTORIES
     19include_directories(
     20    ${PROJECT_BINARY_DIR}
     21    ${QT_INCLUDE_DIR}
     22    ${PACPUS_INCLUDE_DIR}
     23    ${PACPUS_INCLUDE_DIR}/Pacpus/
    2924)
    3025
     
    3227# Link directories
    3328# ========================================
    34 link_directories(
     29link_directories(
     30        ${PACPUS_LIB_DIR}
    3531)
    3632
    37 pacpus_plugin(PLUGIN_CPP PLUGIN_H ${PROJECT_NAME} )
    3833
    39 # ========================================
    40 # List of sources
    41 # ========================================
    42 set(
    43     PROJECT_SRCS
    44     PacpusSocketAirplug.cpp
    45         PacpusSocketAirplug.h
    46         PacpusUDPSocket.cpp
    47         PacpusUDPSocket.h
     34################################################################################
     35# FILES
     36set(PROJECT_HDRS
     37    ${EXPORT_HDR}
     38    PacpusSocketAirplug.h
     39    PacpusUDPSocket.h
     40)
     41set(PROJECT_SRCS
    4842    ${PLUGIN_CPP}
     43    PacpusSocketAirplug.cpp
     44    PacpusUDPSocket.cpp
    4945)
    5046
    51 # ========================================
    52 # Files to MOC
    53 # ========================================
    54 set(
    55     FILES_TO_MOC
     47set(FILES_TO_MOC
     48    ${PLUGIN_HDR}
    5649    PacpusSocketAirplug.h
    57         PacpusUDPSocket.h
    58     ${PLUGIN_H}
     50    PacpusUDPSocket.h
    5951)
    6052
    61 set(
    62     UI_FILES
    63 
     53set(UI_FILES
    6454)
    6555
    66 # ========================================
    67 # Call MOC
    68 # ========================================
    69 qt4_wrap_cpp(
    70     PROJECT_MOC_SRCS
     56################################################################################
     57# Qt: call moc, uic
     58qt_wrap_cpp(PROJECT_MOC_SRCS
    7159    ${FILES_TO_MOC}
    7260)
    7361
    74 qt4_wrap_ui(
    75     PROJECT_UI_SRCS
     62qt_wrap_ui(PROJECT_UI_SRCS
    7663    ${UI_FILES}
    7764)
    7865
    79 # ========================================
    80 # Build a library
    81 # ========================================
    82 pacpus_add_library(
    83     ${PROJECT_NAME} SHARED
     66################################################################################
     67# BUILD and LINK
     68pacpus_add_library(${PROJECT_NAME} SHARED
     69    ${PROJECT_HDRS}
    8470    ${PROJECT_SRCS}
    8571    ${PROJECT_MOC_SRCS}
     
    8773)
    8874
     75
    8976# ========================================
    9077# Libraries
    9178# ========================================
    92 # All the platform
    93 target_link_libraries(
    94     ${PROJECT_NAME}
    95     ${PACPUS_LIBRARIES}
    96     ${QT_LIBRARIES}
    97         ${PACPUS_DEPENDENCIES_LIB}
     79set(LIBS
     80    optimized FileLib debug FileLib_d
     81    optimized PacpusLib debug PacpusLib_d
     82    optimized PacpusTools debug PacpusTools_d
    9883)
     84if (WIN32)
     85    list(APPEND LIBS
     86        optimized ROAD_TIME debug ROAD_TIME_d
     87    )
     88endif()
     89# LINK
     90target_link_libraries(${PROJECT_NAME}
     91                      ${PACPUS_LIBRARIES}
     92                      ${PACPUS_DEPENDENCIES_LIB}
     93                      ${LIBS}
     94                      ${QT_LIBRARIES}
     95                     )
     96qt5_use_modules(${PROJECT_NAME} Network)
     97################################################################################
     98# FOLDERS
     99pacpus_folder(${PROJECT_NAME} "components")
     100################################################################################
     101# INSTALL
     102pacpus_install(${PROJECT_NAME})
    99103
    100 # ========================================
    101 # Install
    102 # ========================================
    103 pacpus_install(${PROJECT_NAME})
     104install(
     105    DIRECTORY   ${PacpusSocket_SOURCE_DIR}
     106    DESTINATION ${PACPUS_INSTALL_DIR}/include
     107    FILES_MATCHING PATTERN "*.h"
     108)
  • trunk/PacpusSocket/PacpusUDPSocket.cpp

    r87 r99  
    55//  author:     Pierre Hudelaine
    66//              Copyright Heudiasyc UMR UTC/CNRS 7253
    7 // 
     7//
    88//  version:    $Id: $
    99//
     
    1212*********************************************************************/
    1313
    14 #include "PacpusUDPSocket.h" 
     14#include "PacpusUDPSocket.h"
    1515
    1616#include <qbuffer.h>
     
    2727// Construct the factory
    2828//////////////////////////////////////////////////////////////////////////
    29 static ComponentFactory <PacpusUDPSocket> sFactory("PacpusUDPSocket"); 
     29static ComponentFactory <PacpusUDPSocket> sFactory("PacpusUDPSocket");
    3030
    3131
     
    3434//////////////////////////////////////////////////////////////////////////
    3535PacpusUDPSocket::PacpusUDPSocket(QString name)
    36     : ComponentBase(name) 
    37 {
    38 } 
     36    : ComponentBase(name)
     37{
     38}
    3939
    4040
     
    4242// Destructor
    4343//////////////////////////////////////////////////////////////////////////
    44 PacpusUDPSocket::~PacpusUDPSocket() 
     44PacpusUDPSocket::~PacpusUDPSocket()
    4545{
    4646}
     
    5252void PacpusUDPSocket::addOutputs()
    5353{
    54         addOutput<QString, PacpusUDPSocket>("udpSocketOutput");
     54        addOutput<QString, PacpusUDPSocket>("string");
    5555}
    5656
     
    6161void PacpusUDPSocket::addInputs()
    6262{
    63         addInput<QString, PacpusUDPSocket>("udpSocketInput", &PacpusUDPSocket::sendDatagrams);
    64 }
    65 
    66 
    67 //////////////////////////////////////////////////////////////////////////
    68 // Called by the ComponentManager to pass the XML parameters to the 
    69 // component 
    70 //////////////////////////////////////////////////////////////////////////
    71 ComponentBase::COMPONENT_CONFIGURATION  PacpusUDPSocket::configureComponent(XmlComponentConfig config) 
    72 { 
     63    addInput<QString, PacpusUDPSocket>("string", &PacpusUDPSocket::sendQString);
     64}
     65
     66
     67//////////////////////////////////////////////////////////////////////////
     68// Called by the ComponentManager to pass the XML parameters to the
     69// component
     70//////////////////////////////////////////////////////////////////////////
     71ComponentBase::COMPONENT_CONFIGURATION  PacpusUDPSocket::configureComponent(XmlComponentConfig config)
     72{
    7373
    7474        socketType_ = config.getProperty("typeSocket");
    75        
     75
    7676        if (socketType_ == "client" || socketType_ == "Client")
    7777        {
    7878            address2send_.setAddress(config.getProperty("address"));
    7979            port2send_ = config.getProperty("port").toUInt();
    80             socketType_ = "client";             
     80            socketType_ = "client";
    8181        }
    8282        else if (socketType_ == "server" || socketType_ == "Server")
     
    9292            socketType_ = "client";
    9393        }
    94        
    95         return ComponentBase::CONFIGURED_OK; 
    96 } 
     94
     95        return ComponentBase::CONFIGURED_OK;
     96}
    9797
    9898
     
    100100// Called by the ComponentManager to start the component
    101101//////////////////////////////////////////////////////////////////////////
    102 void PacpusUDPSocket::startActivity() 
    103 { 
     102void PacpusUDPSocket::startActivity()
     103{
    104104        if (!(udpSocket_ = new QUdpSocket()))
    105105                qFatal("Failed to init UDP socket!");
    106  
     106
    107107        if (socketType_ == "server")
    108108        {
     
    112112                        qWarning() << "Failed to bind socket for server on port" << port2bind_;
    113113        }
    114            
     114
    115115        connect(udpSocket_, SIGNAL(readyRead()), this, SLOT(readPendingDatagrams()));
    116        
    117         updSocketOutput_ = getTypedOutput<QString, PacpusUDPSocket>("udpSocketOutput");
     116
     117        udpSocketOutput_ = getTypedOutput<QString, PacpusUDPSocket>("string");
    118118}
    119119
     
    122122// Send datagram QString
    123123//////////////////////////////////////////////////////////////////////////
    124 void PacpusUDPSocket::sendDatagrams(QString frame)
    125 { 
     124void PacpusUDPSocket::sendQString(const QString& frame)
     125{
    126126        int sent=0;
    127        
     127
    128128        if (socketType_ == "client")
    129129        {
    130             if ((sent = udpSocket_->writeDatagram(frame.toLocal8Bit(), address2send_, port2send_)) == -1) 
    131                         qDebug() << "Failed to send the frame: " << address2send_ << port2send_ << frame << endl; 
     130            if ((sent = udpSocket_->writeDatagram(frame.toLocal8Bit(), address2send_, port2send_)) == -1)
     131                        qDebug() << "Failed to send the frame: " << address2send_ << port2send_ << frame << endl;
    132132        }
    133133        else if (socketType_ == "server")
     
    135135            for (int i = 0; i < listClients.size(); i++)
    136136            {
    137                         if ((sent = udpSocket_->writeDatagram(frame.toLocal8Bit(), listClients[i]->getAddress(), listClients[i]->getPort())) == -1) 
    138                                 qDebug() << "Failed to send the frame: " << listClients[i]->getAddress() << listClients[i]->getPort() << frame << endl; 
     137                        if ((sent = udpSocket_->writeDatagram(frame.toLocal8Bit(), listClients[i]->getAddress(), listClients[i]->getPort())) == -1)
     138                                qDebug() << "Failed to send the frame: " << listClients[i]->getAddress() << listClients[i]->getPort() << frame << endl;
    139139            }
    140140        }
    141 } 
     141}
    142142
    143143
     
    145145// Send datagram QByteArray
    146146//////////////////////////////////////////////////////////////////////////
    147 void PacpusUDPSocket::sendDatagrams(QByteArray frame) 
    148 { 
     147void PacpusUDPSocket::sendDatagrams(QByteArray frame)
     148{
    149149        int sent=0;
    150        
     150
    151151        if (socketType_ == "client")
    152152        {
    153             if ((sent = udpSocket_->writeDatagram(frame, address2send_, port2send_)) == -1) 
    154                         qDebug() << "Failed to send the frame: " << address2send_ << port2send_ << frame << endl; 
     153            if ((sent = udpSocket_->writeDatagram(frame, address2send_, port2send_)) == -1)
     154                        qDebug() << "Failed to send the frame: " << address2send_ << port2send_ << frame << endl;
    155155        }
    156156        else if (socketType_ == "server")
     
    158158            for (int i = 0; i < listClients.size(); i++)
    159159            {
    160                         if ((sent = udpSocket_->writeDatagram(frame, listClients[i]->getAddress(), listClients[i]->getPort())) == -1) 
    161                                 qDebug() << "Failed to send the frame: " << listClients[i]->getAddress() << listClients[i]->getPort() << frame << endl; 
     160                        if ((sent = udpSocket_->writeDatagram(frame, listClients[i]->getAddress(), listClients[i]->getPort())) == -1)
     161                                qDebug() << "Failed to send the frame: " << listClients[i]->getAddress() << listClients[i]->getPort() << frame << endl;
    162162            }
    163163        }
    164 } 
    165 
    166 
    167 //////////////////////////////////////////////////////////////////////////
    168 // Called when the socket receive a new datagram 
     164}
     165
     166
     167//////////////////////////////////////////////////////////////////////////
     168// Called when the socket receive a new datagram
    169169//////////////////////////////////////////////////////////////////////////
    170170void PacpusUDPSocket::readPendingDatagrams()
    171171{
    172         while (udpSocket_->hasPendingDatagrams()) 
    173         {
    174                 QByteArray datagram; 
    175                 datagram.resize(udpSocket_->pendingDatagramSize()); 
    176                 QHostAddress sender; 
     172        while (udpSocket_->hasPendingDatagrams())
     173        {
     174                QByteArray datagram;
     175                datagram.resize(udpSocket_->pendingDatagramSize());
     176                QHostAddress sender;
    177177                quint16 senderPort;
    178    
     178
    179179                if(udpSocket_->readDatagram(datagram.data(), datagram.size(),  &sender, &senderPort) != -1)
    180                 {                   
     180                {
    181181                    if (socketType_ == "server")
    182182                    {
    183183                                bool flag = false;
    184                
    185                                 for (int i = 0; i < listClients.size(); i++) 
    186                                 { 
     184
     185                                for (int i = 0; i < listClients.size(); i++)
     186                                {
    187187                                        if (listClients[i]->getAddress() == sender && listClients[i]->getPort() == senderPort)
    188188                                                flag = true;
    189189                                }
    190                        
     190
    191191                                if (flag == false)
    192192                                        listClients << new Client(sender, senderPort);
    193193                        }
    194                        
    195                         if (updSocketOutput_ && updSocketOutput_->hasConnection())
    196                                 updSocketOutput_->send(QString(datagram.data()));
     194
     195                        if (udpSocketOutput_ && udpSocketOutput_->hasConnection())
     196                                udpSocketOutput_->send(QString(datagram.data()));
    197197                }
    198198                else
  • trunk/PacpusSocket/PacpusUDPSocket.h

    r87 r99  
    55//  author:     Pierre Hudelaine
    66//              Copyright Heudiasyc UMR UTC/CNRS 7253
    7 // 
     7//
    88//  version:    $Id: $
    99//
     
    1515
    1616#include "Pacpus/kernel/Log.h"
    17 #include "Pacpus/kernel/ComponentBase.h" 
    18 #include "Pacpus/kernel/ComponentFactory.h" 
     17#include "Pacpus/kernel/ComponentBase.h"
     18#include "Pacpus/kernel/ComponentFactory.h"
    1919
    2020// Export macro for PacpusSocket DLL for Windows only
     
    2828#   endif
    2929#else
    30     // On other platforms, simply ignore this 
    31 #   define PACPUSSOCKET_API 
     30    // On other platforms, simply ignore this
     31#   define PACPUSSOCKET_API
    3232#endif
    3333
     
    3838class PACPUSSOCKET_API Client
    3939{
    40 public: 
     40public:
    4141    /// Constructor
    4242    Client();
     
    4444    /// Destructor
    4545    ~Client();
    46    
     46
    4747    QHostAddress address_;
    4848    quint16 port_;
    49    
    50     QHostAddress getAddress() {return address_;};   
     49
     50    QHostAddress getAddress() {return address_;};
    5151    quint16 getPort() {return port_;};
    5252};
     
    5454class PACPUSSOCKET_API PacpusUDPSocket
    5555        : public QObject
    56         , public ComponentBase 
    57 { 
     56        , public ComponentBase
     57{
    5858  Q_OBJECT
    5959
    60 public: 
     60public:
    6161    /// Constructor
    6262    PacpusUDPSocket(QString name);
     
    7171
    7272    /// Slot d'envoie des paquets
    73     void sendDatagrams(QString frame);
     73    void sendQString(const QString& frame);
    7474    void sendDatagrams(QByteArray frame);
    75    
     75
    7676Q_SIGNALS:
    7777    void newDatagram(QByteArray datagram);
     
    8383    virtual void stopActivity();
    8484    virtual COMPONENT_CONFIGURATION configureComponent(XmlComponentConfig config);
    85        
    86         virtual void addInputs();
     85
     86    virtual void addInputs();
    8787    virtual void addOutputs();
    88        
    89         OutputInterface<QString, PacpusUDPSocket>* udpSocketOutput_;
     88
     89    OutputInterface<QString, PacpusUDPSocket>* udpSocketOutput_;
    9090
    9191    QUdpSocket * udpSocket_;
     
    9494    quint16 port2send_;
    9595    QHostAddress address2send_;
    96     QString socketType_;         
    97      
     96    QString socketType_;
     97
    9898    QList <Client *> listClients;
    9999};
Note: See TracChangeset for help on using the changeset viewer.