aboutsummaryrefslogtreecommitdiffstats
path: root/src/native/windows/msofficecomm/ClassFactory.h
blob: abe56cd20540beeb1ee5beed279e3a0c5679d2ad (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
/*
 * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Distributable under LGPL license.
 * See terms of license at gnu.org.
 */
#ifndef _JMSOFFICECOMM_CLASSFACTORY_H_
#define _JMSOFFICECOMM_CLASSFACTORY_H_

#include "OutOfProcessServer.h"
#include "UnknownImpl.h"

/**
 * Represents a base implementation of the <tt>IClassFactory</tt> interface.
 *
 * @author Lyubomir Marinov
 */
class ClassFactory
    : public UnknownImpl<IClassFactory, IID_IClassFactory>
{
public:
    // IClassFactory
    STDMETHOD(LockServer)(BOOL lock)
        {
            lock ? OutOfProcessServer::addRef() : OutOfProcessServer::release();
            return S_OK;
        };

    HRESULT registerClassObject()
        {
            return
                ::CoRegisterClassObject(
                        _clsid,
                        this,
                        CLSCTX_LOCAL_SERVER,
                        REGCLS_MULTIPLEUSE | REGCLS_SUSPENDED,
                        &_registration);
        };

    HRESULT revokeClassObject() { return ::CoRevokeClassObject(_registration); };

protected:
    ClassFactory(REFCLSID clsid) : _clsid(clsid), _registration(0) {};
    virtual ~ClassFactory() {};

    const CLSID _clsid;

private:
    DWORD _registration;
};

#endif /* #ifndef _JMSOFFICECOMM_CLASSFACTORY_H_ */