Skip to main content
summaryrefslogtreecommitdiffstats
blob: af931f7859e849acf1b719bba25ccd05f91a7ded (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
#ifndef _PRAGMA_COPYRIGHT_
#define _PRAGMA_COPYRIGHT_
#pragma comment(copyright, "%Z% %I% %W% %D% %T%\0")
#endif /* _PRAGMA_COPYRIGHT_ */
/****************************************************************************

* Copyright (c) 2008, 2010 IBM Corporation.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0s
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html

 Classes: FilterProcessor

 Description: Properties of class 'FilterProcessor':
    input: a. a message queue
    output: a. a stream
            b. a message queue
    action: use user-defined filter handlers to process the messages
   
 Author: Nicole Nie

 History:
   Date     Who ID    Description
   -------- --- ---   -----------
   02/10/09 nieyy      Initial code (D153875)

****************************************************************************/

#include "filterproc.hpp"
#include <assert.h>

#include "log.hpp"
#include "exception.hpp"
#include "socket.hpp"

#include "statemachine.hpp"
#include "ctrlblock.hpp"
#include "message.hpp"
#include "stream.hpp"
#include "filter.hpp"
#include "filterlist.hpp"
#include "queue.hpp"
#include "eventntf.hpp"
#include "observer.hpp"

FilterProcessor::FilterProcessor(int hndl)
    : Processor(hndl), filtered(false), curFilterID(SCI_FILTER_NULL)
{
    name = "UpstreamFilter";

    inQueue = NULL;
    outQueue = NULL;

    observer = NULL;
}

Message * FilterProcessor::read()
{
    assert(inQueue);

    Message *msg = NULL;

    filtered = false;
    msg = inQueue->consume();
    
    return msg;
}

void FilterProcessor::process(Message * msg)
{
    assert(msg);

    int id = msg->getFilterID();
    if (id != SCI_FILTER_NULL) {
        Filter *filter = gFilterList->getFilter(id);
        // call user's filter handler
        if (filter != NULL) {
            curFilterID = id;
            
            filtered = true;
            filter->input(msg->getGroup(), msg->getContentBuf(), msg->getContentLen());
        }
    }
}

void FilterProcessor::write(Message * msg)
{
    assert(outQueue);

    if (filtered) {
        inQueue->remove();
        return;
    }

    if ((msg->getType() == Message::INIT_ACK) && 
            (gCtrlBlock->getMyRole() == CtrlBlock::FRONT_END)) {
        struct eventRC {
            int num;
            int count;
        } *frc;

        frc = (eventRC *)gNotifier->getRetVal(msg->getID());
        frc->count++;
        if (frc->count == frc->num) {
            gNotifier->notify(msg->getID());
        }
        inQueue->remove();

        return;
    }

    if (observer) {
        observer->notify();
    }

    msg->setRefCount(msg->getRefCount() + 1);
    outQueue->produce(msg);

    inQueue->remove();
}

void FilterProcessor::seize()
{
    gStateMachine->parse(StateMachine::FATAL_EXCEPTION);
}

void FilterProcessor::clean()
{
    // no action
}

bool FilterProcessor::isActive()
{
    return gCtrlBlock->isEnabled() || (inQueue->getSize() > 0);
}

void FilterProcessor::deliever(Message * msg)
{
    if (observer) {
        observer->notify();
    }
    outQueue->produce(msg);
}

int FilterProcessor::getCurFilterID()
{
    return curFilterID;
}

void FilterProcessor::setInQueue(MessageQueue * queue)
{
    inQueue = queue;
}

void FilterProcessor::setOutQueue(MessageQueue * queue)
{
    outQueue = queue;
}

void FilterProcessor::setObserver(Observer * ob)
{
    observer = ob;
}

Back to the top