LCOV - code coverage report
Current view: top level - libreoffice/framework/source/jobs - jobresult.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 6 55 10.9 %
Date: 2012-12-27 Functions: 2 9 22.2 %
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             : #include <jobs/jobresult.hxx>
      21             : #include <jobs/jobconst.hxx>
      22             : #include <threadhelp/readguard.hxx>
      23             : #include <threadhelp/writeguard.hxx>
      24             : #include <general.h>
      25             : #include <services.h>
      26             : 
      27             : #include <rtl/ustrbuf.hxx>
      28             : #include <vcl/svapp.hxx>
      29             : #include <comphelper/sequenceashashmap.hxx>
      30             : 
      31             : namespace framework{
      32             : 
      33             : /**
      34             :     @short      standard dtor
      35             :     @descr      It does nothing else ...
      36             :                 but it marks this new instance as non valid!
      37             : */
      38         124 : JobResult::JobResult()
      39         124 :     : ThreadHelpBase(&Application::GetSolarMutex())
      40             : {
      41             :     // reset the flag mask!
      42             :     // It will reset the accessible state of this object.
      43             :     // That can be usefull if something will fail here ...
      44         124 :     m_eParts = E_NOPART;
      45         124 : }
      46             : 
      47             : //________________________________
      48             : /**
      49             :     @short      special ctor
      50             :     @descr      It initialize this new instance with a pure job execution result
      51             :                 and analyze it. Doing so, we update our other members.
      52             : 
      53             :                 <p>
      54             :                 It's a list of named values, packed inside this any.
      55             :                 Following protocol is used:
      56             :                 <p>
      57             :                 <ul>
      58             :                     <li>
      59             :                         "SaveArguments" [sequence< css.beans.NamedValue >]
      60             :                         <br>
      61             :                         The returned list of (for this generic implementation unknown!)
      62             :                         properties, will be written directly to the configuration and replace
      63             :                         any old values there. There will no check for changes and we doesn't
      64             :                         support any mege feature here. They are written only. The job has
      65             :                         to modify this list.
      66             :                     </li>
      67             :                     <li>
      68             :                         "SendDispatchResult" [css.frame.DispatchResultEvent]
      69             :                         <br>
      70             :                         The given event is send to all current registered listener.
      71             :                         But it's not guaranteed. In case no listener are available or
      72             :                         this job isn't part of the dispatch environment (because it was used
      73             :                         by the css..task.XJobExecutor->trigger() implementation) this option
      74             :                         will be ignored.
      75             :                     </li>
      76             :                     <li>
      77             :                         "Deactivate" [boolean]
      78             :                         <br>
      79             :                         The job whish to be disabled. But note: There is no way, to enable it later
      80             :                         again by using this implementation. It can be done by using the configuration
      81             :                         only. (Means to register this job again.)
      82             :                         If a job knows, that there exist some status or result listener, it must use
      83             :                         the options "SendDispatchStatus" and "SendDispatchResult" (see before) too, to
      84             :                         inform it about the deactivation of this service.
      85             :                     </li>
      86             :                 </ul>
      87             : 
      88             :     @param      aResult
      89             :                     the job result
      90             : */
      91           0 : JobResult::JobResult( /*IN*/ const css::uno::Any& aResult )
      92           0 :     : ThreadHelpBase(&Application::GetSolarMutex())
      93             : {
      94             :     // safe the pure result
      95             :     // May someone need it later ...
      96           0 :     m_aPureResult = aResult;
      97             : 
      98             :     // reset the flag mask!
      99             :     // It will reset the accessible state of this object.
     100             :     // That can be usefull if something will fail here ...
     101           0 :     m_eParts = E_NOPART;
     102             : 
     103             :     // analyze the result and update our other members
     104           0 :     ::comphelper::SequenceAsHashMap aProtocol(aResult);
     105           0 :     if ( aProtocol.empty() )
     106           0 :         return;
     107             : 
     108           0 :     ::comphelper::SequenceAsHashMap::const_iterator pIt = aProtocol.end();
     109             : 
     110           0 :     pIt = aProtocol.find(JobConst::ANSWER_DEACTIVATE_JOB());
     111           0 :     if (pIt != aProtocol.end())
     112             :     {
     113           0 :         pIt->second >>= m_bDeactivate;
     114           0 :         if (m_bDeactivate)
     115           0 :             m_eParts |= E_DEACTIVATE;
     116             :     }
     117             : 
     118           0 :     pIt = aProtocol.find(JobConst::ANSWER_SAVE_ARGUMENTS());
     119           0 :     if (pIt != aProtocol.end())
     120             :     {
     121           0 :         pIt->second >>= m_lArguments;
     122           0 :         if (m_lArguments.getLength() > 0)
     123           0 :             m_eParts |= E_ARGUMENTS;
     124             :     }
     125             : 
     126           0 :     pIt = aProtocol.find(JobConst::ANSWER_SEND_DISPATCHRESULT());
     127           0 :     if (pIt != aProtocol.end())
     128             :     {
     129           0 :         if (pIt->second >>= m_aDispatchResult)
     130           0 :             m_eParts |= E_DISPATCHRESULT;
     131           0 :     }
     132             : }
     133             : 
     134             : //________________________________
     135             : /**
     136             :     @short      copy dtor
     137             :     @descr      -
     138             : */
     139           0 : JobResult::JobResult( const JobResult& rCopy )
     140           0 :     : ThreadHelpBase(&Application::GetSolarMutex())
     141             : {
     142           0 :     m_aPureResult     = rCopy.m_aPureResult     ;
     143           0 :     m_eParts          = rCopy.m_eParts          ;
     144           0 :     m_lArguments      = rCopy.m_lArguments      ;
     145           0 :     m_bDeactivate     = rCopy.m_bDeactivate     ;
     146           0 :     m_aDispatchResult = rCopy.m_aDispatchResult ;
     147           0 : }
     148             : 
     149             : //________________________________
     150             : /**
     151             :     @short      standard dtor
     152             :     @descr      Free all internaly used resources at the end of living.
     153             : */
     154         124 : JobResult::~JobResult()
     155             : {
     156             :     // Nothing realy to do here.
     157         124 : }
     158             : 
     159             : //________________________________
     160             : /**
     161             :     @short      =operator
     162             :     @descr      Must be implemented to overwrite this instance with another one.
     163             : 
     164             :     @param      rCopy
     165             :                     reference to the other instance, which should be used for copying.
     166             : */
     167           0 : void JobResult::operator=( const JobResult& rCopy )
     168             : {
     169             :     /* SAFE { */
     170           0 :     WriteGuard aWriteLock(m_aLock);
     171           0 :     m_aPureResult     = rCopy.m_aPureResult     ;
     172           0 :     m_eParts          = rCopy.m_eParts          ;
     173           0 :     m_lArguments      = rCopy.m_lArguments      ;
     174           0 :     m_bDeactivate     = rCopy.m_bDeactivate     ;
     175           0 :     m_aDispatchResult = rCopy.m_aDispatchResult ;
     176           0 :     aWriteLock.unlock();
     177             :     /* } SAFE */
     178           0 : }
     179             : 
     180             : //________________________________
     181             : /**
     182             :     @short      checks for existing parts of the analyzed result
     183             :     @descr      The internal flag mask was set after analyzing of the pure result.
     184             :                 An user of us can check here, if the required part was realy part
     185             :                 of this result. Otherwhise it would use invalid informations ...
     186             :                 by using our other members!
     187             : 
     188             :     @param      eParts
     189             :                     a flag mask too, which will be compared with our internaly set one.
     190             : 
     191             :     @return     We return true only, if any set flag of the given mask match.
     192             : */
     193           0 : sal_Bool JobResult::existPart( sal_uInt32 eParts ) const
     194             : {
     195             :     /* SAFE { */
     196           0 :     ReadGuard aReadLock(m_aLock);
     197           0 :     return ((m_eParts & eParts) == eParts);
     198             :     /* } SAFE */
     199             : }
     200             : 
     201             : //________________________________
     202             : /**
     203             :     @short      provides access to our internal members
     204             :     @descr      The return value will be valid only in case a call of
     205             :                 existPart(E_...) before returned true!
     206             : 
     207             :     @return     It returns the state of the internal member
     208             :                 without any checks!
     209             : */
     210           0 : css::uno::Sequence< css::beans::NamedValue > JobResult::getArguments() const
     211             : {
     212             :     /* SAFE { */
     213           0 :     ReadGuard aReadLock(m_aLock);
     214           0 :     return m_lArguments;
     215             :     /* } SAFE */
     216             : }
     217             : 
     218             : //________________________________
     219             : 
     220           0 : css::frame::DispatchResultEvent JobResult::getDispatchResult() const
     221             : {
     222             :     /* SAFE { */
     223           0 :     ReadGuard aReadLock(m_aLock);
     224           0 :     return m_aDispatchResult;
     225             :     /* } SAFE */
     226             : }
     227             : 
     228             : } // namespace framework
     229             : 
     230             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10