nsNetModuleStandalone.cpp 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
  2. /* This Source Code Form is subject to the terms of the Mozilla Public
  3. * License, v. 2.0. If a copy of the MPL was not distributed with this
  4. * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  5. #include "necko-config.h"
  6. #include "mozilla/ModuleUtils.h"
  7. #include "mozilla/DebugOnly.h"
  8. #include "nsCOMPtr.h"
  9. #include "nsICategoryManager.h"
  10. #include "nsIClassInfoImpl.h"
  11. #include "nsIComponentManager.h"
  12. #include "nsIServiceManager.h"
  13. #include "nsNetCID.h"
  14. #include "nsPIDNSService.h"
  15. #include "nsPISocketTransportService.h"
  16. #include "nscore.h"
  17. extern const mozilla::Module kNeckoStandaloneModule;
  18. namespace mozilla {
  19. nsresult
  20. InitNetModuleStandalone()
  21. {
  22. nsresult rv;
  23. nsCOMPtr<nsPIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID, &rv);
  24. if (NS_SUCCEEDED(rv)) {
  25. mozilla::DebugOnly<nsresult> rv = dns->Init();
  26. NS_ASSERTION(NS_SUCCEEDED(rv), "DNS service init failed");
  27. } else {
  28. NS_WARNING("failed to get dns service");
  29. }
  30. nsCOMPtr<nsPISocketTransportService> sts = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
  31. if (NS_SUCCEEDED(rv)) {
  32. mozilla::DebugOnly<nsresult> rv = sts->Init();
  33. NS_ASSERTION(NS_SUCCEEDED(rv), "Socket transport service init failed");
  34. } else {
  35. NS_WARNING("failed to get socket transport service");
  36. }
  37. return NS_OK;
  38. }
  39. nsresult
  40. ShutdownNetModuleStandalone()
  41. {
  42. nsresult rv;
  43. nsCOMPtr<nsPIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID, &rv);
  44. if (NS_SUCCEEDED(rv)) {
  45. mozilla::DebugOnly<nsresult> rv = dns->Shutdown();
  46. NS_ASSERTION(NS_SUCCEEDED(rv), "DNS service shutdown failed");
  47. } else {
  48. NS_WARNING("failed to get dns service");
  49. }
  50. nsCOMPtr<nsPISocketTransportService> sts = do_GetService(NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &rv);
  51. if (NS_SUCCEEDED(rv)) {
  52. mozilla::DebugOnly<nsresult> rv = sts->Shutdown(true);
  53. NS_ASSERTION(NS_SUCCEEDED(rv), "Socket transport service shutdown failed");
  54. } else {
  55. NS_WARNING("failed to get socket transport service");
  56. }
  57. return NS_OK;
  58. }
  59. } // namespace mozilla
  60. #include "nsDNSService2.h"
  61. NS_GENERIC_FACTORY_SINGLETON_CONSTRUCTOR(nsIDNSService,
  62. nsDNSService::GetXPCOMSingleton)
  63. #include "nsSocketTransportService2.h"
  64. typedef mozilla::net::nsSocketTransportService nsSocketTransportService;
  65. #undef LOG
  66. #undef LOG_ENABLED
  67. NS_GENERIC_FACTORY_CONSTRUCTOR_INIT(nsSocketTransportService, Init)
  68. // Net module startup hook
  69. static nsresult nsNetStartup()
  70. {
  71. return NS_OK;
  72. }
  73. // Net module shutdown hook
  74. static void nsNetShutdown()
  75. {
  76. }
  77. NS_DEFINE_NAMED_CID(NS_SOCKETTRANSPORTSERVICE_CID);
  78. NS_DEFINE_NAMED_CID(NS_DNSSERVICE_CID);
  79. static const mozilla::Module::CIDEntry kNeckoCIDs[] = {
  80. { &kNS_SOCKETTRANSPORTSERVICE_CID, false, nullptr, nsSocketTransportServiceConstructor },
  81. { &kNS_DNSSERVICE_CID, false, nullptr, nsIDNSServiceConstructor },
  82. { nullptr }
  83. };
  84. static const mozilla::Module::ContractIDEntry kNeckoContracts[] = {
  85. { NS_SOCKETTRANSPORTSERVICE_CONTRACTID, &kNS_SOCKETTRANSPORTSERVICE_CID },
  86. { NS_DNSSERVICE_CONTRACTID, &kNS_DNSSERVICE_CID },
  87. { nullptr }
  88. };
  89. const mozilla::Module kNeckoStandaloneModule = {
  90. mozilla::Module::kVersion,
  91. kNeckoCIDs,
  92. kNeckoContracts,
  93. nullptr,
  94. nullptr,
  95. nsNetStartup,
  96. nsNetShutdown
  97. };