labath updated this revision to Diff 103971.
labath added a comment.

This is how things would look like if we move Connection to Utility instead. I
needed to do two things to make this happen:

- Keep Connection::CreateDefaultConnection in Host (now known as 
Host::CreateDefaultConnection), because this actually creates concrete 
instances).
- Move IOObject to Utility as well. Connection interface was depending on this 
class. Although theoretically a forward declaration could suffice, we still 
shouldn't depend on stuff forward-declared in another module. The same 
rationale can apply to this class as well -- it's an abstract interface, which 
can live in Utility, and all concrete instances can (hopefully) stay in Host.


https://reviews.llvm.org/D34400

Files:
  include/lldb/Core/Connection.h
  include/lldb/Host/File.h
  include/lldb/Host/Host.h
  include/lldb/Host/IOObject.h
  include/lldb/Host/MainLoopBase.h
  include/lldb/Host/Socket.h
  include/lldb/Host/posix/ConnectionFileDescriptorPosix.h
  include/lldb/Host/windows/ConnectionGenericFileWindows.h
  include/lldb/Utility/Connection.h
  include/lldb/Utility/IOObject.h
  source/API/SBCommunication.cpp
  source/Core/CMakeLists.txt
  source/Core/Communication.cpp
  source/Core/Connection.cpp
  source/Host/CMakeLists.txt
  source/Host/common/Host.cpp
  source/Host/common/IOObject.cpp
  source/Host/posix/ConnectionFileDescriptorPosix.cpp
  source/Utility/CMakeLists.txt
  source/Utility/Connection.cpp
  source/Utility/IOObject.cpp
  tools/lldb-server/Acceptor.h

Index: tools/lldb-server/Acceptor.h
===================================================================
--- tools/lldb-server/Acceptor.h
+++ tools/lldb-server/Acceptor.h
@@ -9,7 +9,7 @@
 #ifndef lldb_server_Acceptor_h_
 #define lldb_server_Acceptor_h_
 
-#include "lldb/Core/Connection.h"
+#include "lldb/Utility/Connection.h"
 #include "lldb/Host/Socket.h"
 #include "lldb/Utility/Status.h"
 
Index: source/Utility/IOObject.cpp
===================================================================
--- source/Utility/IOObject.cpp
+++ source/Utility/IOObject.cpp
@@ -7,8 +7,9 @@
 //
 //===----------------------------------------------------------------------===//
 
-#include "lldb/Host/IOObject.h"
+#include "lldb/Utility/IOObject.h"
 
 using namespace lldb_private;
 
 const IOObject::WaitableHandle IOObject::kInvalidHandleValue = -1;
+IOObject::~IOObject() = default;
Index: source/Utility/Connection.cpp
===================================================================
--- source/Utility/Connection.cpp
+++ source/Utility/Connection.cpp
@@ -1,14 +1,14 @@
-//===-- IOObject.cpp --------------------------------------------*- C++ -*-===//
+//===-- Connection.cpp ------------------------------------------*- C++ -*-===//
 //
 //                     The LLVM Compiler Infrastructure
 //
 // This file is distributed under the University of Illinois Open Source
 // License. See LICENSE.TXT for details.
 //
 //===----------------------------------------------------------------------===//
 
-#include "lldb/Host/IOObject.h"
+#include "lldb/Utility/Connection.h"
 
 using namespace lldb_private;
 
-const IOObject::WaitableHandle IOObject::kInvalidHandleValue = -1;
+Connection::~Connection() = default;
Index: source/Utility/CMakeLists.txt
===================================================================
--- source/Utility/CMakeLists.txt
+++ source/Utility/CMakeLists.txt
@@ -1,13 +1,15 @@
 add_lldb_library(lldbUtility
   Baton.cpp
+  Connection.cpp
   ConstString.cpp
   DataBufferHeap.cpp
   DataBufferLLVM.cpp
   DataEncoder.cpp
   DataExtractor.cpp
   FastDemangle.cpp
   FileSpec.cpp
   History.cpp
+  IOObject.cpp
   JSON.cpp
   LLDBAssert.cpp
   Log.cpp
Index: source/Host/posix/ConnectionFileDescriptorPosix.cpp
===================================================================
--- source/Host/posix/ConnectionFileDescriptorPosix.cpp
+++ source/Host/posix/ConnectionFileDescriptorPosix.cpp
@@ -16,10 +16,10 @@
 
 #include "lldb/Host/posix/ConnectionFileDescriptorPosix.h"
 #include "lldb/Host/Config.h"
-#include "lldb/Host/IOObject.h"
 #include "lldb/Host/Socket.h"
 #include "lldb/Host/SocketAddress.h"
 #include "lldb/Utility/SelectHelper.h"
+#include "lldb/Utility/Timeout.h"
 
 // C Includes
 #include <errno.h>
@@ -42,7 +42,6 @@
 #include "llvm/ADT/SmallVector.h"
 #endif
 // Project includes
-#include "lldb/Core/Communication.h"
 #include "lldb/Core/Timer.h"
 #include "lldb/Host/Host.h"
 #include "lldb/Host/Socket.h"
Index: source/Host/common/Host.cpp
===================================================================
--- source/Host/common/Host.cpp
+++ source/Host/common/Host.cpp
@@ -58,6 +58,7 @@
 #include "lldb/Host/Predicate.h"
 #include "lldb/Host/ProcessLauncher.h"
 #include "lldb/Host/ThreadLauncher.h"
+#include "lldb/Host/posix/ConnectionFileDescriptorPosix.h"
 #include "lldb/Target/FileAction.h"
 #include "lldb/Target/ProcessLaunchInfo.h"
 #include "lldb/Target/UnixSignals.h"
@@ -74,6 +75,7 @@
 
 #if defined(_WIN32)
 #include "lldb/Host/windows/ProcessLauncherWindows.h"
+#include "lldb/Host/windows/ConnectionGenericFileWindows.h"
 #else
 #include "lldb/Host/posix/ProcessLauncherPosixFork.h"
 #endif
@@ -624,6 +626,14 @@
   return s_unix_signals_sp;
 }
 
