Changeset 28349 in vbox for trunk/src/VBox/Main
- Timestamp:
- Apr 15, 2010 9:18:31 AM (15 years ago)
- svn:sync-xref-src-repo-rev:
- 60109
- Location:
- trunk/src/VBox/Main
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/HostHardwareLinux.h
r25728 r28349 44 44 /** The device node of the drive. */ 45 45 iprt::MiniString mDevice; 46 /** The hal unique device identifier, if available. */ 46 /** A unique identifier for the device, if available. This should be 47 * kept consistant accross different probing methods of a given 48 * platform if at all possible. */ 47 49 iprt::MiniString mUdi; 48 50 /** A textual description of the drive. */ … … 124 126 /** The device node of the device. */ 125 127 iprt::MiniString mDevice; 126 /** The sysfs path of the device. */ 128 /** The system identifier of the device. Specific to the probing 129 * method. */ 127 130 iprt::MiniString mSysfsPath; 128 131 /** Type for the list of interfaces. */ 129 132 typedef std::vector<iprt::MiniString> InterfaceList; 130 /** The sys fs paths of the device's interfaces. */133 /** The system IDs of the device's interfaces. */ 131 134 InterfaceList mInterfaces; 132 135 133 136 /** Constructors */ 134 137 USBDeviceInfo(const iprt::MiniString &aDevice, 135 const iprt::MiniString &aSys fsPath)138 const iprt::MiniString &aSystemID) 136 139 : mDevice(aDevice), 137 mSysfsPath(aSys fsPath)140 mSysfsPath(aSystemID) 138 141 { } 139 142 }; … … 172 175 /** Convenience typedef. */ 173 176 typedef VBoxMainUSBDeviceInfo::USBDeviceInfo::InterfaceList USBInterfaceList; 177 178 /** Implementation of the hotplug waiter class below */ 179 class VBoxMainHotplugWaiterImpl 180 { 181 public: 182 VBoxMainHotplugWaiterImpl (void) {} 183 virtual ~VBoxMainHotplugWaiterImpl (void) {} 184 /** @copydoc VBoxMainHotplugWaiter::Wait */ 185 virtual int Wait (RTMSINTERVAL cMillies) = 0; 186 /** @copydoc VBoxMainHotplugWaiter::Interrupt */ 187 virtual void Interrupt (void) = 0; 188 }; 174 189 175 190 /** … … 181 196 class VBoxMainHotplugWaiter 182 197 { 183 /** Opaque context struct. */ 184 struct Context; 185 186 /** Opaque waiter context. */ 187 Context *mContext; 188 public: 189 /** Constructor */ 198 /** Class implementation. */ 199 VBoxMainHotplugWaiterImpl *mImpl; 200 public: 201 /** Constructor. Responsible for selecting the implementation. */ 190 202 VBoxMainHotplugWaiter (void); 191 203 /** Destructor. */ 192 ~VBoxMainHotplugWaiter (void); 204 ~VBoxMainHotplugWaiter (void) 205 { 206 delete mImpl; 207 } 193 208 /** 194 209 * Wait for a hotplug event. … … 202 217 * @param cMillies How long to wait for at most. 203 218 */ 204 int Wait (RTMSINTERVAL cMillies); 219 int Wait (RTMSINTERVAL cMillies) 220 { 221 return mImpl->Wait(cMillies); 222 } 205 223 /** 206 224 * Interrupts an active wait. In the current implementation, the wait 207 225 * may not return until up to two seconds after calling this method. 208 226 */ 209 void Interrupt (void); 227 void Interrupt (void) 228 { 229 mImpl->Interrupt(); 230 } 210 231 }; 211 232 -
trunk/src/VBox/Main/linux/HostHardwareLinux.cpp
r28315 r28349 1053 1053 } 1054 1054 1055 struct VBoxMainHotplugWaiter::Context1056 {1057 1055 #if defined RT_OS_LINUX && defined VBOX_WITH_DBUS 1056 class hotplugDBusImpl : public VBoxMainHotplugWaiterImpl 1057 { 1058 1058 /** The connection to DBus */ 1059 1059 RTMemAutoPtr <DBusConnection, VBoxHalShutdownPrivate> mConnection; … … 1063 1063 /** A flag to say that we wish to interrupt the current wait. */ 1064 1064 volatile bool mInterrupt; 1065 1066 public: 1067 /** Test whether this implementation can be used on the current system */ 1068 static bool HalAvailable(void) 1069 { 1070 RTMemAutoPtr<DBusConnection, VBoxHalShutdown> dbusConnection; 1071 1072 /* Try to open a test connection to hal */ 1073 if (RT_SUCCESS(RTDBusLoadLib()) && RT_SUCCESS(halInit (&dbusConnection))) 1074 return !!dbusConnection; 1075 return false; 1076 } 1077 1065 1078 /** Constructor */ 1066 Context() : mTriggered(false), mInterrupt(false) {} 1067 #endif /* defined RT_OS_LINUX && defined VBOX_WITH_DBUS */ 1079 hotplugDBusImpl (void); 1080 virtual ~hotplugDBusImpl (void); 1081 /** @copydoc VBoxMainHotplugWaiter::Wait */ 1082 virtual int Wait (RTMSINTERVAL cMillies); 1083 /** @copydoc VBoxMainHotplugWaiter::Interrupt */ 1084 virtual void Interrupt (void); 1068 1085 }; 1069 1086 … … 1072 1089 * the Context structure when a device (not necessarily USB) is added or 1073 1090 * removed. */ 1074 VBoxMainHotplugWaiter::VBoxMainHotplugWaiter () 1075 { 1076 #if defined RT_OS_LINUX && defined VBOX_WITH_DBUS 1091 hotplugDBusImpl::hotplugDBusImpl (void) : mTriggered(false), mInterrupt(false) 1092 { 1077 1093 int rc = VINF_SUCCESS; 1078 1094 1079 mContext = new Context;1080 1095 if (RT_SUCCESS(RTDBusLoadLib())) 1081 1096 { 1082 for (unsigned i = 0; RT_SUCCESS(rc) && i < 5 && !mCon text->mConnection; ++i)1083 { 1084 rc = halInitPrivate (&mCon text->mConnection);1085 } 1086 if (!mCon text->mConnection)1097 for (unsigned i = 0; RT_SUCCESS(rc) && i < 5 && !mConnection; ++i) 1098 { 1099 rc = halInitPrivate (&mConnection); 1100 } 1101 if (!mConnection) 1087 1102 rc = VERR_NOT_SUPPORTED; 1088 1103 DBusMessage *pMessage; 1089 1104 while ( RT_SUCCESS(rc) 1090 && (pMessage = dbus_connection_pop_message (mCon text->mConnection.get())) != NULL)1105 && (pMessage = dbus_connection_pop_message (mConnection.get())) != NULL) 1091 1106 dbus_message_unref (pMessage); /* empty the message queue. */ 1092 1107 if ( RT_SUCCESS(rc) 1093 && !dbus_connection_add_filter (mCon text->mConnection.get(),1108 && !dbus_connection_add_filter (mConnection.get(), 1094 1109 dbusFilterFunction, 1095 (void *) &m Context->mTriggered, NULL))1110 (void *) &mTriggered, NULL)) 1096 1111 rc = VERR_NO_MEMORY; 1097 1112 if (RT_FAILURE(rc)) 1098 mContext->mConnection.reset(); 1099 } 1100 #endif /* defined RT_OS_LINUX && defined VBOX_WITH_DBUS */ 1113 mConnection.reset(); 1114 } 1101 1115 } 1102 1116 1103 1117 /* Destructor */ 1104 VBoxMainHotplugWaiter::~VBoxMainHotplugWaiter () 1105 { 1106 #if defined RT_OS_LINUX && defined VBOX_WITH_DBUS 1107 if (!!mContext->mConnection) 1108 dbus_connection_remove_filter (mContext->mConnection.get(), dbusFilterFunction, 1109 (void *) &mContext->mTriggered); 1110 delete mContext; 1111 #endif /* defined RT_OS_LINUX && defined VBOX_WITH_DBUS */ 1118 hotplugDBusImpl::~hotplugDBusImpl () 1119 { 1120 if (!!mConnection) 1121 dbus_connection_remove_filter (mConnection.get(), dbusFilterFunction, 1122 (void *) &mTriggered); 1112 1123 } 1113 1124 … … 1115 1126 * connection. Because the connection is private we don't have to worry about 1116 1127 * blocking other users. */ 1117 int VBoxMainHotplugWaiter::Wait(RTMSINTERVAL cMillies)1128 int hotplugDBusImpl::Wait(RTMSINTERVAL cMillies) 1118 1129 { 1119 1130 int rc = VINF_SUCCESS; 1120 #if defined RT_OS_LINUX && defined VBOX_WITH_DBUS 1121 if (!mContext->mConnection) 1131 if (!mConnection) 1122 1132 rc = VERR_NOT_SUPPORTED; 1123 1133 bool connected = true; 1124 m Context->mTriggered = false;1125 m Context->mInterrupt = false;1134 mTriggered = false; 1135 mInterrupt = false; 1126 1136 unsigned cRealMillies; 1127 1137 if (cMillies != RT_INDEFINITE_WAIT) … … 1129 1139 else 1130 1140 cRealMillies = DBUS_POLL_TIMEOUT; 1131 while ( RT_SUCCESS(rc) && connected && !m Context->mTriggered1132 && !m Context->mInterrupt)1133 { 1134 connected = dbus_connection_read_write_dispatch (mCon text->mConnection.get(),1141 while ( RT_SUCCESS(rc) && connected && !mTriggered 1142 && !mInterrupt) 1143 { 1144 connected = dbus_connection_read_write_dispatch (mConnection.get(), 1135 1145 cRealMillies); 1136 if (m Context->mInterrupt)1146 if (mInterrupt) 1137 1147 LogFlowFunc(("wait loop interrupted\n")); 1138 1148 if (cMillies != RT_INDEFINITE_WAIT) 1139 m Context->mInterrupt = true;1149 mInterrupt = true; 1140 1150 } 1141 1151 if (!connected) 1142 1152 rc = VERR_TRY_AGAIN; 1143 #else /* !(defined RT_OS_LINUX && defined VBOX_WITH_DBUS) */ 1144 rc = VERR_NOT_IMPLEMENTED; 1153 return rc; 1154 } 1155 1156 /* Set a flag to tell the Wait not to resume next time it times out. */ 1157 void hotplugDBusImpl::Interrupt() 1158 { 1159 LogFlowFunc(("\n")); 1160 mInterrupt = true; 1161 } 1145 1162 #endif /* !(defined RT_OS_LINUX && defined VBOX_WITH_DBUS) */ 1146 return rc; 1147 } 1148 1149 /* Set a flag to tell the Wait not to resume next time it times out. */ 1150 void VBoxMainHotplugWaiter::Interrupt() 1163 1164 class hotplugNullImpl : public VBoxMainHotplugWaiterImpl 1165 { 1166 public: 1167 hotplugNullImpl (void) {} 1168 virtual ~hotplugNullImpl (void) {} 1169 /** @copydoc VBoxMainHotplugWaiter::Wait */ 1170 virtual int Wait (RTMSINTERVAL) 1171 { 1172 return VERR_NOT_SUPPORTED; 1173 } 1174 /** @copydoc VBoxMainHotplugWaiter::Interrupt */ 1175 virtual void Interrupt (void) {} 1176 }; 1177 1178 VBoxMainHotplugWaiter::VBoxMainHotplugWaiter(void) 1151 1179 { 1152 1180 #if defined RT_OS_LINUX && defined VBOX_WITH_DBUS 1153 LogFlowFunc(("\n")); 1154 mContext->mInterrupt = true; 1155 #endif /* defined RT_OS_LINUX && defined VBOX_WITH_DBUS */ 1156 } 1157 1181 if (hotplugDBusImpl::HalAvailable()) 1182 { 1183 mImpl = new hotplugDBusImpl; 1184 return; 1185 } 1186 #endif /* !(defined RT_OS_LINUX && defined VBOX_WITH_DBUS) */ 1187 mImpl = new hotplugNullImpl; 1188 } 1158 1189 1159 1190 class sysfsPathHandler
Note:
See TracChangeset
for help on using the changeset viewer.