LCOV - code coverage report
Current view: top level - libreoffice/framework/inc/classes - protocolhandlercache.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 4 4 100.0 %
Date: 2012-12-27 Functions: 8 8 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       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             : #ifndef __FRAMEWORK_CLASSES_PROTOCOLHANDLERCACHE_HXX_
      21             : #define __FRAMEWORK_CLASSES_PROTOCOLHANDLERCACHE_HXX_
      22             : 
      23             : #include <general.h>
      24             : #include <stdtypes.h>
      25             : #include <macros/debug.hxx>
      26             : 
      27             : #include <com/sun/star/util/URL.hpp>
      28             : 
      29             : #include <unotools/configitem.hxx>
      30             : #include <rtl/ustring.hxx>
      31             : #include <fwidllapi.h>
      32             : 
      33             : namespace framework{
      34             : 
      35             : #define PACKAGENAME_PROTOCOLHANDLER                 DECLARE_ASCII("Office.ProtocolHandler"                          )   /// name of our configuration package
      36             : 
      37             : #define CFG_PATH_SEPERATOR                          DECLARE_ASCII("/"                                               )   /// separator for configuration paths
      38             : 
      39             : #define SETNAME_HANDLER                             DECLARE_ASCII("HandlerSet"                                      )   /// name of configuration set inside package
      40             : #define PROPERTY_PROTOCOLS                          DECLARE_ASCII("Protocols"                                       )   /// properties of a protocol handler
      41             : 
      42             : //_________________________________________________________________________________________________________________
      43             : 
      44             : /**
      45             :     Programmer can register his own services to handle different protocols.
      46             :     Don't forget: It doesn't mean "handling of documents" ... these services could handle protocols ...
      47             :     e.g. "mailto:", "file://", ".java:"
      48             :     This struct holds the information about one such registered protocol handler.
      49             :     A list of handler objects is defined as ProtocolHandlerHash. see below
      50             : */
      51        7839 : struct FWI_DLLPUBLIC ProtocolHandler
      52             : {
      53             :     /* member */
      54             :     public:
      55             : 
      56             :         /// the uno implementation name of this handler
      57             :         ::rtl::OUString m_sUNOName;
      58             :         /// list of URL pattern which defines the protocols which this handler is registered for
      59             :         OUStringList m_lProtocols;
      60             : };
      61             : 
      62             : //_________________________________________________________________________________________________________________
      63             : 
      64             : /**
      65             :     This hash use registered pattern of all protocol handlers as keys and provide her
      66             :     uno implementation names as value. Overloading of the index operator makes it possible
      67             :     to search for a key by using a full qualified URL on list of all possible pattern keys.
      68             : */
      69          30 : class FWI_DLLPUBLIC PatternHash : public BaseHash< ::rtl::OUString >
      70             : {
      71             :     /* interface */
      72             :     public:
      73             : 
      74             :         PatternHash::iterator findPatternKey( const ::rtl::OUString& sURL );
      75             : };
      76             : 
      77             : //_________________________________________________________________________________________________________________
      78             : 
      79             : /**
      80             :     This hash holds protocol handler structs by her names.
      81             : */
      82             : typedef BaseHash< ProtocolHandler > HandlerHash;
      83             : 
      84             : //_________________________________________________________________________________________________________________
      85             : 
      86             : /**
      87             :     @short          this hash makes it easy to find a protocol handler by using his uno implementation name.
      88             :     @descr          It holds two lists of informations:
      89             :                         - first holds all handler by her uno implementation names and
      90             :                           can be used to get her other properties
      91             :                         - another one maps her registered pattern to her uno names to
      92             :                           perform search on such data
      93             :                     But this lists a static for all instances of this class. So it's possible to
      94             :                     create new objects without opening configuration twice and free memory automaticly
      95             :                     if last object will gone.
      96             : 
      97             :     @attention      We implement a singleton concept - so we doesn't need any mutex member here.
      98             :                     Because to safe access on static member we must use a static global lock
      99             :                     here too.
     100             : 
     101             :     @devstatus      ready to use
     102             :     @threadsafe     yes
     103             : */
     104             : 
     105             : class HandlerCFGAccess;
     106             : class FWI_DLLPUBLIC HandlerCache
     107             : {
     108             :     /* member */
     109             :     private:
     110             : 
     111             :         /// list of all registered handler registered by her uno implementation names
     112             :         static HandlerHash* m_pHandler;
     113             :         /// maps URL pattern to handler names
     114             :         static PatternHash* m_pPattern;
     115             :         /// informs about config updates
     116             :         static HandlerCFGAccess* m_pConfig;
     117             :         /// ref count to construct/destruct internal member lists on demand by using singleton mechanism
     118             :         static sal_Int32 m_nRefCount;
     119             : 
     120             :     /* interface */
     121             :     public:
     122             : 
     123             :                  HandlerCache();
     124             :         virtual ~HandlerCache();
     125             : 
     126             :         sal_Bool search( const ::rtl::OUString& sURL, ProtocolHandler* pReturn ) const;
     127             :         sal_Bool search( const css::util::URL&  aURL, ProtocolHandler* pReturn ) const;
     128             : 
     129             :         void takeOver(HandlerHash* pHandler, PatternHash* pPattern);
     130             : };
     131             : 
     132             : //_________________________________________________________________________________________________________________
     133             : 
     134             : /**
     135             :     @short          implements configuration access for handler configuration
     136             :     @descr          We use the ConfigItem mechanism to read/write values from/to configuration.
     137             :                     We set a data container pointer for filling or reading ... this class use it temp.
     138             :                     After successfuly calling of read(), we can use filled container directly or merge it with an existing one.
     139             :                     After successfuly calling of write() all values of given data container are flushed to our configuration -
     140             :                     but current implementation doesn't support writeing realy.
     141             : 
     142             :     @base           ::utl::ConfigItem
     143             :                     base mechanism for configuration access
     144             : 
     145             :     @devstatus      ready to use
     146             :     @threadsafe     no
     147             : */
     148          22 : class FWI_DLLPUBLIC HandlerCFGAccess : public ::utl::ConfigItem
     149             : {
     150             :     private:
     151             :         HandlerCache* m_pCache;
     152             : 
     153             :     /* interface */
     154             :     public:
     155             :                  HandlerCFGAccess( const ::rtl::OUString& sPackage  );
     156             :         void     read            (       HandlerHash**    ppHandler ,
     157             :                                          PatternHash**    ppPattern );
     158             : 
     159          30 :         void setCache(HandlerCache* pCache) {m_pCache = pCache;};
     160             :         virtual void Notify(const css::uno::Sequence< rtl::OUString >& lPropertyNames);
     161             :         virtual void Commit();
     162             : };
     163             : 
     164             : } // namespace framework
     165             : 
     166             : #endif // #ifndef __FRAMEWORK_CLASSES_PROTOCOLHANDLERCACHE_HXX_
     167             : 
     168             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10