~ubuntu-branches/debian/sid/libdc0/sid

« back to all changes in this revision

Viewing changes to dclib/csearchsocket.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Pasi Savilaakso
  • Date: 2004-06-05 23:01:37 UTC
  • Revision ID: james.westby@ubuntu.com-20040605230137-2ty5g6rcfyguk4et
Tags: upstream-0.3.2
Import upstream version 0.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
                          csearchsocket.cpp  -  description
 
3
                             -------------------
 
4
    begin                : Thu May 27 2004
 
5
    copyright            : (C) 2004 by Mathias K�ster
 
6
    email                : mathen@users.berlios.de
 
7
 ***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
 *                                                                         *
 
11
 *   This program is free software; you can redistribute it and/or modify  *
 
12
 *   it under the terms of the GNU General Public License as published by  *
 
13
 *   the Free Software Foundation; either version 2 of the License, or     *
 
14
 *   (at your option) any later version.                                   *
 
15
 *                                                                         *
 
16
 ***************************************************************************/
 
17
 
 
18
#ifdef HAVE_CONFIG_H
 
19
#include <config.h>
 
20
#endif
 
21
 
 
22
#include <stdio.h>
 
23
 
 
24
#include <dclib/dcos.h>
 
25
#include <dclib/dclib.h>
 
26
#include <dclib/core/cstring.h>
 
27
#include <dclib/cmessagehandler.h>
 
28
 
 
29
#include "csearchsocket.h"
 
30
 
 
31
/** */
 
32
CSearchSocket::CSearchSocket()
 
33
{
 
34
        m_pCallback = 0;
 
35
}
 
36
 
 
37
/** */
 
38
CSearchSocket::~CSearchSocket()
 
39
{
 
40
        SetCallBackFunction(0);
 
41
}
 
42
 
 
43
/** */
 
44
int CSearchSocket::HandleMessage( char * c, int )
 
45
{
 
46
        int p=0;
 
47
        eDCMessage type;
 
48
        CObject * Object;
 
49
        CMessageHandler MessageHandler;
 
50
        CString s;
 
51
        int err;
 
52
        s = c;
 
53
 
 
54
        while( (type=MessageHandler.Parse(&s,p,Object=0)) != DC_MESSAGE_PARSE_ERROR )
 
55
        {
 
56
                switch (type)
 
57
                {
 
58
                        case DC_MESSAGE_SEARCHRESULT:
 
59
                        {
 
60
                                break;
 
61
                        }
 
62
 
 
63
                        default:
 
64
                        {
 
65
                                // remove message
 
66
                                delete Object;
 
67
                                Object = 0;
 
68
                                break;
 
69
                        }
 
70
                }
 
71
 
 
72
                if (Object)
 
73
                {
 
74
                        err = -1;
 
75
 
 
76
                        ((CDCMessage*)Object)->m_eType = type;
 
77
 
 
78
                        if ( m_pCallback != 0 )
 
79
                        {
 
80
                                err = m_pCallback->notify( this, Object );
 
81
                        }
 
82
 
 
83
                        if ( err == -1 )
 
84
                        {
 
85
                                printf("CallBack failed (state)...\n");
 
86
                                delete Object;
 
87
                        }
 
88
                }
 
89
        }
 
90
 
 
91
        return 0;
 
92
}
 
93
 
 
94
/** */
 
95
void CSearchSocket::DataAvailable( const char * buffer, int len )
 
96
{
 
97
        CString m_sBuffer;
 
98
        
 
99
        m_sBuffer = buffer;
 
100
 
 
101
        // add traffic control
 
102
        CSocket::m_Traffic.AddTraffic(ettCONTROLRX,len);
 
103
 
 
104
        // add '|' for parser
 
105
        m_sBuffer += '|';
 
106
 
 
107
        HandleMessage( (char*)m_sBuffer.Data(), m_sBuffer.Length() );
 
108
}
 
109
 
 
110
/** */
 
111
void CSearchSocket::ConnectionState( eConnectionState state )
 
112
{
 
113
        int err = -1;
 
114
 
 
115
        CMessageConnectionState *Object;
 
116
 
 
117
        Object = new CMessageConnectionState();
 
118
 
 
119
        Object->m_eState   = state;
 
120
        Object->m_sMessage = GetSocketError();
 
121
 
 
122
        if ( m_pCallback != 0 )
 
123
        {
 
124
                err = m_pCallback->notify( this, Object );
 
125
        }
 
126
 
 
127
        if ( err == -1 )
 
128
        {
 
129
                printf("CallBack failed (state)...\n");
 
130
                delete Object;
 
131
        }
 
132
}