summaryrefslogtreecommitdiff
path: root/cpp/src/IceStorm/SubscriberFactory.h
blob: 23e4fd30c0ebb4a9e436dd9d1d80e6b8a5013d3f (plain)
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
// **********************************************************************
//
// Copyright (c) 2003-2004 ZeroC, Inc. All rights reserved.
//
// This copy of Ice is licensed to you under the terms described in the
// ICE_LICENSE file included in this distribution.
//
// **********************************************************************

#ifndef SUBSCRIBER_FACTORY_H
#define SUBSCRIBER_FACTORY_H

#include <IceStorm/IceStormInternal.h> // For QoS, TopicLink
#include <IceStorm/QueuedProxy.h>
#include <IceUtil/RecMutex.h>
#include <map>

namespace IceStorm
{

//
// Forward declarations.
//
class TraceLevels;
typedef IceUtil::Handle<TraceLevels> TraceLevelsPtr;

class Subscriber;
typedef IceUtil::Handle<Subscriber> SubscriberPtr;

class Flusher;
typedef IceUtil::Handle<Flusher> FlusherPtr;

//
// Factory object that knows how to create various type of Subscriber
// objects.
//
class SubscriberFactory  : public IceUtil::Shared
{
public:

    SubscriberFactory(const Ice::CommunicatorPtr&, const TraceLevelsPtr&, const FlusherPtr&);

    //
    // Create a link subscriber (that is a subscriber that points to
    // another topic instance).
    //
    SubscriberPtr createLinkSubscriber(const TopicLinkPrx&, Ice::Int);

    //
    // Create a Subscriber with the given QoS.
    //
    SubscriberPtr createSubscriber(const QoS&, const Ice::ObjectPrx&);

    //
    // Increment the usage count of a queued proxy.
    //
    void incProxyUsageCount(const QueuedProxyPtr&);

    //
    // Decrement the usage count of a queued proxy.
    //
    void decProxyUsageCount(const QueuedProxyPtr&);

private:

    //
    // SubscriberFactory maps all subscriber proxies to queued proxies.
    // Only one queued proxy is created for a subscriber's proxy,
    // regardless of how many topics it subscribes to.
    //
    struct ProxyInfo
    {
        QueuedProxyPtr proxy;
        Ice::Int count;
    };

    Ice::CommunicatorPtr _communicator;
    TraceLevelsPtr _traceLevels;
    FlusherPtr _flusher;
    IceUtil::RecMutex _proxiesMutex;
    std::map<Ice::ObjectPrx, ProxyInfo> _proxies;
};

typedef IceUtil::Handle<SubscriberFactory> SubscriberFactoryPtr;

} // End namespace IceStorm

#endif