LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/framework/source/jobs - jobresult.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 26 55 47.3 %
Date: 2013-07-09 Functions: 7 11 63.6 %
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         654 : JobResult::JobResult()
      39         654 :     : ThreadHelpBase(&Application::GetSolarMutex())
      40             : {
      41             :     // reset the flag mask!
      42             :     // It will reset the accessible state of this object.
      43             :     // That can be useful if something will fail here ...
      44         654 :     m_eParts = E_NOPART;
      45         654 : }
      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          13 : JobResult::JobResult( /*IN*/ const css::uno::Any& aResult )
      92          13 :     : ThreadHelpBase(&Application::GetSolarMutex())
      93             : {
      94             :     // safe the pure result
      95             :     // May someone need it later ...
      96          13 :     m_aPureResult = aResult;
      97             : 
      98             :     // reset the flag mask!
      99             :     // It will reset the accessible state of this object.
     100             :     // That can be useful if something will fail here ...
     101          13 :     m_eParts = E_NOPART;
     102             : 
     103             :     // analyze the result and update our other members
     104          13 :     ::comphelper::SequenceAsHashMap aProtocol(aResult);
     105          13 :     if ( aProtocol.empty() )
     106          26 :         return;
     107             : 
     108           0 :     ::comphelper::SequenceAsHashMap::const_iterator pIt = aProtocol.find(JobConst::ANSWER_DEACTIVATE_JOB());
     109           0 :     if (pIt != aProtocol.end())
     110             :     {
     111           0 :         pIt->second >>= m_bDeactivate;
     112           0 :         if (m_bDeactivate)
     113           0 :             m_eParts |= E_DEACTIVATE;
     114             :     }
     115             : 
     116           0 :     pIt = aProtocol.find(JobConst::ANSWER_SAVE_ARGUMENTS());
     117           0 :     if (pIt != aProtocol.end())
     118             :     {
     119           0 :         pIt->second >>= m_lArguments;
     120           0 :         if (m_lArguments.getLength() > 0)
     121           0 :             m_eParts |= E_ARGUMENTS;
     122             :     }
     123             : 
     124           0 :     pIt = aProtocol.find(JobConst::ANSWER_SEND_DISPATCHRESULT());
     125           0 :     if (pIt != aProtocol.end())
     126             :     {
     127           0 :         if (pIt->second >>= m_aDispatchResult)
     128           0 :             m_eParts |= E_DISPATCHRESULT;
     129           0 :     }
     130             : }
     131             : 
     132             : //________________________________
     133             : /**
     134             :     @short      copy dtor
     135             :     @descr      -
     136             : */
     137           0 : JobResult::JobResult( const JobResult& rCopy )
     138           0 :     : ThreadHelpBase(&Application::GetSolarMutex())
     139             : {
     140           0 :     m_aPureResult     = rCopy.m_aPureResult     ;
     141           0 :     m_eParts          = rCopy.m_eParts          ;
     142           0 :     m_lArguments      = rCopy.m_lArguments      ;
     143           0 :     m_bDeactivate     = rCopy.m_bDeactivate     ;
     144           0 :     m_aDispatchResult = rCopy.m_aDispatchResult ;
     145           0 : }
     146             : 
     147             : //________________________________
     148             : /**
     149             :     @short      standard dtor
     150             :     @descr      Free all internaly used resources at the end of living.
     151             : */
     152         667 : JobResult::~JobResult()
     153             : {
     154             :     // Nothing realy to do here.
     155         667 : }
     156             : 
     157             : //________________________________
     158             : /**
     159             :     @short      =operator
     160             :     @descr      Must be implemented to overwrite this instance with another one.
     161             : 
     162             :     @param      rCopy
     163             :                     reference to the other instance, which should be used for copying.
     164             : */
     165          13 : void JobResult::operator=( const JobResult& rCopy )
     166             : {
     167             :     /* SAFE { */
     168          13 :     WriteGuard aWriteLock(m_aLock);
     169          13 :     m_aPureResult     = rCopy.m_aPureResult     ;
     170          13 :     m_eParts          = rCopy.m_eParts          ;
     171          13 :     m_lArguments      = rCopy.m_lArguments      ;
     172          13 :     m_bDeactivate     = rCopy.m_bDeactivate     ;
     173          13 :     m_aDispatchResult = rCopy.m_aDispatchResult ;
     174          13 :     aWriteLock.unlock();
     175             :     /* } SAFE */
     176          13 : }
     177             : 
     178             : //________________________________
     179             : /**
     180             :     @short      checks for existing parts of the analyzed result
     181             :     @descr      The internal flag mask was set after analyzing of the pure result.
     182             :                 An user of us can check here, if the required part was realy part
     183             :                 of this result. Otherwhise it would use invalid information ...
     184             :                 by using our other members!
     185             : 
     186             :     @param      eParts
     187             :                     a flag mask too, which will be compared with our internaly set one.
     188             : 
     189             :     @return     We return true only, if any set flag of the given mask match.
     190             : */
     191          26 : sal_Bool JobResult::existPart( sal_uInt32 eParts ) const
     192             : {
     193             :     /* SAFE { */
     194          26 :     ReadGuard aReadLock(m_aLock);
     195          26 :     return ((m_eParts & eParts) == eParts);
     196             :     /* } SAFE */
     197             : }
     198             : 
     199             : //________________________________
     200             : /**
     201             :     @short      provides access to our internal members
     202             :     @descr      The return value will be valid only in case a call of
     203             :                 existPart(E_...) before returned true!
     204             : 
     205             :     @return     It returns the state of the internal member
     206             :                 without any checks!
     207             : */
     208           0 : css::uno::Sequence< css::beans::NamedValue > JobResult::getArguments() const
     209             : {
     210             :     /* SAFE { */
     211           0 :     ReadGuard aReadLock(m_aLock);
     212           0 :     return m_lArguments;
     213             :     /* } SAFE */
     214             : }
     215             : 
     216             : //________________________________
     217             : 
     218           0 : css::frame::DispatchResultEvent JobResult::getDispatchResult() const
     219             : {
     220             :     /* SAFE { */
     221           0 :     ReadGuard aReadLock(m_aLock);
     222           0 :     return m_aDispatchResult;
     223             :     /* } SAFE */
     224             : }
     225             : 
     226         402 : } // namespace framework
     227             : 
     228             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10