PageRenderTime 62ms CodeModel.GetById 29ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/azureus-4.7.0.2/org/gudy/azureus2/platform/unix/PlatformManagerImpl.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 336 lines | 214 code | 64 blank | 58 comment | 6 complexity | 71985c02479fafa3e4a4c9671c60ad38 MD5 | raw file
  1. /**
  2. * Copyright (C) 2006 Aelitis, All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation; either version 2
  7. * of the License, or (at your option) any later version.
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. * You should have received a copy of the GNU General Public License
  13. * along with this program; if not, write to the Free Software
  14. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  15. *
  16. * AELITIS, SAS au capital de 63.529,40 euros
  17. * 8 Allee Lenotre, La Grille Royale, 78600 Le Mesnil le Roi, France.
  18. *
  19. */
  20. package org.gudy.azureus2.platform.unix;
  21. import java.io.File;
  22. import java.net.InetAddress;
  23. import java.util.HashSet;
  24. import org.gudy.azureus2.core3.logging.LogEvent;
  25. import org.gudy.azureus2.core3.logging.LogIDs;
  26. import org.gudy.azureus2.core3.logging.Logger;
  27. import org.gudy.azureus2.core3.util.AEMonitor;
  28. import org.gudy.azureus2.core3.util.SystemProperties;
  29. import org.gudy.azureus2.platform.*;
  30. import org.gudy.azureus2.plugins.platform.PlatformManagerException;
  31. import com.aelitis.azureus.core.AzureusCore;
  32. /**
  33. * @author TuxPaper
  34. * @created Dec 18, 2006
  35. *
  36. */
  37. public class PlatformManagerImpl implements PlatformManager
  38. {
  39. private static final LogIDs LOGID = LogIDs.CORE;
  40. private static final String ERR_UNSUPPORTED = "Unsupported capability called on platform manager";
  41. protected static PlatformManagerImpl singleton;
  42. protected static AEMonitor class_mon = new AEMonitor("PlatformManager");
  43. private final HashSet capabilitySet = new HashSet();
  44. private static final Object migrate_lock = new Object();
  45. /**
  46. * Gets the platform manager singleton, which was already initialized
  47. */
  48. public static PlatformManagerImpl getSingleton() {
  49. return singleton;
  50. }
  51. static {
  52. initializeSingleton();
  53. }
  54. /**
  55. * Instantiates the singleton
  56. */
  57. private static void initializeSingleton() {
  58. try {
  59. class_mon.enter();
  60. singleton = new PlatformManagerImpl();
  61. } catch (Throwable e) {
  62. Logger.log(new LogEvent(LOGID, "Failed to initialize platform manager"
  63. + " for Unix Compatable OS", e));
  64. } finally {
  65. class_mon.exit();
  66. }
  67. }
  68. /**
  69. * Creates a new PlatformManager and initializes its capabilities
  70. */
  71. public PlatformManagerImpl() {
  72. capabilitySet.add(PlatformManagerCapabilities.GetUserDataDirectory);
  73. }
  74. // @see org.gudy.azureus2.platform.PlatformManager#copyFilePermissions(java.lang.String, java.lang.String)
  75. public void copyFilePermissions(String from_file_name, String to_file_name)
  76. throws PlatformManagerException {
  77. throw new PlatformManagerException(ERR_UNSUPPORTED);
  78. }
  79. // @see org.gudy.azureus2.platform.PlatformManager#createProcess(java.lang.String, boolean)
  80. public void createProcess(String command_line, boolean inherit_handles)
  81. throws PlatformManagerException {
  82. throw new PlatformManagerException(ERR_UNSUPPORTED);
  83. }
  84. // @see org.gudy.azureus2.platform.PlatformManager#dispose()
  85. public void dispose() {
  86. }
  87. // @see org.gudy.azureus2.platform.PlatformManager#getApplicationCommandLine()
  88. public String getApplicationCommandLine() throws PlatformManagerException {
  89. throw new PlatformManagerException(ERR_UNSUPPORTED);
  90. }
  91. // @see org.gudy.azureus2.platform.PlatformManager#getPlatformType()
  92. public int getPlatformType() {
  93. return PT_UNIX;
  94. }
  95. // @see org.gudy.azureus2.platform.PlatformManager#getUserDataDirectory()
  96. public String getUserDataDirectory()
  97. throws PlatformManagerException
  98. {
  99. String userhome = System.getProperty("user.home");
  100. String temp_user_path = userhome + SystemProperties.SEP + "."
  101. + SystemProperties.APPLICATION_NAME.toLowerCase()
  102. + SystemProperties.SEP;
  103. synchronized (migrate_lock) {
  104. File home = new File(temp_user_path);
  105. if (!home.exists()) { //might be a fresh install or might be an old non-migrated install
  106. String old_home_path = userhome + SystemProperties.SEP + "."
  107. + SystemProperties.APPLICATION_NAME + SystemProperties.SEP;
  108. File old_home = new File(old_home_path);
  109. if (old_home.exists()) { //migrate
  110. String msg = "Migrating unix user config dir [" + old_home_path
  111. + "] ===> [" + temp_user_path + "]";
  112. System.out.println(msg);
  113. Logger.log(new LogEvent(LOGID,
  114. "SystemProperties::getUserPath(Unix): " + msg));
  115. try {
  116. old_home.renameTo(home);
  117. } catch (Throwable t) {
  118. t.printStackTrace();
  119. Logger.log(new LogEvent(LOGID, "migration rename failed:", t));
  120. }
  121. }
  122. }
  123. }
  124. return temp_user_path;
  125. }
  126. public String
  127. getComputerName()
  128. {
  129. String host = System.getenv( "HOST" );
  130. if ( host != null && host.length() > 0 ){
  131. return( host );
  132. }
  133. return( null );
  134. }
  135. // @see org.gudy.azureus2.platform.PlatformManager#getVersion()
  136. public String getVersion() throws PlatformManagerException {
  137. throw new PlatformManagerException(ERR_UNSUPPORTED);
  138. }
  139. // @see org.gudy.azureus2.platform.PlatformManager#hasCapability(org.gudy.azureus2.platform.PlatformManagerCapabilities)
  140. public boolean hasCapability(PlatformManagerCapabilities capability) {
  141. return capabilitySet.contains(capability);
  142. }
  143. // @see org.gudy.azureus2.platform.PlatformManager#isApplicationRegistered()
  144. public boolean isApplicationRegistered() throws PlatformManagerException {
  145. throw new PlatformManagerException(ERR_UNSUPPORTED);
  146. }
  147. // @see org.gudy.azureus2.platform.PlatformManager#performRecoverableFileDelete(java.lang.String)
  148. public void performRecoverableFileDelete(String file_name)
  149. throws PlatformManagerException {
  150. throw new PlatformManagerException(ERR_UNSUPPORTED);
  151. }
  152. // @see org.gudy.azureus2.platform.PlatformManager#ping(java.net.InetAddress, java.net.InetAddress, org.gudy.azureus2.platform.PlatformManagerPingCallback)
  153. public void ping(InetAddress interface_address, InetAddress target,
  154. PlatformManagerPingCallback callback) throws PlatformManagerException {
  155. throw new PlatformManagerException(ERR_UNSUPPORTED);
  156. }
  157. // @see org.gudy.azureus2.platform.PlatformManager#registerApplication()
  158. public void registerApplication() throws PlatformManagerException {
  159. throw new PlatformManagerException(ERR_UNSUPPORTED);
  160. }
  161. // @see org.gudy.azureus2.platform.PlatformManager#addListener(org.gudy.azureus2.platform.PlatformManagerListener)
  162. public void addListener(PlatformManagerListener listener) {
  163. // No Listener Functionality
  164. }
  165. // @see org.gudy.azureus2.platform.PlatformManager#removeListener(org.gudy.azureus2.platform.PlatformManagerListener)
  166. public void removeListener(PlatformManagerListener listener) {
  167. // No Listener Functionality
  168. }
  169. public File
  170. getVMOptionFile()
  171. throws PlatformManagerException
  172. {
  173. throw new PlatformManagerException(ERR_UNSUPPORTED);
  174. }
  175. public String[]
  176. getExplicitVMOptions()
  177. throws PlatformManagerException
  178. {
  179. throw new PlatformManagerException(ERR_UNSUPPORTED);
  180. }
  181. public void
  182. setExplicitVMOptions(
  183. String[] options )
  184. throws PlatformManagerException
  185. {
  186. throw new PlatformManagerException(ERR_UNSUPPORTED);
  187. }
  188. public boolean
  189. getRunAtLogin()
  190. throws PlatformManagerException
  191. {
  192. throw new PlatformManagerException(ERR_UNSUPPORTED);
  193. }
  194. public void
  195. setRunAtLogin(
  196. boolean run )
  197. throws PlatformManagerException
  198. {
  199. throw new PlatformManagerException(ERR_UNSUPPORTED);
  200. }
  201. public void
  202. startup(
  203. AzureusCore azureus_core )
  204. throws PlatformManagerException
  205. {
  206. }
  207. public int
  208. getShutdownTypes()
  209. {
  210. return( 0 );
  211. }
  212. public void
  213. shutdown(
  214. int type )
  215. throws PlatformManagerException
  216. {
  217. throw new PlatformManagerException("Unsupported capability called on platform manager");
  218. }
  219. // @see org.gudy.azureus2.platform.PlatformManager#setTCPTOSEnabled(boolean)
  220. public void setTCPTOSEnabled(boolean enabled) throws PlatformManagerException {
  221. throw new PlatformManagerException(ERR_UNSUPPORTED);
  222. }
  223. // @see org.gudy.azureus2.platform.PlatformManager#testNativeAvailability(java.lang.String)
  224. public boolean testNativeAvailability(String name)
  225. throws PlatformManagerException {
  226. throw new PlatformManagerException(ERR_UNSUPPORTED);
  227. }
  228. // @see org.gudy.azureus2.platform.PlatformManager#traceRoute(java.net.InetAddress, java.net.InetAddress, org.gudy.azureus2.platform.PlatformManagerPingCallback)
  229. public void traceRoute(InetAddress interface_address, InetAddress target,
  230. PlatformManagerPingCallback callback) throws PlatformManagerException {
  231. throw new PlatformManagerException(ERR_UNSUPPORTED);
  232. }
  233. // @see org.gudy.azureus2.plugins.platform.PlatformManager#getLocation(long)
  234. public File getLocation(long location_id) throws PlatformManagerException {
  235. switch ((int)location_id) {
  236. case LOC_USER_DATA:
  237. return( new File( getUserDataDirectory() ));
  238. case LOC_DOCUMENTS:
  239. return new File(System.getProperty("user.home"));
  240. case LOC_MUSIC:
  241. case LOC_VIDEO:
  242. default:
  243. return( null );
  244. }
  245. }
  246. // @see org.gudy.azureus2.plugins.platform.PlatformManager#isAdditionalFileTypeRegistered(java.lang.String, java.lang.String)
  247. public boolean isAdditionalFileTypeRegistered(String name, String type)
  248. throws PlatformManagerException {
  249. throw new PlatformManagerException(ERR_UNSUPPORTED);
  250. }
  251. // @see org.gudy.azureus2.plugins.platform.PlatformManager#registerAdditionalFileType(java.lang.String, java.lang.String, java.lang.String, java.lang.String)
  252. public void registerAdditionalFileType(String name, String description,
  253. String type, String content_type) throws PlatformManagerException {
  254. throw new PlatformManagerException(ERR_UNSUPPORTED);
  255. }
  256. // @see org.gudy.azureus2.plugins.platform.PlatformManager#showFile(java.lang.String)
  257. public void showFile(String file_name) throws PlatformManagerException {
  258. throw new PlatformManagerException(ERR_UNSUPPORTED);
  259. }
  260. // @see org.gudy.azureus2.plugins.platform.PlatformManager#unregisterAdditionalFileType(java.lang.String, java.lang.String)
  261. public void unregisterAdditionalFileType(String name, String type)
  262. throws PlatformManagerException {
  263. throw new PlatformManagerException(ERR_UNSUPPORTED);
  264. }
  265. // @see org.gudy.azureus2.platform.PlatformManager#getAzComputerID()
  266. public String getAzComputerID() throws PlatformManagerException {
  267. throw new PlatformManagerException(ERR_UNSUPPORTED);
  268. }
  269. public void requestUserAttention(int type, Object data) throws PlatformManagerException {
  270. throw new PlatformManagerException("Unsupported capability called on platform manager");
  271. }
  272. }