LCOV - code coverage report
Current view: directory - rdf/build - nsRDFModule.cpp (source / functions) Found Hit Coverage
Test: app.info Lines: 16 12 75.0 %
Date: 2012-06-02 Functions: 9 7 77.8 %

       1                 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 : /* ***** BEGIN LICENSE BLOCK *****
       3                 :  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
       4                 :  *
       5                 :  * The contents of this file are subject to the Mozilla Public License Version
       6                 :  * 1.1 (the "License"); you may not use this file except in compliance with
       7                 :  * the License. You may obtain a copy of the License at
       8                 :  * http://www.mozilla.org/MPL/
       9                 :  *
      10                 :  * Software distributed under the License is distributed on an "AS IS" basis,
      11                 :  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
      12                 :  * for the specific language governing rights and limitations under the
      13                 :  * License.
      14                 :  *
      15                 :  * The Original Code is mozilla.org code.
      16                 :  *
      17                 :  * The Initial Developer of the Original Code is
      18                 :  * Netscape Communications Corporation.
      19                 :  * Portions created by the Initial Developer are Copyright (C) 1998
      20                 :  * the Initial Developer. All Rights Reserved.
      21                 :  *
      22                 :  * Contributor(s):
      23                 :  *   Benjamin Smedberg <benjamin@smedbergs.us>
      24                 :  *
      25                 :  * Alternatively, the contents of this file may be used under the terms of
      26                 :  * either of the GNU General Public License Version 2 or later (the "GPL"),
      27                 :  * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
      28                 :  * in which case the provisions of the GPL or the LGPL are applicable instead
      29                 :  * of those above. If you wish to allow use of your version of this file only
      30                 :  * under the terms of either the GPL or the LGPL, and not to allow others to
      31                 :  * use your version of this file under the terms of the MPL, indicate your
      32                 :  * decision by deleting the provisions above and replace them with the notice
      33                 :  * and other provisions required by the GPL or the LGPL. If you do not delete
      34                 :  * the provisions above, a recipient may use your version of this file under
      35                 :  * the terms of any one of the MPL, the GPL or the LGPL.
      36                 :  *
      37                 :  * ***** END LICENSE BLOCK ***** */
      38                 : #include "nsCOMPtr.h"
      39                 : #include "mozilla/ModuleUtils.h"
      40                 : 
      41                 : #include "nsIFactory.h"
      42                 : #include "nsRDFService.h"
      43                 : #include "nsIRDFContainer.h"
      44                 : #include "nsIRDFContainerUtils.h"
      45                 : #include "nsIRDFCompositeDataSource.h"
      46                 : #include "nsIRDFContentSink.h"
      47                 : #include "nsISupports.h"
      48                 : #include "nsRDFBaseDataSources.h"
      49                 : #include "nsRDFBuiltInDataSources.h"
      50                 : #include "nsFileSystemDataSource.h"
      51                 : #include "nsRDFCID.h"
      52                 : #include "nsIComponentManager.h"
      53                 : #include "rdf.h"
      54                 : #include "nsIServiceManager.h"
      55                 : #include "nsILocalStore.h"
      56                 : #include "nsRDFXMLParser.h"
      57                 : #include "nsRDFXMLSerializer.h"
      58                 : 
      59                 : #include "rdfISerializer.h"
      60                 : 
      61                 : //----------------------------------------------------------------------
      62                 : 
      63                 : // Functions used to create new instances of a given object by the
      64                 : // generic factory.
      65                 : 
      66                 : #define MAKE_CTOR(_func,_new,_ifname)                                \
      67                 : static nsresult                                                      \
      68                 : CreateNew##_func(nsISupports* aOuter, REFNSIID aIID, void **aResult) \
      69                 : {                                                                    \
      70                 :     if (!aResult) {                                                  \
      71                 :         return NS_ERROR_INVALID_POINTER;                             \
      72                 :     }                                                                \
      73                 :     if (aOuter) {                                                    \
      74                 :         *aResult = nsnull;                                           \
      75                 :         return NS_ERROR_NO_AGGREGATION;                              \
      76                 :     }                                                                \
      77                 :     nsI##_ifname* inst;                                              \
      78                 :     nsresult rv = NS_New##_new(&inst);                               \
      79                 :     if (NS_FAILED(rv)) {                                             \
      80                 :         *aResult = nsnull;                                           \
      81                 :         return rv;                                                   \
      82                 :     }                                                                \
      83                 :     rv = inst->QueryInterface(aIID, aResult);                        \
      84                 :     if (NS_FAILED(rv)) {                                             \
      85                 :         *aResult = nsnull;                                           \
      86                 :     }                                                                \
      87                 :     NS_RELEASE(inst);             /* get rid of extra refcnt */      \
      88                 :     return rv;                                                       \
      89                 : }
      90                 : 
      91                 : extern nsresult
      92                 : NS_NewDefaultResource(nsIRDFResource** aResult);
      93                 : 
      94              10 : MAKE_CTOR(RDFXMLDataSource,RDFXMLDataSource,RDFDataSource)
      95               0 : MAKE_CTOR(RDFCompositeDataSource,RDFCompositeDataSource,RDFCompositeDataSource)
      96             267 : MAKE_CTOR(RDFContainer,RDFContainer,RDFContainer)
      97                 : 
      98             172 : MAKE_CTOR(RDFContainerUtils,RDFContainerUtils,RDFContainerUtils)
      99                 : 
     100            2072 : MAKE_CTOR(RDFContentSink,RDFContentSink,RDFContentSink)
     101           56424 : MAKE_CTOR(RDFDefaultResource,DefaultResource,RDFResource)
     102                 : 
     103                 : #define MAKE_RDF_CTOR(_func,_new,_ifname)                            \
     104                 : static nsresult                                                      \
     105                 : CreateNew##_func(nsISupports* aOuter, REFNSIID aIID, void **aResult) \
     106                 : {                                                                    \
     107                 :     if (!aResult) {                                                  \
     108                 :         return NS_ERROR_INVALID_POINTER;                             \
     109                 :     }                                                                \
     110                 :     if (aOuter) {                                                    \
     111                 :         *aResult = nsnull;                                           \
     112                 :         return NS_ERROR_NO_AGGREGATION;                              \
     113                 :     }                                                                \
     114                 :     rdfI##_ifname* inst;                                             \
     115                 :     nsresult rv = NS_New##_new(&inst);                               \
     116                 :     if (NS_FAILED(rv)) {                                             \
     117                 :         *aResult = nsnull;                                           \
     118                 :         return rv;                                                   \
     119                 :     }                                                                \
     120                 :     rv = inst->QueryInterface(aIID, aResult);                        \
     121                 :     if (NS_FAILED(rv)) {                                             \
     122                 :         *aResult = nsnull;                                           \
     123                 :     }                                                                \
     124                 :     NS_RELEASE(inst);             /* get rid of extra refcnt */      \
     125                 :     return rv;                                                       \
     126                 : }
     127                 : 
     128                 : extern nsresult
     129                 : NS_NewTriplesSerializer(rdfISerializer** aResult);
     130                 : 
     131               0 : MAKE_RDF_CTOR(TriplesSerializer, TriplesSerializer, Serializer)
     132                 : 
     133                 : NS_DEFINE_NAMED_CID(NS_RDFCOMPOSITEDATASOURCE_CID);
     134                 : NS_DEFINE_NAMED_CID(NS_RDFFILESYSTEMDATASOURCE_CID);
     135                 : NS_DEFINE_NAMED_CID(NS_RDFINMEMORYDATASOURCE_CID);
     136                 : NS_DEFINE_NAMED_CID(NS_RDFXMLDATASOURCE_CID);
     137                 : NS_DEFINE_NAMED_CID(NS_RDFDEFAULTRESOURCE_CID);
     138                 : NS_DEFINE_NAMED_CID(NS_RDFCONTENTSINK_CID);
     139                 : NS_DEFINE_NAMED_CID(NS_RDFCONTAINER_CID);
     140                 : NS_DEFINE_NAMED_CID(NS_RDFCONTAINERUTILS_CID);
     141                 : NS_DEFINE_NAMED_CID(NS_RDFSERVICE_CID);
     142                 : NS_DEFINE_NAMED_CID(NS_RDFXMLPARSER_CID);
     143                 : NS_DEFINE_NAMED_CID(NS_RDFXMLSERIALIZER_CID);
     144                 : NS_DEFINE_NAMED_CID(NS_RDFNTRIPLES_SERIALIZER_CID);
     145                 : NS_DEFINE_NAMED_CID(NS_LOCALSTORE_CID);
     146                 : 
     147                 : 
     148                 : static const mozilla::Module::CIDEntry kRDFCIDs[] = {
     149                 :     { &kNS_RDFCOMPOSITEDATASOURCE_CID, false, NULL, CreateNewRDFCompositeDataSource },
     150                 :     { &kNS_RDFFILESYSTEMDATASOURCE_CID, false, NULL, FileSystemDataSource::Create },
     151                 :     { &kNS_RDFINMEMORYDATASOURCE_CID, false, NULL, NS_NewRDFInMemoryDataSource },
     152                 :     { &kNS_RDFXMLDATASOURCE_CID, false, NULL, CreateNewRDFXMLDataSource },
     153                 :     { &kNS_RDFDEFAULTRESOURCE_CID, false, NULL, CreateNewRDFDefaultResource },
     154                 :     { &kNS_RDFCONTENTSINK_CID, false, NULL, CreateNewRDFContentSink },
     155                 :     { &kNS_RDFCONTAINER_CID, false, NULL, CreateNewRDFContainer },
     156                 :     { &kNS_RDFCONTAINERUTILS_CID, false, NULL, CreateNewRDFContainerUtils },
     157                 :     { &kNS_RDFSERVICE_CID, false, NULL, RDFServiceImpl::CreateSingleton },
     158                 :     { &kNS_RDFXMLPARSER_CID, false, NULL, nsRDFXMLParser::Create },
     159                 :     { &kNS_RDFXMLSERIALIZER_CID, false, NULL, nsRDFXMLSerializer::Create },
     160                 :     { &kNS_RDFNTRIPLES_SERIALIZER_CID, false, NULL, CreateNewTriplesSerializer },
     161                 :     { &kNS_LOCALSTORE_CID, false, NULL, NS_NewLocalStore },
     162                 :     { NULL }
     163                 : };
     164                 : 
     165                 : static const mozilla::Module::ContractIDEntry kRDFContracts[] = {
     166                 :     { NS_RDF_DATASOURCE_CONTRACTID_PREFIX "composite-datasource", &kNS_RDFCOMPOSITEDATASOURCE_CID },
     167                 :     { NS_RDF_DATASOURCE_CONTRACTID_PREFIX "files", &kNS_RDFFILESYSTEMDATASOURCE_CID },
     168                 :     { NS_RDF_DATASOURCE_CONTRACTID_PREFIX "in-memory-datasource", &kNS_RDFINMEMORYDATASOURCE_CID },
     169                 :     { NS_RDF_DATASOURCE_CONTRACTID_PREFIX "xml-datasource", &kNS_RDFXMLDATASOURCE_CID },
     170                 :     { NS_RDF_RESOURCE_FACTORY_CONTRACTID, &kNS_RDFDEFAULTRESOURCE_CID },
     171                 :     { NS_RDF_CONTRACTID "/content-sink;1", &kNS_RDFCONTENTSINK_CID },
     172                 :     { NS_RDF_CONTRACTID "/container;1", &kNS_RDFCONTAINER_CID },
     173                 :     { NS_RDF_CONTRACTID "/container-utils;1", &kNS_RDFCONTAINERUTILS_CID },
     174                 :     { NS_RDF_CONTRACTID "/rdf-service;1", &kNS_RDFSERVICE_CID },
     175                 :     { NS_RDF_CONTRACTID "/xml-parser;1", &kNS_RDFXMLPARSER_CID },
     176                 :     { NS_RDF_CONTRACTID "/xml-serializer;1", &kNS_RDFXMLSERIALIZER_CID },
     177                 :     { NS_RDF_SERIALIZER "ntriples", &kNS_RDFNTRIPLES_SERIALIZER_CID },
     178                 :     { NS_LOCALSTORE_CONTRACTID, &kNS_LOCALSTORE_CID },
     179                 :     { NULL }
     180                 : };
     181                 : 
     182                 : static nsresult
     183            1404 : StartupRDFModule()
     184                 : {
     185            1404 :     if (RDFServiceImpl::gRDFService) {
     186               0 :         NS_ERROR("Leaked the RDF service from a previous startup.");
     187               0 :         RDFServiceImpl::gRDFService = nsnull;
     188                 :     }
     189                 : 
     190            1404 :     return NS_OK;
     191                 : }
     192                 : 
     193                 : static void
     194            1404 : ShutdownRDFModule()
     195                 : {
     196            1404 :     if (RDFServiceImpl::gRDFService) {
     197                 :         // XXX make this an assertion!
     198               1 :         NS_WARNING("Leaking the RDF Service.");
     199                 :     }
     200            1404 : }
     201                 : 
     202                 : static const mozilla::Module kRDFModule = {
     203                 :     mozilla::Module::kVersion,
     204                 :     kRDFCIDs,
     205                 :     kRDFContracts,
     206                 :     NULL,
     207                 :     NULL,
     208                 :     StartupRDFModule,
     209                 :     ShutdownRDFModule
     210                 : };
     211                 : 
     212                 : NSMODULE_DEFN(nsRDFModule) = &kRDFModule;

Generated by: LCOV version 1.7