+std::unique_ptr<Connection> Host::CreateDefaultConnection(llvm::StringRef url) {
+#if defined(_WIN32)
+  if (url.startswith("file://"))
+    return std::unique_ptr<Connection>(new ConnectionGenericFile());
+#endif
+  return std::unique_ptr<Connection>(new ConnectionFileDescriptor());
+}
+
 #if defined(LLVM_ON_UNIX)
 WaitStatus WaitStatus::Decode(int wstatus) {
   if (WIFEXITED(wstatus))
Index: source/Host/CMakeLists.txt
===================================================================
--- source/Host/CMakeLists.txt
+++ source/Host/CMakeLists.txt
@@ -13,7 +13,6 @@
   common/HostNativeThreadBase.cpp
   common/HostProcess.cpp
   common/HostThread.cpp
-  common/IOObject.cpp
   common/LockFileBase.cpp
   common/MainLoop.cpp
   common/MonitoringProcessLauncher.cpp
Index: source/Core/Connection.cpp
===================================================================
--- source/Core/Connection.cpp
+++ /dev/null
@@ -1,32 +0,0 @@
-//===-- Connection.cpp ------------------------------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "lldb/Core/Connection.h"
-
-#if defined(_WIN32)
-#include "lldb/Host/windows/ConnectionGenericFileWindows.h"
-#endif
-
-#include "lldb/Host/ConnectionFileDescriptor.h"
-
-#include <string.h> // for strstr
-
-using namespace lldb_private;
-
-Connection::Connection() {}
-
-Connection::~Connection() {}
-
-Connection *Connection::CreateDefaultConnection(const char *url) {
-#if defined(_WIN32)
-  if (strstr(url, "file://") == url)
-    return new ConnectionGenericFile();
-#endif
-  return new ConnectionFileDescriptor();
-}
Index: source/Core/Communication.cpp
===================================================================
--- source/Core/Communication.cpp
+++ source/Core/Communication.cpp
@@ -9,11 +9,11 @@
 
 #include "lldb/Core/Communication.h"
 
-#include "lldb/Core/Connection.h"
 #include "lldb/Core/Event.h"
 #include "lldb/Core/Listener.h"
 #include "lldb/Host/HostThread.h"
 #include "lldb/Host/ThreadLauncher.h"
+#include "lldb/Utility/Connection.h"
 #include "lldb/Utility/ConstString.h" // for ConstString
 #include "lldb/Utility/Log.h"
 #include "lldb/Utility/Logging.h" // for LogIfAnyCategoriesSet, LIBLLDB...
Index: source/Core/CMakeLists.txt
===================================================================
--- source/Core/CMakeLists.txt
+++ source/Core/CMakeLists.txt
@@ -7,7 +7,6 @@
   ArchSpec.cpp
   Broadcaster.cpp
   Communication.cpp
-  Connection.cpp
   Debugger.cpp
   Disassembler.cpp
   DumpDataExtractor.cpp
Index: source/API/SBCommunication.cpp
===================================================================
--- source/API/SBCommunication.cpp
+++ source/API/SBCommunication.cpp
@@ -11,6 +11,7 @@
 #include "lldb/API/SBBroadcaster.h"
 #include "lldb/Core/Communication.h"
 #include "lldb/Host/ConnectionFileDescriptor.h"
+#include "lldb/Host/Host.h"
 #include "lldb/Utility/Log.h"
 
 using namespace lldb;
@@ -51,7 +52,7 @@
 ConnectionStatus SBCommunication::Connect(const char *url) {
   if (m_opaque) {
     if (!m_opaque->HasConnection())
-      m_opaque->SetConnection(Connection::CreateDefaultConnection(url));
+      m_opaque->SetConnection(Host::CreateDefaultConnection(url).release());
     return m_opaque->Connect(url, NULL);
   }
   return eConnectionStatusNoConnection;
Index: include/lldb/Utility/IOObject.h
===================================================================
--- include/lldb/Utility/IOObject.h
+++ include/lldb/Utility/IOObject.h
@@ -32,7 +32,7 @@
 
   IOObject(FDType type, bool should_close)
       : m_fd_type(type), m_should_close_fd(should_close) {}
-  virtual ~IOObject() {}
+  virtual ~IOObject();
 
   virtual Status Read(void *buf, size_t &num_bytes) = 0;
   virtual Status Write(const void *buf, size_t &num_bytes) = 0;
Index: include/lldb/Utility/Connection.h
===================================================================
--- include/lldb/Utility/Connection.h
+++ include/lldb/Utility/Connection.h
@@ -31,7 +31,7 @@
 namespace lldb_private {
 
 //----------------------------------------------------------------------
-/// @class Connection Connection.h "lldb/Core/Connection.h"
+/// @class Connection Connection.h "lldb/Host/Connection.h"
 /// @brief A communication connection class.
 ///
 /// A class that implements that actual communication functions for
@@ -48,16 +48,14 @@
   //------------------------------------------------------------------
   /// Default constructor
   //------------------------------------------------------------------
-  Connection();
+  Connection() = default;
 
   //------------------------------------------------------------------
   /// Virtual destructor since this class gets subclassed and handed
   /// to a Communication object.
   //------------------------------------------------------------------
   virtual ~Connection();
 
-  static Connection *CreateDefaultConnection(const char *url);
-
   //------------------------------------------------------------------
   /// Connect using the connect string \a url.
   ///
Index: include/lldb/Host/windows/ConnectionGenericFileWindows.h
===================================================================
--- include/lldb/Host/windows/ConnectionGenericFileWindows.h
+++ include/lldb/Host/windows/ConnectionGenericFileWindows.h
@@ -10,7 +10,7 @@
 #ifndef liblldb_Host_windows_ConnectionGenericFileWindows_h_
 #define liblldb_Host_windows_ConnectionGenericFileWindows_h_
 
-#include "lldb/Core/Connection.h"
+#include "lldb/Host/Connection.h"
 #include "lldb/Host/windows/windows.h"
 #include "lldb/lldb-types.h"
 
Index: include/lldb/Host/posix/ConnectionFileDescriptorPosix.h
===================================================================
--- include/lldb/Host/posix/ConnectionFileDescriptorPosix.h
+++ include/lldb/Host/posix/ConnectionFileDescriptorPosix.h
@@ -19,10 +19,10 @@
 
 // Other libraries and framework includes
 // Project includes
-#include "lldb/Core/Connection.h"
-#include "lldb/Host/IOObject.h"
 #include "lldb/Host/Pipe.h"
 #include "lldb/Host/Predicate.h"
+#include "lldb/Utility/Connection.h"
+#include "lldb/Utility/IOObject.h"
 
 namespace lldb_private {
 
Index: include/lldb/Host/Socket.h
===================================================================
--- include/lldb/Host/Socket.h
+++ include/lldb/Host/Socket.h
@@ -15,9 +15,9 @@
 
 #include "lldb/lldb-private.h"
 
-#include "lldb/Host/IOObject.h"
 #include "lldb/Host/Predicate.h"
 #include "lldb/Host/SocketAddress.h"
+#include "lldb/Utility/IOObject.h"
 #include "lldb/Utility/Status.h"
 
 #ifdef _WIN32
Index: include/lldb/Host/MainLoopBase.h
===================================================================
--- include/lldb/Host/MainLoopBase.h
+++ include/lldb/Host/MainLoopBase.h
@@ -10,12 +10,10 @@
 #ifndef lldb_Host_posix_MainLoopBase_h_
 #define lldb_Host_posix_MainLoopBase_h_
 
-#include <functional>
-
-#include "llvm/Support/ErrorHandling.h"
-
-#include "lldb/Host/IOObject.h"
+#include "lldb/Utility/IOObject.h"
 #include "lldb/Utility/Status.h"
+#include "llvm/Support/ErrorHandling.h"
+#include <functional>
 
 namespace lldb_private {
 
Index: include/lldb/Host/Host.h
===================================================================
--- include/lldb/Host/Host.h
+++ include/lldb/Host/Host.h
@@ -237,6 +237,8 @@
                                        uint32_t line_no);
 
   static size_t GetEnvironment(StringList &env);
+
+  static std::unique_ptr<Connection> CreateDefaultConnection(llvm::StringRef url);
 };
 
 } // namespace lldb_private
Index: include/lldb/Host/File.h
===================================================================
--- include/lldb/Host/File.h
+++ include/lldb/Host/File.h
@@ -10,7 +10,7 @@
 #ifndef liblldb_File_h_
 #define liblldb_File_h_
 
-#include "lldb/Host/IOObject.h"
+#include "lldb/Utility/IOObject.h"
 #include "lldb/Host/PosixApi.h"
 #include "lldb/Utility/Status.h"
 #include "lldb/lldb-private.h"
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to