6 * Copyright (C) 2005-2013 Team XBMC
9 * This Program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
14 * This Program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with XBMC; see the file COPYING. If not, see
21 * <http://www.gnu.org/licenses/>.
28 #include <dbus/dbus.h>
33 #include "utils/log.h"
34 #include "threads/CriticalSection.h"
35 #include "utils/StringUtils.h"
36 #include "utils/URIUtils.h"
37 #include "MediaSource.h"
43 CStdString FriendlyName;
44 CHALDevice(const char *udi) { UDI = udi; }
47 class CStorageDevice : public CHALDevice
50 CStorageDevice(const char *udi) : CHALDevice(udi) { HotPlugged = false; Mounted = false; Approved = false; MountedByXBMC = false; }
56 CStdString MountPoint;
61 CStdString FileSystem;
64 { // Not the prettiest but it's better than having to reproduce it elsewere in the code...
65 CStdString rtn, tmp1, tmp2, tmp3, tmp4;
67 tmp1 = StringUtils::Format("UUID %s | ", UUID.c_str());
68 if (FileSystem.size() > 0)
69 tmp2 = StringUtils::Format("FileSystem %s | ", FileSystem.c_str());
70 if (MountPoint.size() > 0)
71 tmp3 = StringUtils::Format("Mounted on %s | ", MountPoint.c_str());
73 tmp4 = StringUtils::Format("HotPlugged YES | ");
75 tmp4 = StringUtils::Format("HotPlugged NO | ");
78 rtn = StringUtils::Format("%s%s%s%sType %i |Approved YES ", tmp1.c_str(), tmp2.c_str(), tmp3.c_str(), tmp4.c_str(), Type);
80 rtn = StringUtils::Format("%s%s%s%sType %i |Approved NO ", tmp1.c_str(), tmp2.c_str(), tmp3.c_str(), tmp4.c_str(), Type);
84 void toMediaSource(CMediaSource *share)
86 share->strPath = MountPoint;
88 share->strName = Label;
91 share->strName = MountPoint;
92 URIUtils::RemoveSlashAtEnd(share->strName);
93 share->strName = URIUtils::GetFileName(share->strName);
96 share->m_ignore = true;
98 share->m_iDriveType = CMediaSource::SOURCE_TYPE_REMOVABLE;
99 else if(strcmp(FileSystem.c_str(), "iso9660") == 0 || strcmp(FileSystem.c_str(), "udf") == 0)
100 share->m_iDriveType = CMediaSource::SOURCE_TYPE_DVD;
102 share->m_iDriveType = CMediaSource::SOURCE_TYPE_LOCAL;
111 static const char *StorageTypeToString(int DeviceType);
112 static int StorageTypeFromString(const char *DeviceString);
118 std::vector<CStorageDevice> GetVolumeDevices();
119 bool Eject(CStdString path);
121 DBusConnection *m_DBusSystemConnection;
122 LibHalContext *m_Context;
123 static DBusError m_Error;
124 static bool NewMessage;
127 void UpdateDevice(const char *udi);
128 void AddDevice(const char *udi);
129 bool RemoveDevice(const char *udi);
132 bool m_Notifications;
133 LibHalContext *InitializeHal();
134 bool InitializeDBus();
137 bool UnMount(CStorageDevice volume);
138 bool Mount(CStorageDevice *volume, CStdString mountpath);
139 void HandleNewVolume(CStorageDevice *dev);
140 static bool ApproveDevice(CStorageDevice *device);
142 static bool DeviceFromVolumeUdi(const char *udi, CStorageDevice *device);
143 static CCriticalSection m_lock;
145 #if defined(HAS_SDL_JOYSTICK)
146 bool m_bMultipleJoysticksSupport;
150 static void DeviceRemoved(LibHalContext *ctx, const char *udi);
151 static void DeviceNewCapability(LibHalContext *ctx, const char *udi, const char *capability);
152 static void DeviceLostCapability(LibHalContext *ctx, const char *udi, const char *capability);
153 static void DevicePropertyModified(LibHalContext *ctx, const char *udi, const char *key, dbus_bool_t is_removed, dbus_bool_t is_added);
154 static void DeviceCondition(LibHalContext *ctx, const char *udi, const char *condition_name, const char *condition_details);
155 static void DeviceAdded(LibHalContext *ctx, const char *udi);
158 std::vector<CStorageDevice> m_Volumes;
159 #if defined(HAS_SDL_JOYSTICK)
160 std::vector<CHALDevice> m_Joysticks;
164 extern CHALManager g_HalManager;