hxsymbiannetapi.cpp
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:8k
源码类别:

Symbian

开发平台:

C/C++

  1. /* ***** BEGIN LICENSE BLOCK ***** 
  2.  * Version: RCSL 1.0/RPSL 1.0 
  3.  *  
  4.  * Portions Copyright (c) 1995-2003 RealNetworks, Inc. All Rights Reserved. 
  5.  *      
  6.  * The contents of this file, and the files included with this file, are 
  7.  * subject to the current version of the RealNetworks Public Source License 
  8.  * Version 1.0 (the "RPSL") available at 
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed 
  10.  * the file under the RealNetworks Community Source License Version 1.0 
  11.  * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
  12.  * in which case the RCSL will apply. You may also obtain the license terms 
  13.  * directly from RealNetworks.  You may not use this file except in 
  14.  * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
  15.  * applicable to this file, the RCSL.  Please see the applicable RPSL or 
  16.  * RCSL for the rights, obligations and limitations governing use of the 
  17.  * contents of the file.  
  18.  *  
  19.  * This file is part of the Helix DNA Technology. RealNetworks is the 
  20.  * developer of the Original Code and owns the copyrights in the portions 
  21.  * it created. 
  22.  *  
  23.  * This file, and the files included with this file, is distributed and made 
  24.  * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  25.  * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  26.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
  27.  * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  28.  * 
  29.  * Technology Compatibility Kit Test Suite(s) Location: 
  30.  *    http://www.helixcommunity.org/content/tck 
  31.  * 
  32.  * Contributor(s): 
  33.  *  
  34.  * ***** END LICENSE BLOCK ***** */ 
  35. #include "platform/symbian/hxsymbiannetapi.h"
  36. #include "platform/symbian/hxsymbianresolv.h"
  37. #include "platform/symbian/hxsymbiantcpsock.h"
  38. #include "platform/symbian/hxsymbianudpsock.h"
  39. #include "platform/symbian/hxsymbianapman.h"
  40. #include "hxcloakedtcp.h"
  41. #include "hxccf.h"
  42. #include "debug.h"
  43. #define D_NETAPI 0x10000000
  44. HXNetworkServices::HXNetworkServices(IUnknown* pContext) :
  45.     m_lRefCount(0),
  46.     m_pContext(0)
  47. {
  48.     if (pContext)
  49.     {
  50. m_pContext = pContext;
  51. m_pContext->AddRef();
  52.     }
  53.     HXSymbianAccessPointManager* pAPManager = 
  54. HXSymbianAccessPointManager::CreateObject();
  55.     if (pAPManager)
  56.     {
  57. IUnknown* pOuter = (IUnknown*)(IHXNetworkServices*)this;
  58. HX_RESULT res = pAPManager->SetupAggregation(pOuter, 
  59.      &m_pAccessPointMan);
  60. if (HXR_OK == res)
  61. {
  62.     pAPManager->SetContext(pContext);
  63. }
  64. else
  65. {
  66.     pAPManager->AddRef();
  67.     HX_RELEASE(pAPManager);
  68. }
  69.     }
  70. }
  71. HXNetworkServices::~HXNetworkServices()
  72. {
  73.     HX_RELEASE(m_pAccessPointMan);
  74.     HX_RELEASE(m_pContext);
  75. }
  76.     /*
  77.      *  IUnknown methods
  78.      */
  79. STDMETHODIMP HXNetworkServices::QueryInterface(THIS_
  80.        REFIID riid,
  81.        void** ppvObj)
  82. {
  83.     DPRINTF(D_NETAPI, ("HXNetworkServices::QueryInterface()n"));
  84.     QInterfaceList qiList[] =
  85.     {
  86. { GET_IIDHANDLE(IID_IUnknown), (IUnknown*)(IHXNetworkServices*)this },
  87. { GET_IIDHANDLE(IID_IHXNetworkServices), (IHXNetworkServices*) this },
  88. { GET_IIDHANDLE(IID_IHXCloakedNetworkServices), (IHXCloakedNetworkServices*) this },
  89.     };
  90.     HX_RESULT res = QIFind(qiList, QILISTSIZE(qiList), riid, ppvObj);
  91.     if ((HXR_OK != res) && m_pAccessPointMan)
  92.     {
  93. res = m_pAccessPointMan->QueryInterface(riid, ppvObj);
  94.     }
  95.     return res;
  96. }
  97. STDMETHODIMP_(ULONG32) HXNetworkServices::AddRef(THIS)
  98. {
  99.     return InterlockedIncrement(&m_lRefCount);
  100. }
  101. STDMETHODIMP_(ULONG32)HXNetworkServices::Release(THIS)
  102. {
  103.     if (InterlockedDecrement(&m_lRefCount) > 0)
  104.     {
  105.         return m_lRefCount;
  106.     }
  107.     
  108.     delete this;
  109.     return 0;
  110. }
  111.     /*
  112.      * IHXNetworkServices methods
  113.      */
  114.     /************************************************************************
  115.      * Method:
  116.      *     IHXNetworkServices::CreateTCPSocket
  117.      * Purpose:
  118.      *     Create a new TCP socket.
  119.      */
  120. STDMETHODIMP HXNetworkServices::CreateTCPSocket(THIS_
  121. IHXTCPSocket**    /*OUT*/  ppTCPSocket)
  122. {
  123.     DPRINTF(D_NETAPI, ("HXNetworkServices::CreateTCPSocket()n"));
  124.     HX_RESULT res = HXR_FAILED;
  125.     IHXCommonClassFactory* pCCF = 0;
  126.     if (m_pContext &&
  127. (m_pContext->QueryInterface(IID_IHXCommonClassFactory, 
  128.     (void**)&pCCF) == HXR_OK) && pCCF)
  129.     {
  130. IHXResolver* pResolver = 0;
  131. res = CreateResolver(&pResolver);
  132. if (res == HXR_OK)
  133. {
  134.     *ppTCPSocket = new HXSymbianTCPSocket(pCCF, pResolver);
  135.     if (*ppTCPSocket)
  136.     {
  137. (*ppTCPSocket)->AddRef();
  138. res = HXR_OK;
  139.     }
  140.     else
  141.     {
  142. res = HXR_OUTOFMEMORY;
  143.     }
  144. }
  145. HX_RELEASE(pResolver);
  146.     }
  147.     HX_RELEASE(pCCF);
  148.     return res;
  149. }
  150.     /************************************************************************
  151.      * Method:
  152.      *     IHXNetworkServices::CreateUDPSocket
  153.      * Purpose:
  154.      *     Create a new UDP socket.
  155.      */
  156. STDMETHODIMP HXNetworkServices::CreateUDPSocket(THIS_
  157. IHXUDPSocket**    /*OUT*/  ppUDPSocket)
  158. {
  159.     DPRINTF(D_NETAPI, ("HXNetworkServices::CreateUDPSocket()n"));
  160.     
  161.     HX_RESULT res = HXR_FAILED;
  162.     IHXCommonClassFactory* pCCF = 0;
  163.     if (m_pContext &&
  164. (m_pContext->QueryInterface(IID_IHXCommonClassFactory, 
  165.     (void**)&pCCF) == HXR_OK) &&
  166. pCCF)
  167.     {
  168. *ppUDPSocket = new HXSymbianUDPSocket(pCCF);
  169. if (*ppUDPSocket)
  170. {
  171.     (*ppUDPSocket)->AddRef();
  172.     res = HXR_OK;
  173. }
  174. else
  175. {
  176.     res = HXR_OUTOFMEMORY;
  177. }
  178.     }
  179.     HX_RELEASE(pCCF);
  180.     return res;
  181. }
  182.     /************************************************************************
  183.      * Method:
  184.      *     IHXNetworkServices::CreateListenSocket
  185.      * Purpose:
  186.      *     Create a new TCP socket that will listen for connections on a
  187.      *     particular port.
  188.      */
  189. STDMETHODIMP HXNetworkServices::CreateListenSocket(THIS_
  190.     IHXListenSocket** /*OUT*/ ppListenSocket)
  191. {
  192.     DPRINTF(D_NETAPI, ("HXNetworkServices::CreateListenSocket()n"));
  193.     return HXR_NOTIMPL;
  194. }
  195.     /************************************************************************
  196.      * Method:
  197.      *     IHXNetworkServices::CreateResolver
  198.      * Purpose:
  199.      *     Create a new resolver that can lookup host names
  200.      */
  201. STDMETHODIMP HXNetworkServices::CreateResolver(THIS_
  202.      IHXResolver**    /*OUT*/     ppResolver)
  203. {
  204.     DPRINTF(D_NETAPI, ("HXNetworkServices::CreateResolver()n"));
  205.     HX_RESULT res = HXR_OUTOFMEMORY;
  206.     *ppResolver = new HXSymbianResolver(m_pContext);
  207.     if (*ppResolver)
  208.     {
  209. (*ppResolver)->AddRef();
  210. res = HXR_OK;
  211.     }
  212.     return res;
  213. }
  214.     /*
  215.      * IHXNetworkCloakedServices methods
  216.      */
  217.     /************************************************************************
  218.      * Method:
  219.      *     IHXCloakedNetworkServices::CreateClientCloakedSocket
  220.      * Purpose:
  221.      *     Create a new HTTP cloaked TCP socket for the client.
  222.      */
  223. STDMETHODIMP HXNetworkServices::CreateClientCloakedSocket(THIS_
  224. IHXTCPSocket**    /*OUT*/     ppTCPSocket)
  225. {
  226.     DPRINTF(D_NETAPI, ("HXNetworkServices::CreateClientCloakedSocket()n"));
  227. #if defined(HELIX_FEATURE_HTTPCLOAK)
  228.     HX_RESULT res = HXR_FAILED;
  229.     if (m_pContext)
  230.     {
  231. *ppTCPSocket = new HXClientCloakedTCPSocket(m_pContext);
  232. if (*ppTCPSocket)
  233. {
  234.     (*ppTCPSocket)->AddRef();
  235.     res = HXR_OK;
  236. }
  237. else
  238. {
  239.     res = HXR_OUTOFMEMORY;
  240. }
  241.     }
  242.     return res;
  243. #else
  244.     return HXR_NOTIMPL;
  245. #endif /* HELIX_FEATURE_HTTPCLOAK */
  246. }
  247.     /************************************************************************
  248.      * Method:
  249.      *     IHXCloakedNetworkServices::CreateServerCloakedSocket
  250.      * Purpose:
  251.      *     Create a new HTTP cloaked TCP socket that will listen for 
  252.      *      connections on a particular port.
  253.      */
  254. STDMETHODIMP HXNetworkServices::CreateServerCloakedSocket(THIS_
  255. IHXListenSocket**    /*OUT*/     ppListenSocket)
  256. {
  257.     DPRINTF(D_NETAPI, ("HXNetworkServices::CreateServerCloakedSocket()n"));
  258.     return HXR_NOTIMPL;
  259. }
  260. void HXNetworkServices::Close()
  261. {
  262.     DPRINTF(D_NETAPI, ("HXNetworkServices::Close()n"));
  263.     HX_RELEASE(m_pContext);
  264. }