LibreOffice Module framework (master) 1
protocolhandlercache.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
20#pragma once
21
22#include <unordered_map>
23#include <optional>
24
25#include <com/sun/star/util/URL.hpp>
26
28#include <rtl/ustring.hxx>
29
30namespace framework{
31
32inline constexpr OUStringLiteral PACKAGENAME_PROTOCOLHANDLER = u"Office.ProtocolHandler";
33
34#define CFG_PATH_SEPARATOR "/"
35
36#define PROPERTY_PROTOCOLS "Protocols"
37
46{
47 /* member */
48 public:
49
51 OUString m_sUNOName;
53 std::vector<OUString> m_lProtocols;
54};
55
61typedef std::unordered_map<OUString, OUString> PatternHash;
62
66typedef std::unordered_map<OUString, ProtocolHandler> HandlerHash;
67
88class HandlerCache final
89{
90 /* member */
91 private:
92
94 static std::optional<HandlerHash> s_pHandler;
96 static std::optional<PatternHash> s_pPattern;
100 static sal_Int32 m_nRefCount;
101
102 /* interface */
103 public:
104
105 HandlerCache();
107
108 bool search( const OUString& sURL, ProtocolHandler* pReturn ) const;
109 bool search( const css::util::URL& aURL, ProtocolHandler* pReturn ) const;
110
111 void takeOver(HandlerHash aHandler, PatternHash aPattern);
112};
113
129{
130 private:
132
133 virtual void ImplCommit() override;
134
135 /* interface */
136 public:
137 HandlerCFGAccess( const OUString& sPackage );
138 void read ( HandlerHash& rHandlerHash, PatternHash& rPatternHash );
139
140 void setCache(HandlerCache* pCache) {m_pCache = pCache;};
141 virtual void Notify(const css::uno::Sequence< OUString >& lPropertyNames) override;
142};
143
144} // namespace framework
145
146/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
implements configuration access for handler configuration @descr We use the ConfigItem mechanism to r...
virtual void Notify(const css::uno::Sequence< OUString > &lPropertyNames) override
virtual void ImplCommit() override
void setCache(HandlerCache *pCache)
void read(HandlerHash &rHandlerHash, PatternHash &rPatternHash)
use base class mechanism to fill given structures @descr User use us as a wrapper between configurati...
HandlerCFGAccess(const OUString &sPackage)
dtor of the config access class @descr It opens the configuration package automatically by using base...
static HandlerCFGAccess * s_pConfig
informs about config updates
static sal_Int32 m_nRefCount
ref count to construct/destruct internal member lists on demand by using singleton mechanism
HandlerCache()
ctor of the cache of all registered protocol handler @descr It tries to open the right configuration ...
void takeOver(HandlerHash aHandler, PatternHash aPattern)
static std::optional< PatternHash > s_pPattern
maps URL pattern to handler names
static std::optional< HandlerHash > s_pHandler
list of all registered handler registered by her uno implementation names
bool search(const OUString &sURL, ProtocolHandler *pReturn) const
dtor of the cache @descr It frees all used memory.
~HandlerCache()
dtor of the cache @descr It frees all used memory.
float u
std::unordered_map< OUString, OUString > PatternHash
This hash use registered pattern of all protocol handlers as keys and provide her uno implementation ...
std::unordered_map< OUString, ProtocolHandler > HandlerHash
This hash holds protocol handler structs by her names.
constexpr OUStringLiteral PACKAGENAME_PROTOCOLHANDLER
Programmer can register his own services to handle different protocols.
std::vector< OUString > m_lProtocols
list of URL pattern which defines the protocols which this handler is registered for
OUString m_sUNOName
the uno implementation name of this handler