Changeset 1365

Show
Ignore:
Timestamp:
06/01/05 21:09:25 (4 years ago)
Author:
madcat
Message:

Improvements. Searching mostly works now.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • testing/cgcomm/cgcomm.cpp

    r1290 r1365  
    3232                m_listener, this, &ModMain::onIncoming 
    3333        ); 
     34        logMsg("Core/GUI Communication listening on port 9990"); 
     35        return true; 
    3436} 
    3537int ModMain::onExit() { 
    3638        m_listener->destroy(); 
     39        return 0; 
    3740} 
    3841 
    3942void ModMain::onIncoming(SocketServer *sock, SocketEvent evt) { 
    40         boost::shared_ptr<Client> c(new Client(sock->accept())); 
     43        Client *c = new Client(sock->accept()); 
     44        c->getEventTable().addHandler(c, this, &ModMain::onClientEvent); 
    4145        m_clients.insert(c); 
     46} 
     47void ModMain::onClientEvent(Client *c, int evt) { 
     48        if (evt == EVT_DESTROY) { 
     49                m_clients.erase(c); 
     50                delete c; 
     51        } 
    4252} 
    4353 
  • testing/cgcomm/cgcomm.h

    r1290 r1365  
    11/* 
    2  *  Copyright (C) 2004-2005 Alo Sarv <madcat_@users.sourceforge.net> 
     2 *  Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 
    33 * 
    44 *  This program is free software; you can redistribute it and/or modify 
     
    1717 */ 
    1818 
     19#ifndef __CGCOMM_H__ 
     20#define __CGCOMM_H__ 
     21 
    1922#include <hn/modules.h> 
    2023#include <hn/sockets.h> 
     
    3033private: 
    3134        void onIncoming(SocketServer *sock, SocketEvent evt); 
     35        void onClientEvent(Client *c, int evt); 
     36 
    3237        SocketServer *m_listener; 
    33         typedef std::set<boost::shared_ptr<Client> > ClientMap; 
     38        typedef std::set<Client*> ClientMap; 
    3439        ClientMap m_clients; 
    3540        typedef ClientMap::iterator Iter; 
     
    3843} 
    3944 
     45#endif 
  • testing/cgcomm/client.cpp

    r1290 r1365  
     1/* 
     2 *  Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 
     3 * 
     4 *  This program is free software; you can redistribute it and/or modify 
     5 *  it under the terms of the GNU General Public License as published by 
     6 *  the Free Software Foundation; either version 2 of the License, or 
     7 *  (at your option) any later version. 
     8 * 
     9 *  This program is distributed in the hope that it will be useful, 
     10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     12 *  GNU General Public License for more details. 
     13 * 
     14 *  You should have received a copy of the GNU General Public License 
     15 *  along with this program; if not, write to the Free Software 
     16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     17 */ 
     18 
    119#include "client.h" 
    220#include "subsysbase.h" 
     
    1028#include "sub_search.h" 
    1129#include "sub_shared.h" 
     30#include "opcodes.h" 
    1231 
    1332namespace CGComm { 
    1433 
    15 enum SubSystems { 
    16         SUB_AUTH     = 0x01, 
    17         SUB_SEARCH   = 0x02, 
    18         SUB_DOWNLOAD = 0x03, 
    19         SUB_SHARED   = 0x04, 
    20         SUB_CONFIG   = 0x05, 
    21         SUB_HASHER   = 0x06, 
    22         SUB_PLUGINS  = 0x07, 
    23         SUB_LOG      = 0x08, 
    24         SUB_EXT      = 0xff 
    25 }; 
     34IMPLEMENT_EVENT_TABLE(Client, Client*, int); 
    2635 
    2736Client::Client(SocketClient *sock) : m_socket(sock) { 
     
    4352void Client::parse(const std::string &data) { 
    4453        m_buffer.append(data); 
    45         while (true) { 
    46                 if (m_buffer.size() < 6) { 
     54        while (m_buffer.size() > 4) { 
     55                std::istringstream tmp(m_buffer); 
     56                uint8_t subsys = Utils::getVal<uint8_t>(tmp); 
     57                uint16_t size = Utils::getVal<uint16_t>(tmp); 
     58                if (m_buffer.size() < size + 3u) { 
    4759                        return; 
    4860                } 
    49                 std::istringstream tmp(m_buffer); 
    50                 uint8_t proto = Utils::getVal<uint8_t>(tmp); 
    51                 CHECK_THROW(proto == 0x01); 
    52                 uint16_t size = Utils::getVal<uint16_t>(tmp); 
    53                 if (m_buffer.size() < size + 5) { 
    54                         return; 
    55                 } 
    56                 std::istringstream packet(m_buffer.substr(5, size)); 
    57                 m_buffer.erase(0, size + 5); 
    58                 uint8_t subsystem = Utils::getVal<uint8_t>(packet); 
    59                 Iter it = m_subMap.find(subsystem); 
     61                std::istringstream packet(m_buffer.substr(3, size)); 
     62                Iter it = m_subMap.find(subsys); 
    6063                if (it == m_subMap.end()) { 
    6164                        logWarning( 
    6265                                boost::format("Unknown subsystem %s") 
    63                                 % Utils::hexDump(subsystem
     66                                % Utils::hexDump(subsys
    6467                        ); 
    6568                        continue; 
     
    6770                        (*it).second->handle(packet); 
    6871                } 
     72                m_buffer.erase(0, size + 3); 
    6973        } 
     74} 
     75 
     76void Client::onSocketEvent(SocketClient *sock, SocketEvent evt) { 
     77        if (evt == SOCK_READ) { 
     78                std::string buf; 
     79                *sock >> buf; 
     80                return parse(buf); 
     81        } else if (evt == SOCK_LOST || evt == SOCK_TIMEOUT || evt == SOCK_ERR) { 
     82                destroy(); 
     83        } 
     84} 
     85 
     86void Client::destroy() { 
     87        getEventTable().postEvent(this, EVT_DESTROY); 
     88        m_socket->destroy(); 
    7089} 
    7190 
  • testing/cgcomm/client.h

    r1290 r1365  
     1/* 
     2 *  Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 
     3 * 
     4 *  This program is free software; you can redistribute it and/or modify 
     5 *  it under the terms of the GNU General Public License as published by 
     6 *  the Free Software Foundation; either version 2 of the License, or 
     7 *  (at your option) any later version. 
     8 * 
     9 *  This program is distributed in the hope that it will be useful, 
     10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     12 *  GNU General Public License for more details. 
     13 * 
     14 *  You should have received a copy of the GNU General Public License 
     15 *  along with this program; if not, write to the Free Software 
     16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     17 */ 
     18 
    119#ifndef __CLIENT_H__ 
    220#define __CLIENT_H__ 
     
    826namespace CGComm { 
    927class SubSysBase; 
     28enum ClientEvents { 
     29        EVT_DESTROY 
     30}; 
    1031 
    1132class Client { 
    1233public: 
     34        DECLARE_EVENT_TABLE(Client*, int); 
     35 
    1336        Client(SocketClient *sock); 
     37 
     38        void destroy(); 
    1439private: 
    1540        void parse(const std::string &data); 
     
    2449}; 
    2550 
    26 enum OpCodes { 
    27         OC_LIST = 0x01, 
    28         OC_MONITOR = 0x02, 
    29         OC_CANCEL = 0x03, 
    30         OC_PAUSE = 0x04, 
    31         OC_RESUME = 0x05, 
    32         OC_ADD = 0x06, 
    33         OC_REMOVE = 0x07, 
    34         OC_SET = 0x08, 
    35         OC_GET = 0x09 
    36 }; 
    37  
    3851} // CGComm 
    3952 
  • testing/cgcomm/sub_auth.cpp

    r1290 r1365  
     1/* 
     2 *  Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 
     3 * 
     4 *  This program is free software; you can redistribute it and/or modify 
     5 *  it under the terms of the GNU General Public License as published by 
     6 *  the Free Software Foundation; either version 2 of the License, or 
     7 *  (at your option) any later version. 
     8 * 
     9 *  This program is distributed in the hope that it will be useful, 
     10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     12 *  GNU General Public License for more details. 
     13 * 
     14 *  You should have received a copy of the GNU General Public License 
     15 *  along with this program; if not, write to the Free Software 
     16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     17 */ 
     18 
     19#include "sub_auth.h" 
     20#include "opcodes.h" 
     21 
     22namespace CGComm { 
     23namespace Subsystem { 
     24 
     25Auth::Auth(SocketClient *sock) : SubSysBase(sock, SUB_AUTH) {} 
     26void Auth::handle(std::istream &i) {} 
     27 
     28} 
     29} 
     30 
  • testing/cgcomm/sub_auth.h

    r1290 r1365  
     1/* 
     2 *  Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 
     3 * 
     4 *  This program is free software; you can redistribute it and/or modify 
     5 *  it under the terms of the GNU General Public License as published by 
     6 *  the Free Software Foundation; either version 2 of the License, or 
     7 *  (at your option) any later version. 
     8 * 
     9 *  This program is distributed in the hope that it will be useful, 
     10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     12 *  GNU General Public License for more details. 
     13 * 
     14 *  You should have received a copy of the GNU General Public License 
     15 *  along with this program; if not, write to the Free Software 
     16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     17 */ 
     18 
    119#ifndef __SUB_AUTH_H__ 
    220#define __SUB_AUTH_H__ 
  • testing/cgcomm/sub_config.cpp

    r1290 r1365  
     1/* 
     2 *  Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 
     3 * 
     4 *  This program is free software; you can redistribute it and/or modify 
     5 *  it under the terms of the GNU General Public License as published by 
     6 *  the Free Software Foundation; either version 2 of the License, or 
     7 *  (at your option) any later version. 
     8 * 
     9 *  This program is distributed in the hope that it will be useful, 
     10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     12 *  GNU General Public License for more details. 
     13 * 
     14 *  You should have received a copy of the GNU General Public License 
     15 *  along with this program; if not, write to the Free Software 
     16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     17 */ 
     18 
     19#include "sub_config.h" 
     20#include "opcodes.h" 
     21 
     22namespace CGComm { 
     23namespace Subsystem { 
     24 
     25Config::Config(SocketClient *sock) : SubSysBase(sock, SUB_CONFIG) {} 
     26void Config::handle(std::istream &i) {} 
     27 
     28} 
     29} 
  • testing/cgcomm/sub_config.h

    r1290 r1365  
     1/* 
     2 *  Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 
     3 * 
     4 *  This program is free software; you can redistribute it and/or modify 
     5 *  it under the terms of the GNU General Public License as published by 
     6 *  the Free Software Foundation; either version 2 of the License, or 
     7 *  (at your option) any later version. 
     8 * 
     9 *  This program is distributed in the hope that it will be useful, 
     10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     12 *  GNU General Public License for more details. 
     13 * 
     14 *  You should have received a copy of the GNU General Public License 
     15 *  along with this program; if not, write to the Free Software 
     16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     17 */ 
     18 
    119#ifndef __SUB_CONFIG_H__ 
    220#define __SUB_CONFIG_H__ 
  • testing/cgcomm/sub_download.cpp

    r1290 r1365  
     1/* 
     2 *  Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 
     3 * 
     4 *  This program is free software; you can redistribute it and/or modify 
     5 *  it under the terms of the GNU General Public License as published by 
     6 *  the Free Software Foundation; either version 2 of the License, or 
     7 *  (at your option) any later version. 
     8 * 
     9 *  This program is distributed in the hope that it will be useful, 
     10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     12 *  GNU General Public License for more details. 
     13 * 
     14 *  You should have received a copy of the GNU General Public License 
     15 *  along with this program; if not, write to the Free Software 
     16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     17 */ 
     18 
     19#include "sub_download.h" 
     20#include "opcodes.h" 
     21 
     22namespace CGComm { 
     23namespace Subsystem { 
     24 
     25Download::Download(SocketClient *sock) : SubSysBase(sock, SUB_DOWNLOAD) {} 
     26void Download::handle(std::istream &i) {} 
     27 
     28} 
     29} 
  • testing/cgcomm/sub_download.h

    r1290 r1365  
     1/* 
     2 *  Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 
     3 * 
     4 *  This program is free software; you can redistribute it and/or modify 
     5 *  it under the terms of the GNU General Public License as published by 
     6 *  the Free Software Foundation; either version 2 of the License, or 
     7 *  (at your option) any later version. 
     8 * 
     9 *  This program is distributed in the hope that it will be useful, 
     10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     12 *  GNU General Public License for more details. 
     13 * 
     14 *  You should have received a copy of the GNU General Public License 
     15 *  along with this program; if not, write to the Free Software 
     16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     17 */ 
     18 
    119#ifndef __SUB_DOWNLOAD_H__ 
    220#define __SUB_DOWNLOAD_H__ 
  • testing/cgcomm/sub_ext.cpp

    r1290 r1365  
     1/* 
     2 *  Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 
     3 * 
     4 *  This program is free software; you can redistribute it and/or modify 
     5 *  it under the terms of the GNU General Public License as published by 
     6 *  the Free Software Foundation; either version 2 of the License, or 
     7 *  (at your option) any later version. 
     8 * 
     9 *  This program is distributed in the hope that it will be useful, 
     10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     12 *  GNU General Public License for more details. 
     13 * 
     14 *  You should have received a copy of the GNU General Public License 
     15 *  along with this program; if not, write to the Free Software 
     16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     17 */ 
     18 
     19#include "sub_ext.h" 
     20#include "opcodes.h" 
     21 
     22namespace CGComm { 
     23namespace Subsystem { 
     24 
     25Ext::Ext(SocketClient *sock) : SubSysBase(sock, SUB_EXT) {} 
     26void Ext::handle(std::istream &i) {} 
     27 
     28 
     29} 
     30} 
  • testing/cgcomm/sub_ext.h

    r1290 r1365  
     1/* 
     2 *  Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 
     3 * 
     4 *  This program is free software; you can redistribute it and/or modify 
     5 *  it under the terms of the GNU General Public License as published by 
     6 *  the Free Software Foundation; either version 2 of the License, or 
     7 *  (at your option) any later version. 
     8 * 
     9 *  This program is distributed in the hope that it will be useful, 
     10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     12 *  GNU General Public License for more details. 
     13 * 
     14 *  You should have received a copy of the GNU General Public License 
     15 *  along with this program; if not, write to the Free Software 
     16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     17 */ 
     18 
     19 
    120#ifndef __SUB_EXT_H__ 
    221#define __SUB_EXT_H__ 
     
    524namespace CGComm { 
    625namespace Subsystem { 
     26 
    727class Ext : public SubSysBase { 
    828public: 
     
    1030        virtual void handle(std::istream &i); 
    1131}; 
     32 
    1233} 
    1334} 
  • testing/cgcomm/sub_hasher.cpp

    r1290 r1365  
     1/* 
     2 *  Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 
     3 * 
     4 *  This program is free software; you can redistribute it and/or modify 
     5 *  it under the terms of the GNU General Public License as published by 
     6 *  the Free Software Foundation; either version 2 of the License, or 
     7 *  (at your option) any later version. 
     8 * 
     9 *  This program is distributed in the hope that it will be useful, 
     10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     12 *  GNU General Public License for more details. 
     13 * 
     14 *  You should have received a copy of the GNU General Public License 
     15 *  along with this program; if not, write to the Free Software 
     16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     17 */ 
     18 
     19#include "sub_hasher.h" 
     20#include "opcodes.h" 
     21 
     22namespace CGComm { 
     23namespace Subsystem { 
     24 
     25Hasher::Hasher(SocketClient *sock) : SubSysBase(sock, SUB_HASHER) {} 
     26void Hasher::handle(std::istream &i) {} 
     27 
     28} 
     29} 
  • testing/cgcomm/sub_hasher.h

    r1290 r1365  
     1/* 
     2 *  Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 
     3 * 
     4 *  This program is free software; you can redistribute it and/or modify 
     5 *  it under the terms of the GNU General Public License as published by 
     6 *  the Free Software Foundation; either version 2 of the License, or 
     7 *  (at your option) any later version. 
     8 * 
     9 *  This program is distributed in the hope that it will be useful, 
     10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     12 *  GNU General Public License for more details. 
     13 * 
     14 *  You should have received a copy of the GNU General Public License 
     15 *  along with this program; if not, write to the Free Software 
     16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     17 */ 
     18 
    119#ifndef __SUB_HASHER_H__ 
    220#define __SUB_HASHER_H__ 
     
    523namespace CGComm { 
    624namespace Subsystem { 
     25 
    726class Hasher : public SubSysBase { 
    827public: 
     
    1029        virtual void handle(std::istream &i); 
    1130}; 
     31 
    1232} 
    1333} 
  • testing/cgcomm/sub_log.cpp

    r1290 r1365  
     1/* 
     2 *  Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 
     3 * 
     4 *  This program is free software; you can redistribute it and/or modify 
     5 *  it under the terms of the GNU General Public License as published by 
     6 *  the Free Software Foundation; either version 2 of the License, or 
     7 *  (at your option) any later version. 
     8 * 
     9 *  This program is distributed in the hope that it will be useful, 
     10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     12 *  GNU General Public License for more details. 
     13 * 
     14 *  You should have received a copy of the GNU General Public License 
     15 *  along with this program; if not, write to the Free Software 
     16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     17 */ 
     18 
     19#include "sub_log.h" 
     20#include "opcodes.h" 
     21 
     22namespace CGComm { 
     23namespace Subsystem { 
     24         
     25Log::Log(SocketClient *sock) : SubSysBase(sock, SUB_LOG) {} 
     26void Log::handle(std::istream &i) {}     
     27 
     28} 
     29} 
  • testing/cgcomm/sub_log.h

    r1290 r1365  
     1/* 
     2 *  Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 
     3 * 
     4 *  This program is free software; you can redistribute it and/or modify 
     5 *  it under the terms of the GNU General Public License as published by 
     6 *  the Free Software Foundation; either version 2 of the License, or 
     7 *  (at your option) any later version. 
     8 * 
     9 *  This program is distributed in the hope that it will be useful, 
     10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     12 *  GNU General Public License for more details. 
     13 * 
     14 *  You should have received a copy of the GNU General Public License 
     15 *  along with this program; if not, write to the Free Software 
     16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     17 */ 
     18 
    119#ifndef __SUB_LOG_H__ 
    220#define __SUB_LOG_H__ 
     
    523namespace CGComm { 
    624namespace Subsystem { 
     25 
    726class Log : public SubSysBase { 
    827public: 
     
    1029        virtual void handle(std::istream &i); 
    1130}; 
     31 
    1232} 
    1333} 
  • testing/cgcomm/sub_plugins.cpp

    r1290 r1365  
     1/* 
     2 *  Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 
     3 * 
     4 *  This program is free software; you can redistribute it and/or modify 
     5 *  it under the terms of the GNU General Public License as published by 
     6 *  the Free Software Foundation; either version 2 of the License, or 
     7 *  (at your option) any later version. 
     8 * 
     9 *  This program is distributed in the hope that it will be useful, 
     10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     12 *  GNU General Public License for more details. 
     13 * 
     14 *  You should have received a copy of the GNU General Public License 
     15 *  along with this program; if not, write to the Free Software 
     16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     17 */ 
     18 
     19#include "sub_plugins.h" 
     20#include "opcodes.h" 
     21 
     22 
     23namespace CGComm { 
     24namespace Subsystem { 
     25 
     26Plugins::Plugins(SocketClient *sock) : SubSysBase(sock, SUB_PLUGINS) {} 
     27void Plugins::handle(std::istream &i) {} 
     28 
     29} 
     30} 
  • testing/cgcomm/sub_plugins.h

    r1290 r1365  
     1/* 
     2 *  Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 
     3 * 
     4 *  This program is free software; you can redistribute it and/or modify 
     5 *  it under the terms of the GNU General Public License as published by 
     6 *  the Free Software Foundation; either version 2 of the License, or 
     7 *  (at your option) any later version. 
     8 * 
     9 *  This program is distributed in the hope that it will be useful, 
     10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     12 *  GNU General Public License for more details. 
     13 * 
     14 *  You should have received a copy of the GNU General Public License 
     15 *  along with this program; if not, write to the Free Software 
     16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     17 */ 
     18 
    119#ifndef __SUB_PLUGINS_H__ 
    220#define __SUB_PLUGINS_H__ 
     
    523namespace CGComm { 
    624namespace Subsystem { 
     25 
    726class Plugins : public SubSysBase { 
    827public: 
     
    1029        virtual void handle(std::istream &i); 
    1130}; 
     31 
    1232} 
    1333} 
  • testing/cgcomm/sub_search.cpp

    r1290 r1365  
     1/* 
     2 *  Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 
     3 * 
     4 *  This program is free software; you can redistribute it and/or modify 
     5 *  it under the terms of the GNU General Public License as published by 
     6 *  the Free Software Foundation; either version 2 of the License, or 
     7 *  (at your option) any later version. 
     8 * 
     9 *  This program is distributed in the hope that it will be useful, 
     10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     12 *  GNU General Public License for more details. 
     13 * 
     14 *  You should have received a copy of the GNU General Public License 
     15 *  along with this program; if not, write to the Free Software 
     16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     17 */ 
     18 
    119#include "sub_search.h" 
    220#include <hn/search.h> 
     
    422#include <hn/sockets.h> 
    523#include <boost/bind.hpp> 
     24#include "tag.h" 
     25#include "opcodes.h" 
    626 
    727namespace CGComm { 
    828namespace Subsystem { 
    929 
    10 Search::Search(SocketClient *sock) : SubSysBase(sock), m_lastResultCount() {} 
     30Search::Search(SocketClient *sock) : SubSysBase(sock, SUB_SEARCH),  
     31m_lastResultCount() {} 
    1132 
    1233void Search::handle(std::istream &i) { 
    1334        uint8_t oc = Utils::getVal<uint8_t>(i); 
    1435        switch (oc) { 
    15                 case 0x00: perform(i); break; 
     36                case OC_GET: perform(i); break; 
     37                case OC_DOWNLOAD: download(i); break; 
    1638                default: break; 
    1739        } 
     
    2345        uint64_t minSize = 0; 
    2446        uint64_t maxSize = 0; 
     47        uint32_t filetype; 
    2548        uint16_t tc = getVal<uint16_t>(i); 
    2649        while (i && tc--) { 
     
    2851                uint16_t len = getVal<uint16_t>(i); 
    2952                switch (oc) { 
    30                         case 0x01
     53                        case TAG_KEYWORDS
    3154                                str = getVal<std::string>(i, len); 
    3255                                break; 
    33                         case 0x02
     56                        case TAG_MINSIZE
    3457                                minSize = getVal<uint64_t>(i); 
    3558                                break; 
    36                         case 0x03
     59                        case TAG_MAXSIZE
    3760                                maxSize = getVal<uint64_t>(i); 
    3861                                break; 
     62                        case TAG_FILETYPE: 
     63                                filetype = getVal<uint32_t>(i); 
     64                                break; 
    3965                        default: 
     66                                i.seekg(len, std::ios::cur); 
    4067                                break; 
    4168                } 
     
    4673                boost::bind(&Search::foundResults, this, _1) 
    4774        ); 
     75        m_currentSearch->setType(FileType(filetype)); 
    4876        if (minSize) { 
    4977                m_currentSearch->setMinSize(minSize); 
     
    5583} 
    5684 
     85void Search::download(std::istream &i) { 
     86        logDebug( 
     87                boost::format("CurrentSearch has %d results in it.")  
     88                % m_currentSearch->getResultCount() 
     89        ); 
     90        uint32_t id = Utils::getVal<uint32_t>(i); 
     91        if (m_currentSearch && id <= m_currentSearch->getResultCount()) { 
     92                logDebug( 
     93                        boost::format("Starting download from searchResult #%d")  
     94                        % id 
     95                ); 
     96                m_currentSearch->getResult(id)->download(); 
     97        } else { 
     98                logDebug(boost::format("No such search result (%d)") % id); 
     99        } 
     100} 
    57101void Search::foundResults(SearchPtr ptr) { 
    58102        //! \todo Check if search was in progress 
     
    61105        uint32_t cnt = 0; 
    62106        for (uint32_t i = m_lastResultCount; i < ptr->getResultCount(); ++i) { 
     107                SearchResultPtr res = ptr->getResult(i); 
    63108                std::ostringstream tmpR; 
    64                 SearchResultPtr res = ptr->getResult(i); 
    65                 putVal<uint8_t>(tmpR, 0x02); 
    66                 putVal<uint16_t>(tmpR, res->getName().size()); 
    67                 putVal<std::string>(tmpR, res->getName()); 
    68                 putVal<uint64_t>(tmpR, res->getSize()); 
    69                 putVal<uint32_t>(tmpR, res->getSources()); 
     109                putVal<uint8_t>(tmpR, 3); // tagcount 
     110                tmpR << makeTag(TAG_FILENAME, res->getName()); 
     111                tmpR << makeTag(TAG_FILESIZE, res->getSize()); 
     112                tmpR << makeTag(TAG_SRCCNT, res->getSources()); 
    70113                putVal(tmp, tmpR.str(), tmpR.str().size()); 
    71114                ++cnt; 
    72115        } 
    73116        std::ostringstream packet; 
    74         putVal<uint8_t>(packet, 0x01); 
    75         putVal<uint16_t>(packet, tmp.str().size()); 
     117        putVal<uint8_t>(packet, OP_SEARCHRESULTS); 
     118        putVal<uint32_t>(packet, cnt); 
    76119        putVal(packet, tmp.str(), tmp.str().size()); 
    77         m_socket->write(packet.str().data(), packet.str().size()); 
     120        sendPacket(packet.str()); 
     121        m_lastResultCount = ptr->getResultCount(); 
     122        logDebug( 
     123                boost::format("Sent %d sources to GUI") % ptr->getResultCount() 
     124        ); 
    78125} 
    79126 
  • testing/cgcomm/sub_search.h

    r1290 r1365  
     1/* 
     2 *  Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 
     3 * 
     4 *  This program is free software; you can redistribute it and/or modify 
     5 *  it under the terms of the GNU General Public License as published by 
     6 *  the Free Software Foundation; either version 2 of the License, or 
     7 *  (at your option) any later version. 
     8 * 
     9 *  This program is distributed in the hope that it will be useful, 
     10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     12 *  GNU General Public License for more details. 
     13 * 
     14 *  You should have received a copy of the GNU General Public License 
     15 *  along with this program; if not, write to the Free Software 
     16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     17 */ 
     18 
    119#ifndef __SUB_SEARCH_H__ 
    220#define __SUB_SEARCH_H__ 
     
    826namespace CGComm { 
    927namespace Subsystem { 
     28 
    1029class Search : public SubSysBase { 
    1130public: 
     
    1433private: 
    1534        void perform(std::istream &i); 
     35        void download(std::istream &i); 
    1636        void foundResults(SearchPtr ptr); 
     37 
    1738        SearchPtr m_currentSearch; 
    1839        uint32_t m_lastResultCount; 
    1940}; 
     41 
    2042} 
    2143} 
  • testing/cgcomm/sub_shared.cpp

    r1290 r1365  
     1/* 
     2 *  Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 
     3 * 
     4 *  This program is free software; you can redistribute it and/or modify 
     5 *  it under the terms of the GNU General Public License as published by 
     6 *  the Free Software Foundation; either version 2 of the License, or 
     7 *  (at your option) any later version. 
     8 * 
     9 *  This program is distributed in the hope that it will be useful, 
     10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     12 *  GNU General Public License for more details. 
     13 * 
     14 *  You should have received a copy of the GNU General Public License 
     15 *  along with this program; if not, write to the Free Software 
     16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     17 */ 
     18 
     19#include "sub_shared.h" 
     20#include "opcodes.h" 
     21 
     22namespace CGComm { 
     23namespace Subsystem { 
     24 
     25Shared::Shared(SocketClient *sock) : SubSysBase(sock, SUB_SHARED) {} 
     26void Shared::handle(std::istream &i) {} 
     27 
     28} 
     29} 
  • testing/cgcomm/sub_shared.h

    r1290 r1365  
     1/* 
     2 *  Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 
     3 * 
     4 *  This program is free software; you can redistribute it and/or modify 
     5 *  it under the terms of the GNU General Public License as published by 
     6 *  the Free Software Foundation; either version 2 of the License, or 
     7 *  (at your option) any later version. 
     8 * 
     9 *  This program is distributed in the hope that it will be useful, 
     10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     12 *  GNU General Public License for more details. 
     13 * 
     14 *  You should have received a copy of the GNU General Public License 
     15 *  along with this program; if not, write to the Free Software 
     16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     17 */ 
     18 
    119#ifndef __SUB_SHARED_H__ 
    220#define __SUB_SHARED_H__ 
     
    523namespace CGComm { 
    624namespace Subsystem { 
     25 
    726class Shared : public SubSysBase { 
    827public: 
     
    1029        virtual void handle(std::istream &i); 
    1130}; 
     31 
    1232} 
    1333} 
  • testing/cgcomm/subsysbase.cpp

    r1290 r1365  
     1/* 
     2 *  Copyright (C) 2005 Alo Sarv <madcat_@users.sourceforge.net> 
     3 * 
     4 *  This program is free software; you can redistribute it and/or modify 
     5 *  it under the terms of the GNU General Public License as published by 
     6 *  the Free Software Foundation; either version 2 of the License, or 
     7 *  (at your option) any later version. 
     8 * 
     9 *  This program is distributed in the hope that it will be useful, 
     10 *  but WITHOUT ANY WARRANTY; without even the implied warranty of 
     11 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the 
     12 *  GNU General Public License for more details. 
     13 * 
     14 *  You should have received a copy of the GNU General Public License 
     15 *  along with this program; if not, write to the Free Software 
     16 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA 
     17 */ 
     18 
     19#include <hn/osdep.h>&n