activopt.cpp
Upload User: dangjiwu
Upload Date: 2013-07-19
Package Size: 42019k
Code Size: 8k
Category:

Symbian

Development Platform:

Visual C++

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Source last modified: $Id: activopt.cpp,v 1.3.32.3 2004/07/09 01:48:15 hubbe Exp $
  3.  * 
  4.  * Portions Copyright (c) 1995-2004 RealNetworks, Inc. All Rights Reserved.
  5.  * 
  6.  * The contents of this file, and the files included with this file,
  7.  * are subject to the current version of the RealNetworks Public
  8.  * Source License (the "RPSL") available at
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed
  10.  * the file under the current version of the RealNetworks Community
  11.  * Source License (the "RCSL") available at
  12.  * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
  13.  * will apply. You may also obtain the license terms directly from
  14.  * RealNetworks.  You may not use this file except in compliance with
  15.  * the RPSL or, if you have a valid RCSL with RealNetworks applicable
  16.  * to this file, the RCSL.  Please see the applicable RPSL or RCSL for
  17.  * the rights, obligations and limitations governing use of the
  18.  * contents of the file.
  19.  * 
  20.  * Alternatively, the contents of this file may be used under the
  21.  * terms of the GNU General Public License Version 2 or later (the
  22.  * "GPL") in which case the provisions of the GPL are applicable
  23.  * instead of those above. If you wish to allow use of your version of
  24.  * this file only under the terms of the GPL, and not to allow others
  25.  * to use your version of this file under the terms of either the RPSL
  26.  * or RCSL, indicate your decision by deleting the provisions above
  27.  * and replace them with the notice and other provisions required by
  28.  * the GPL. If you do not delete the provisions above, a recipient may
  29.  * use your version of this file under the terms of any one of the
  30.  * RPSL, the RCSL or the GPL.
  31.  * 
  32.  * This file is part of the Helix DNA Technology. RealNetworks is the
  33.  * developer of the Original Code and owns the copyrights in the
  34.  * portions it created.
  35.  * 
  36.  * This file, and the files included with this file, is distributed
  37.  * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
  38.  * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
  39.  * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
  40.  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
  41.  * ENJOYMENT OR NON-INFRINGEMENT.
  42.  * 
  43.  * Technology Compatibility Kit Test Suite(s) Location:
  44.  *    http://www.helixcommunity.org/content/tck
  45.  * 
  46.  * Contributor(s):
  47.  * 
  48.  * ***** END LICENSE BLOCK ***** */
  49. #include "hlxclib/stdlib.h"
  50. #ifdef _BENG_DEBUG
  51. #include "hlxclib/stdio.h"
  52. #endif /* _BENG_DEBUG */
  53. #include "hxtypes.h"
  54. #include "hxcom.h"
  55. #include "hxcomm.h"
  56. #include "hxplugn.h"
  57. #include "hxformt.h"
  58. #include "ihxpckts.h"
  59. #include "hxmon.h"
  60. #include "hxallow.h"
  61. #include "hxerror.h"
  62. #include "hxengin.h"
  63. #include "hxslist.h"
  64. #include "hxstrutl.h"
  65. #include "hxbuffer.h"
  66. #include "activewrap.h"
  67. #include "activopt.h"
  68. #ifdef _BENG_DEBUG
  69.     #define DUMP Dump()
  70. #else
  71.     #define DUMP 
  72. #endif
  73. CActiveOptions::CActiveOptions()
  74.     : m_lRefCount(0)
  75.     , m_pContext(0)
  76.     , m_pOptions(0)
  77. {
  78. }
  79. CActiveOptions::~CActiveOptions()
  80. {
  81.     HX_RELEASE(m_pOptions);
  82.     HX_RELEASE(m_pContext);
  83. }
  84. STDMETHODIMP_(ULONG32)
  85. CActiveOptions::AddRef()
  86. {
  87.     return InterlockedIncrement(&m_lRefCount);
  88. }
  89. STDMETHODIMP_(ULONG32)
  90. CActiveOptions::Release()
  91. {
  92.     if (InterlockedDecrement(&m_lRefCount) > 0)
  93.     {
  94.         return m_lRefCount;
  95.     }
  96.     delete this;
  97.     return 0;
  98. }
  99. HX_RESULT
  100. CActiveOptions::Init(IUnknown* pContext, IHXValues* pOptions)
  101. {
  102.     if (!(pContext || pOptions))
  103. return HXR_FAIL;
  104.     HX_RELEASE(m_pContext);
  105.     m_pContext = pContext;
  106.     m_pContext->AddRef();
  107.     HX_RELEASE(m_pOptions);
  108.     m_pOptions = pOptions;
  109.     pOptions->AddRef();
  110.     IHXBuffer* pLongName = 0;
  111.     CActivePropWrapper* pActiveReg = 0;
  112.     HX_RESULT res = pOptions->GetPropertyBuffer("LongName", pLongName);
  113.     if (HXR_OK != res)
  114.     {
  115. goto cleanup;
  116.     }
  117.     
  118.     //printf( "CActiveOptions::Init(): Setting %s options activen", GetLongName());
  119.     pActiveReg = new CActivePropWrapper();
  120.     if (!pActiveReg)
  121.     {
  122.      res = HXR_FAILED ;
  123. goto cleanup;
  124.     }
  125.     pActiveReg->AddRef();
  126.     res = pActiveReg->Init(pContext, (CActivePropWrapperUser*) this);
  127.     if (HXR_OK != res)
  128.     {
  129. goto cleanup;
  130.     }
  131.     res = pActiveReg->SetAsActive((const char*)pLongName->GetBuffer());
  132.     if (res != HXR_OK)
  133.     {
  134. goto cleanup;
  135.     }
  136. cleanup:
  137.     HX_RELEASE(pLongName);
  138.     HX_RELEASE(pActiveReg);
  139.     return res;
  140. }
  141. /*
  142.     CActivePropWrapperUser methods
  143. */
  144. HX_RESULT
  145. CActiveOptions::PropUpdated (REF(CHXString) strName, REF(UINT32) ulVal, REF(CHXString) strErr)
  146. {
  147.     CHXString strProp;
  148.     HX_RESULT res = GetPropName(strName, strProp);
  149.     if ((HXR_OK != res) || strProp.IsEmpty())
  150.     {
  151. return res;
  152.     }
  153.     m_pOptions->SetPropertyULONG32((const char*)strProp, ulVal);
  154.     //DUMP;
  155.     return HXR_OK ;
  156. }
  157. HX_RESULT
  158. CActiveOptions::PropUpdated (REF(CHXString) strName, REF(CHXString) strVal, REF(CHXString) strErr)
  159. {
  160.     CHXString strProp;
  161.     HX_RESULT res = GetPropName(strName, strProp);
  162.     if ((HXR_OK != res) || strProp.IsEmpty())
  163.     {
  164. return res;
  165.     }
  166.     IHXBuffer* pBuf = 0;
  167.     IHXCommonClassFactory* pClassFactory = 0;
  168.     res = m_pContext->QueryInterface(IID_IHXCommonClassFactory,
  169.      (void**)&pClassFactory);
  170.     if (HXR_OK != res)
  171.     {
  172. goto cleanup;
  173.     }
  174.     res = pClassFactory->CreateInstance(CLSID_IHXBuffer,(void**)&pBuf);
  175.     if (HXR_OK != res)
  176.     {
  177. goto cleanup;
  178.     }
  179.     pBuf->Set((const unsigned char*)(const char*)strVal, strVal.GetLength() + 1);
  180.     res = m_pOptions->SetPropertyBuffer((const char*)strProp, pBuf);
  181.     //DUMP;
  182. cleanup:
  183.     HX_RELEASE(pClassFactory);
  184.     HX_RELEASE(pBuf);
  185.     return res;
  186. }
  187. HX_RESULT
  188. CActiveOptions::PropDeleted (REF(CHXString) strName, REF(CHXString) strErr)
  189. {
  190.     // deleting a property is not supported by IHXValues
  191.     return HXR_OK ;
  192. }
  193. HX_RESULT
  194. CActiveOptions::GetPropName(REF(CHXString) strName, REF(CHXString) strProp)
  195. {
  196.     strProp.Empty();
  197.     IHXBuffer* pLongName = 0;
  198.     HX_RESULT res = m_pOptions->GetPropertyBuffer("LongName", pLongName);
  199.     if (HXR_OK != res)
  200.     {
  201. return HXR_FAILED;
  202.     }
  203.     res = HXR_OK;
  204.     // we only care about the first level of properties under the longname list
  205.     // so strip off the last segment of strName and compare this to the LongName: 
  206.     // they should be equal
  207.     int pos = strName.ReverseFind('.');
  208.     if ((pos == -1) ||
  209. (strName.Left(pos) != (const char*)pLongName->GetBuffer()))
  210.     {
  211. goto cleanup;
  212.     }
  213.     strProp = strName.Right(strName.GetLength()-pos-1);
  214.     // reject changes to the 'read-only' properties: MountPoint, LongName and ShortName
  215.     if ((strProp == "MountPoint") ||
  216. (strProp == "ShortName") ||
  217. (strProp == "LongName"))
  218.     {
  219. res = HXR_FAILED;
  220.     }
  221.     
  222. cleanup:
  223.     HX_RELEASE(pLongName);
  224.     return res;
  225. }
  226. #ifdef _BENG_DEBUG
  227. void
  228. CActiveOptions::Dump()
  229. {
  230.     HX_RESULT res;
  231.     UINT32 ulVal;
  232.     const char* pName;
  233.     IHXBuffer* pBuf;
  234.     m_pOptions->GetPropertyBuffer("LongName", pBuf);
  235.     printf( "%s options:n", (const char*)pBuf->GetBuffer());
  236.     HX_RELEASE(pBuf);
  237.     res = m_pOptions->GetFirstPropertyULONG32(pName, ulVal);
  238.     while(res == HXR_OK)
  239.     {
  240. printf( "t%s:t%dn", pName, ulVal );
  241. res = m_pOptions->GetNextPropertyULONG32(pName, ulVal);
  242.     }
  243.     res = m_pOptions->GetFirstPropertyBuffer(pName, pBuf);
  244.     while(res == HXR_OK)
  245.     {
  246. printf( "t%s:t%sn", pName, (const char*)pBuf->GetBuffer());
  247. HX_RELEASE(pBuf);
  248. res = m_pOptions->GetNextPropertyBuffer(pName, pBuf);
  249.     }
  250.     res = m_pOptions->GetFirstPropertyCString(pName, pBuf);
  251.     while(res == HXR_OK)
  252.     {
  253. printf( "t%s:t%sn", pName, (const char*)pBuf->GetBuffer());
  254. HX_RELEASE(pBuf);
  255. res = m_pOptions->GetNextPropertyCString(pName, pBuf);
  256.     }
  257. }
  258. #endif