LCOV - code coverage report
Current view: top level - basic/source/runtime - ddectrl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 9 78 11.5 %
Date: 2012-08-25 Functions: 3 12 25.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 4 106 3.8 %

           Branch data     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 <tools/errcode.hxx>
      21                 :            : #include <svl/svdde.hxx>
      22                 :            : #include "ddectrl.hxx"
      23                 :            : #include <basic/sberrors.hxx>
      24                 :            : 
      25                 :            : #define DDE_FREECHANNEL ((DdeConnection*)0xffffffff)
      26                 :            : 
      27                 :            : #define DDE_FIRSTERR    0x4000
      28                 :            : #define DDE_LASTERR     0x4011
      29                 :            : 
      30                 :            : static const SbError nDdeErrMap[] =
      31                 :            : {
      32                 :            :     /* DMLERR_ADVACKTIMEOUT       */  0x4000, SbERR_DDE_TIMEOUT,
      33                 :            :     /* DMLERR_BUSY                */  0x4001, SbERR_DDE_BUSY,
      34                 :            :     /* DMLERR_DATAACKTIMEOUT      */  0x4002, SbERR_DDE_TIMEOUT,
      35                 :            :     /* DMLERR_DLL_NOT_INITIALIZED */  0x4003, SbERR_DDE_ERROR,
      36                 :            :     /* DMLERR_DLL_USAGE           */  0x4004, SbERR_DDE_ERROR,
      37                 :            :     /* DMLERR_EXECACKTIMEOUT      */  0x4005, SbERR_DDE_TIMEOUT,
      38                 :            :     /* DMLERR_INVALIDPARAMETER    */  0x4006, SbERR_DDE_ERROR,
      39                 :            :     /* DMLERR_LOW_MEMORY          */  0x4007, SbERR_DDE_ERROR,
      40                 :            :     /* DMLERR_MEMORY_ERROR        */  0x4008, SbERR_DDE_ERROR,
      41                 :            :     /* DMLERR_NOTPROCESSED        */  0x4009, SbERR_DDE_NOTPROCESSED,
      42                 :            :     /* DMLERR_NO_CONV_ESTABLISHED */  0x400a, SbERR_DDE_NO_CHANNEL,
      43                 :            :     /* DMLERR_POKEACKTIMEOUT      */  0x400b, SbERR_DDE_TIMEOUT,
      44                 :            :     /* DMLERR_POSTMSG_FAILED      */  0x400c, SbERR_DDE_QUEUE_OVERFLOW,
      45                 :            :     /* DMLERR_REENTRANCY          */  0x400d, SbERR_DDE_ERROR,
      46                 :            :     /* DMLERR_SERVER_DIED         */  0x400e, SbERR_DDE_PARTNER_QUIT,
      47                 :            :     /* DMLERR_SYS_ERROR           */  0x400f, SbERR_DDE_ERROR,
      48                 :            :     /* DMLERR_UNADVACKTIMEOUT     */  0x4010, SbERR_DDE_TIMEOUT,
      49                 :            :     /* DMLERR_UNFOUND_QUEUE_ID    */  0x4011, SbERR_DDE_NO_CHANNEL
      50                 :            : };
      51                 :            : 
      52                 :          0 : SbError SbiDdeControl::GetLastErr( DdeConnection* pConv )
      53                 :            : {
      54         [ #  # ]:          0 :     if( !pConv )
      55                 :          0 :         return 0;
      56                 :          0 :     long nErr = pConv->GetError();
      57         [ #  # ]:          0 :     if( !nErr )
      58                 :          0 :         return 0;
      59 [ #  # ][ #  # ]:          0 :     if( nErr < DDE_FIRSTERR || nErr > DDE_LASTERR )
      60                 :          0 :         return SbERR_DDE_ERROR;
      61                 :          0 :     return nDdeErrMap[ 2*(nErr - DDE_FIRSTERR) + 1 ];
      62                 :            : }
      63                 :            : 
      64         [ #  # ]:          0 : IMPL_LINK_INLINE( SbiDdeControl,Data , DdeData*, pData,
      65                 :            : {
      66                 :            :     aData = rtl::OUString::createFromAscii( (const char*)(const void*)*pData );
      67                 :            :     return 1;
      68                 :            : }
      69                 :            : )
      70                 :            : 
      71         [ +  - ]:         41 : SbiDdeControl::SbiDdeControl()
      72                 :            : {
      73                 :         41 : }
      74                 :            : 
      75         [ +  - ]:         41 : SbiDdeControl::~SbiDdeControl()
      76                 :            : {
      77         [ +  - ]:         41 :     TerminateAll();
      78                 :         41 : }
      79                 :            : 
      80                 :          0 : sal_Int16 SbiDdeControl::GetFreeChannel()
      81                 :            : {
      82                 :          0 :     sal_Int16 nChannel = 0;
      83                 :          0 :     sal_Int16 nListSize = static_cast<sal_Int16>(aConvList.size());
      84                 :            : 
      85         [ #  # ]:          0 :     for (; nChannel < nListSize; ++nChannel)
      86                 :            :     {
      87         [ #  # ]:          0 :         if (aConvList[nChannel] == DDE_FREECHANNEL)
      88                 :          0 :             return nChannel+1;
      89                 :            :     }
      90                 :            : 
      91         [ #  # ]:          0 :     aConvList.push_back(DDE_FREECHANNEL);
      92                 :          0 :     return nChannel+1;
      93                 :            : }
      94                 :            : 
      95                 :          0 : SbError SbiDdeControl::Initiate( const String& rService, const String& rTopic,
      96                 :            :             sal_Int16& rnHandle )
      97                 :            : {
      98                 :            :     SbError nErr;
      99         [ #  # ]:          0 :     DdeConnection* pConv = new DdeConnection( rService, rTopic );
     100                 :          0 :     nErr = GetLastErr( pConv );
     101         [ #  # ]:          0 :     if( nErr )
     102                 :            :     {
     103         [ #  # ]:          0 :         delete pConv;
     104                 :          0 :         rnHandle = 0;
     105                 :            :     }
     106                 :            :     else
     107                 :            :     {
     108                 :          0 :         sal_Int16 nChannel = GetFreeChannel();
     109                 :          0 :         aConvList[nChannel-1] = pConv;
     110                 :          0 :         rnHandle = nChannel;
     111                 :            :     }
     112                 :          0 :     return 0;
     113                 :            : }
     114                 :            : 
     115                 :          0 : SbError SbiDdeControl::Terminate( sal_uInt16 nChannel )
     116                 :            : {
     117 [ #  # ][ #  # ]:          0 :     if (!nChannel || nChannel > aConvList.size())
                 [ #  # ]
     118                 :          0 :         return SbERR_DDE_NO_CHANNEL;
     119                 :            : 
     120                 :          0 :     DdeConnection* pConv = aConvList[nChannel-1];
     121                 :            : 
     122         [ #  # ]:          0 :     if( pConv == DDE_FREECHANNEL )
     123                 :          0 :         return SbERR_DDE_NO_CHANNEL;
     124                 :            : 
     125         [ #  # ]:          0 :     delete pConv;
     126                 :          0 :     pConv = DDE_FREECHANNEL;
     127                 :            : 
     128                 :          0 :     return 0L;
     129                 :            : }
     130                 :            : 
     131                 :         41 : SbError SbiDdeControl::TerminateAll()
     132                 :            : {
     133                 :            :     DdeConnection *conv;
     134         [ -  + ]:         41 :     for (sal_uInt16 nChannel = 0; nChannel < aConvList.size(); ++nChannel)
     135                 :            :     {
     136                 :          0 :         conv = aConvList[nChannel];
     137                 :            : 
     138         [ #  # ]:          0 :         if (conv != DDE_FREECHANNEL)
     139         [ #  # ]:          0 :             delete conv;
     140                 :            :     }
     141                 :            : 
     142                 :         41 :     aConvList.clear();
     143                 :            : 
     144                 :         41 :     return 0;
     145                 :            : }
     146                 :            : 
     147                 :          0 : SbError SbiDdeControl::Request( sal_uInt16 nChannel, const String& rItem, String& rResult )
     148                 :            : {
     149 [ #  # ][ #  # ]:          0 :     if (!nChannel || nChannel > aConvList.size())
                 [ #  # ]
     150                 :          0 :         return SbERR_DDE_NO_CHANNEL;
     151                 :            : 
     152         [ #  # ]:          0 :     DdeConnection* pConv = aConvList[nChannel-1];
     153                 :            : 
     154         [ #  # ]:          0 :     if( pConv == DDE_FREECHANNEL )
     155                 :          0 :         return SbERR_DDE_NO_CHANNEL;
     156                 :            : 
     157         [ #  # ]:          0 :     DdeRequest aRequest( *pConv, rItem, 30000 );
     158         [ #  # ]:          0 :     aRequest.SetDataHdl( LINK( this, SbiDdeControl, Data ) );
     159         [ #  # ]:          0 :     aRequest.Execute();
     160         [ #  # ]:          0 :     rResult = aData;
     161 [ #  # ][ #  # ]:          0 :     return GetLastErr( pConv );
     162                 :            : }
     163                 :            : 
     164                 :          0 : SbError SbiDdeControl::Execute( sal_uInt16 nChannel, const String& rCommand )
     165                 :            : {
     166 [ #  # ][ #  # ]:          0 :     if (!nChannel || nChannel > aConvList.size())
                 [ #  # ]
     167                 :          0 :         return SbERR_DDE_NO_CHANNEL;
     168                 :            : 
     169         [ #  # ]:          0 :     DdeConnection* pConv = aConvList[nChannel-1];
     170                 :            : 
     171         [ #  # ]:          0 :     if( pConv == DDE_FREECHANNEL )
     172                 :          0 :         return SbERR_DDE_NO_CHANNEL;
     173                 :            : 
     174         [ #  # ]:          0 :     DdeExecute aRequest( *pConv, rCommand, 30000 );
     175         [ #  # ]:          0 :     aRequest.Execute();
     176 [ #  # ][ #  # ]:          0 :     return GetLastErr( pConv );
     177                 :            : }
     178                 :            : 
     179                 :          0 : SbError SbiDdeControl::Poke( sal_uInt16 nChannel, const String& rItem, const String& rData )
     180                 :            : {
     181 [ #  # ][ #  # ]:          0 :     if (!nChannel || nChannel > aConvList.size())
                 [ #  # ]
     182                 :          0 :         return SbERR_DDE_NO_CHANNEL;
     183                 :            : 
     184         [ #  # ]:          0 :     DdeConnection* pConv = aConvList[nChannel-1];
     185                 :            : 
     186         [ #  # ]:          0 :     if( pConv == DDE_FREECHANNEL )
     187                 :          0 :         return SbERR_DDE_NO_CHANNEL;
     188                 :            : 
     189 [ #  # ][ #  # ]:          0 :     DdePoke aRequest( *pConv, rItem, DdeData(rData), 30000 );
                 [ #  # ]
     190         [ #  # ]:          0 :     aRequest.Execute();
     191 [ #  # ][ #  # ]:          0 :     return GetLastErr( pConv );
     192                 :            : }
     193                 :            : 
     194                 :            : 
     195                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10