LCOV - code coverage report
Current view: top level - basic/source/runtime - ddectrl.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 78 0.0 %
Date: 2014-04-14 Functions: 0 12 0.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             : #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             :     {
      56           0 :         return 0;
      57             :     }
      58           0 :     long nErr = pConv->GetError();
      59           0 :     if( !nErr )
      60             :     {
      61           0 :         return 0;
      62             :     }
      63           0 :     if( nErr < DDE_FIRSTERR || nErr > DDE_LASTERR )
      64             :     {
      65           0 :         return SbERR_DDE_ERROR;
      66             :     }
      67           0 :     return nDdeErrMap[ 2 * (nErr - DDE_FIRSTERR) + 1 ];
      68             : }
      69             : 
      70           0 : IMPL_LINK_INLINE( SbiDdeControl,Data , DdeData*, pData,
      71             : {
      72             :     aData = OUString::createFromAscii( (const char*)(const void*)*pData );
      73             :     return 1;
      74             : }
      75             : )
      76             : 
      77           0 : SbiDdeControl::SbiDdeControl()
      78             : {
      79           0 : }
      80             : 
      81           0 : SbiDdeControl::~SbiDdeControl()
      82             : {
      83           0 :     TerminateAll();
      84           0 : }
      85             : 
      86           0 : size_t SbiDdeControl::GetFreeChannel()
      87             : {
      88           0 :     size_t nChannel = 0;
      89           0 :     size_t nListSize = aConvList.size();
      90             : 
      91           0 :     for (; nChannel < nListSize; ++nChannel)
      92             :     {
      93           0 :         if (aConvList[nChannel] == DDE_FREECHANNEL)
      94             :         {
      95           0 :             return nChannel+1;
      96             :         }
      97             :     }
      98             : 
      99           0 :     aConvList.push_back(DDE_FREECHANNEL);
     100           0 :     return nChannel+1;
     101             : }
     102             : 
     103           0 : SbError SbiDdeControl::Initiate( const OUString& rService, const OUString& rTopic,
     104             :                                  size_t& rnHandle )
     105             : {
     106             :     SbError nErr;
     107           0 :     DdeConnection* pConv = new DdeConnection( rService, rTopic );
     108           0 :     nErr = GetLastErr( pConv );
     109           0 :     if( nErr )
     110             :     {
     111           0 :         delete pConv;
     112           0 :         rnHandle = 0;
     113             :     }
     114             :     else
     115             :     {
     116           0 :         size_t nChannel = GetFreeChannel();
     117           0 :         aConvList[nChannel-1] = pConv;
     118           0 :         rnHandle = nChannel;
     119             :     }
     120           0 :     return 0;
     121             : }
     122             : 
     123           0 : SbError SbiDdeControl::Terminate( size_t nChannel )
     124             : {
     125           0 :     if (!nChannel || nChannel > aConvList.size())
     126             :     {
     127           0 :         return SbERR_DDE_NO_CHANNEL;
     128             :     }
     129           0 :     DdeConnection* pConv = aConvList[nChannel-1];
     130             : 
     131           0 :     if( pConv == DDE_FREECHANNEL )
     132             :     {
     133           0 :         return SbERR_DDE_NO_CHANNEL;
     134             :     }
     135           0 :     delete pConv;
     136           0 :     pConv = DDE_FREECHANNEL;
     137             : 
     138           0 :     return 0L;
     139             : }
     140             : 
     141           0 : SbError SbiDdeControl::TerminateAll()
     142             : {
     143             :     DdeConnection *conv;
     144           0 :     for (size_t nChannel = 0; nChannel < aConvList.size(); ++nChannel)
     145             :     {
     146           0 :         conv = aConvList[nChannel];
     147             : 
     148           0 :         if (conv != DDE_FREECHANNEL)
     149             :         {
     150           0 :             delete conv;
     151             :         }
     152             :     }
     153             : 
     154           0 :     aConvList.clear();
     155             : 
     156           0 :     return 0;
     157             : }
     158             : 
     159           0 : SbError SbiDdeControl::Request( size_t nChannel, const OUString& rItem, OUString& rResult )
     160             : {
     161           0 :     if (!nChannel || nChannel > aConvList.size())
     162             :     {
     163           0 :         return SbERR_DDE_NO_CHANNEL;
     164             :     }
     165             : 
     166           0 :     DdeConnection* pConv = aConvList[nChannel-1];
     167             : 
     168           0 :     if( pConv == DDE_FREECHANNEL )
     169             :     {
     170           0 :         return SbERR_DDE_NO_CHANNEL;
     171             :     }
     172             : 
     173           0 :     DdeRequest aRequest( *pConv, rItem, 30000 );
     174           0 :     aRequest.SetDataHdl( LINK( this, SbiDdeControl, Data ) );
     175           0 :     aRequest.Execute();
     176           0 :     rResult = aData;
     177           0 :     return GetLastErr( pConv );
     178             : }
     179             : 
     180           0 : SbError SbiDdeControl::Execute( size_t nChannel, const OUString& rCommand )
     181             : {
     182           0 :     if (!nChannel || nChannel > aConvList.size())
     183             :     {
     184           0 :         return SbERR_DDE_NO_CHANNEL;
     185             :     }
     186             : 
     187           0 :     DdeConnection* pConv = aConvList[nChannel-1];
     188             : 
     189           0 :     if( pConv == DDE_FREECHANNEL )
     190             :     {
     191           0 :         return SbERR_DDE_NO_CHANNEL;
     192             :     }
     193           0 :     DdeExecute aRequest( *pConv, rCommand, 30000 );
     194           0 :     aRequest.Execute();
     195           0 :     return GetLastErr( pConv );
     196             : }
     197             : 
     198           0 : SbError SbiDdeControl::Poke( size_t nChannel, const OUString& rItem, const OUString& rData )
     199             : {
     200           0 :     if (!nChannel || nChannel > aConvList.size())
     201             :     {
     202           0 :         return SbERR_DDE_NO_CHANNEL;
     203             :     }
     204           0 :     DdeConnection* pConv = aConvList[nChannel-1];
     205             : 
     206           0 :     if( pConv == DDE_FREECHANNEL )
     207             :     {
     208           0 :         return SbERR_DDE_NO_CHANNEL;
     209             :     }
     210           0 :     DdePoke aRequest( *pConv, rItem, DdeData(rData), 30000 );
     211           0 :     aRequest.Execute();
     212           0 :     return GetLastErr( pConv );
     213             : }
     214             : 
     215             : 
     216             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10