org.gudy.azureus2.platform.macosx
Class PlatformManagerImpl

java.lang.Object
  extended by org.gudy.azureus2.platform.macosx.PlatformManagerImpl
All Implemented Interfaces:
AEDiagnosticsEvidenceGenerator, PlatformManager

public class PlatformManagerImpl
extends java.lang.Object
implements PlatformManager, AEDiagnosticsEvidenceGenerator

Performs platform-specific operations with Mac OS X

Version:
1.0 Initial Version
Author:
James Yeh
See Also:
PlatformManager

Field Summary
protected static AEMonitor class_mon
           
protected static PlatformManagerImpl singleton
           
 
Fields inherited from interface org.gudy.azureus2.platform.PlatformManager
PT_MACOSX, PT_OTHER, PT_UNIX, PT_WINDOWS, SD_ALL, SD_HIBERNATE, SD_SHUTDOWN, SD_SLEEP, USER_REQUEST_INFO, USER_REQUEST_QUESTION, USER_REQUEST_WARNING
 
Fields inherited from interface org.gudy.azureus2.plugins.platform.PlatformManager
LOC_DOCUMENTS, LOC_MUSIC, LOC_USER_DATA, LOC_VIDEO
 
Constructor Summary
PlatformManagerImpl()
          Creates a new PlatformManager and initializes its capabilities
 
Method Summary
 void addListener(PlatformManagerListener listener)
           
protected  boolean checkPList()
           
protected static boolean compileOSAScript(java.lang.CharSequence[] cmds, java.io.File destination)
          Compiles a new AppleScript instance to the specified location
protected static boolean compileOSAScript(java.lang.CharSequence cmd, java.io.File destination)
          Compiles a new AppleScript instance to the specified location
 void copyFilePermissions(java.lang.String from_file_name, java.lang.String to_file_name)
           
 void createProcess(java.lang.String cmd, boolean inheritsHandles)
          
 void dispose()
          Disposes system resources.
 void generate(IndentWriter writer)
           
 java.lang.String getApplicationCommandLine()
          command to launch Vuze
 java.lang.String getAzComputerID()
           
 java.lang.String getComputerName()
           
 java.lang.String[] getExplicitVMOptions()
           
 java.io.File getLocation(long location_id)
          Get a well-known location, if defined for the platform
 int getMaxOpenFiles()
          This max-open-files concept here is from linux/osx where network connections are treated as 'files'
 int getPlatformType()
          
protected  PListEditor getPList()
           
 boolean getPreventComputerSleep()
           
 boolean getRunAtLogin()
           
 int getShutdownTypes()
           
static PlatformManagerImpl getSingleton()
          Gets the platform manager singleton, which was already initialized
 java.lang.String getUserDataDirectory()
          
 java.lang.String getVersion()
          
 java.io.File getVMOptionFile()
           
 boolean hasCapability(PlatformManagerCapabilities capability)
          Gets whether the platform manager supports a capability
 boolean isAdditionalFileTypeRegistered(java.lang.String name, java.lang.String type)
          Checks to see if the supplied file type is registered with this application
 boolean isApplicationRegistered()
           
 java.lang.Class<?> loadClass(java.lang.ClassLoader loader, java.lang.String class_name)
          Gives a particular platform the ability to alter the class-loading method
static void main(java.lang.String[] args)
           
protected static java.lang.String performOSAScript(java.lang.CharSequence cmd)
          Compiles a new AppleScript instance and runs it
protected static java.lang.String performOSAScript(java.lang.CharSequence[] cmds)
          Compiles a new AppleScript instance and runs it
protected static java.lang.String performOSAScript(java.io.File script)
          Compiles a new AppleScript instance and runs it
 void performRecoverableFileDelete(java.lang.String path)
          
protected static java.lang.Process performRuntimeExec(java.lang.String[] cmdargs)
           
 void ping(java.net.InetAddress interface_address, java.net.InetAddress target, PlatformManagerPingCallback callback)
           
 void playSystemAlert()
          Plays the system alert (the jingle is specified by the user in System Preferences)
 void registerAdditionalFileType(java.lang.String name, java.lang.String description, java.lang.String type, java.lang.String content_type)
          Registers a file type with this application
 void registerApplication()
           
 void removeListener(PlatformManagerListener listener)
           
 void requestUserAttention(int type, java.lang.Object data)
          If the application is not active causes the application icon at the bottom to bounce until the application becomes active If the application is already active then this method does nothing.
 void setExplicitVMOptions(java.lang.String[] options)
           
 void setPreventComputerSleep(boolean prevent_it)
           
 void setRunAtLogin(boolean run)
           
 void setTCPTOSEnabled(boolean enabled)
          enable or disable the platforms support for TCP TOS
 void showFile(java.lang.String path)
          Reveals the file or directory with the platform's default browser
 void showInFinder(java.io.File path)
          Shows the given file or directory in Finder
 void showInTerminal(java.io.File path)
          Shows the given file or directory in Terminal by executing cd /absolute/path/to
 void showInTerminal(java.lang.String path)
          Shows the given file or directory in Terminal by executing cd /absolute/path/to
 void shutdown(int type)
           
 void startup(AzureusCore _azureus_core)
           
 boolean testNativeAvailability(java.lang.String name)
           
protected  void touchPList()
           
 void traceRoute(java.net.InetAddress interface_address, java.net.InetAddress target, PlatformManagerPingCallback callback)
           
 void unregisterAdditionalFileType(java.lang.String name, java.lang.String type)
          Removes a file-type registration
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

singleton

protected static PlatformManagerImpl singleton

class_mon

protected static AEMonitor class_mon
Constructor Detail

PlatformManagerImpl

public PlatformManagerImpl()
Creates a new PlatformManager and initializes its capabilities

Method Detail

getSingleton

public static PlatformManagerImpl getSingleton()
Gets the platform manager singleton, which was already initialized


getPlatformType

public int getPlatformType()


getVersion

public java.lang.String getVersion()
                            throws PlatformManagerException

Throws:
PlatformManagerException

getPList

protected PListEditor getPList()
                        throws java.io.IOException
Throws:
java.io.IOException

checkPList

protected boolean checkPList()

touchPList

protected void touchPList()

getVMOptionFile

public java.io.File getVMOptionFile()
                             throws PlatformManagerException
Throws:
PlatformManagerException

getExplicitVMOptions

public java.lang.String[] getExplicitVMOptions()
                                        throws PlatformManagerException
Throws:
PlatformManagerException

setExplicitVMOptions

public void setExplicitVMOptions(java.lang.String[] options)
                          throws PlatformManagerException
Throws:
PlatformManagerException

startup

public void startup(AzureusCore _azureus_core)
             throws PlatformManagerException
Throws:
PlatformManagerException

getShutdownTypes

public int getShutdownTypes()

shutdown

public void shutdown(int type)
              throws PlatformManagerException
Throws:
PlatformManagerException

setPreventComputerSleep

public void setPreventComputerSleep(boolean prevent_it)
                             throws PlatformManagerException
Throws:
PlatformManagerException

getPreventComputerSleep

public boolean getPreventComputerSleep()

getRunAtLogin

public boolean getRunAtLogin()
                      throws PlatformManagerException
Throws:
PlatformManagerException

setRunAtLogin

public void setRunAtLogin(boolean run)
                   throws PlatformManagerException
Throws:
PlatformManagerException

getUserDataDirectory

public java.lang.String getUserDataDirectory()
                                      throws PlatformManagerException

Throws:
PlatformManagerException
See Also:
SystemProperties.getUserPath()

getComputerName

public java.lang.String getComputerName()
Specified by:
getComputerName in interface PlatformManager
Returns:
null if can't be found

getLocation

public java.io.File getLocation(long location_id)
                         throws PlatformManagerException
Description copied from interface: PlatformManager
Get a well-known location, if defined for the platform

Specified by:
getLocation in interface PlatformManager
Parameters:
location_id - from above LOC_constants
Returns:
Throws:
PlatformManagerException

isApplicationRegistered

public boolean isApplicationRegistered()
                                throws PlatformManagerException
Throws:
PlatformManagerException

getApplicationCommandLine

public java.lang.String getApplicationCommandLine()
                                           throws PlatformManagerException
command to launch Vuze

Throws:
PlatformManagerException

isAdditionalFileTypeRegistered

public boolean isAdditionalFileTypeRegistered(java.lang.String name,
                                              java.lang.String type)
                                       throws PlatformManagerException
Description copied from interface: PlatformManager
Checks to see if the supplied file type is registered with this application

Specified by:
isAdditionalFileTypeRegistered in interface PlatformManager
Returns:
Throws:
PlatformManagerException

unregisterAdditionalFileType

public void unregisterAdditionalFileType(java.lang.String name,
                                         java.lang.String type)
                                  throws PlatformManagerException
Description copied from interface: PlatformManager
Removes a file-type registration

Specified by:
unregisterAdditionalFileType in interface PlatformManager
Throws:
PlatformManagerException

registerAdditionalFileType

public void registerAdditionalFileType(java.lang.String name,
                                       java.lang.String description,
                                       java.lang.String type,
                                       java.lang.String content_type)
                                throws PlatformManagerException
Description copied from interface: PlatformManager
Registers a file type with this application

Specified by:
registerAdditionalFileType in interface PlatformManager
Throws:
PlatformManagerException

registerApplication

public void registerApplication()
                         throws PlatformManagerException
Throws:
PlatformManagerException

createProcess

public void createProcess(java.lang.String cmd,
                          boolean inheritsHandles)
                   throws PlatformManagerException

Throws:
PlatformManagerException

performRecoverableFileDelete

public void performRecoverableFileDelete(java.lang.String path)
                                  throws PlatformManagerException

Throws:
PlatformManagerException

hasCapability

public boolean hasCapability(PlatformManagerCapabilities capability)

Gets whether the platform manager supports a capability

Users of PlatformManager should check for supported capabilities before calling the corresponding methods

Note that support for a particular capability may change arbitrarily in the duration of the application session, but the manager will cache where necessary.

Parameters:
capability - A platform manager capability
Returns:
True if the manager supports the capability

dispose

public void dispose()
Disposes system resources. This method is optional.


setTCPTOSEnabled

public void setTCPTOSEnabled(boolean enabled)
                      throws PlatformManagerException
enable or disable the platforms support for TCP TOS

Throws:
PlatformManagerException

copyFilePermissions

public void copyFilePermissions(java.lang.String from_file_name,
                                java.lang.String to_file_name)
                         throws PlatformManagerException
Throws:
PlatformManagerException

showFile

public void showFile(java.lang.String path)
              throws PlatformManagerException
Reveals the file or directory with the platform's default browser

Specified by:
showFile in interface PlatformManager
Parameters:
path - The full path to a file or directory
Throws:
PlatformManagerException - If this operation fails

playSystemAlert

public void playSystemAlert()
Plays the system alert (the jingle is specified by the user in System Preferences)


showInFinder

public void showInFinder(java.io.File path)

Shows the given file or directory in Finder

Parameters:
path - Absolute path to the file or directory

showInTerminal

public void showInTerminal(java.lang.String path)

Shows the given file or directory in Terminal by executing cd /absolute/path/to

Parameters:
path - Absolute path to the file or directory

showInTerminal

public void showInTerminal(java.io.File path)

Shows the given file or directory in Terminal by executing cd /absolute/path/to

Parameters:
path - Absolute path to the file or directory

performOSAScript

protected static java.lang.String performOSAScript(java.lang.CharSequence cmd)
                                            throws java.io.IOException
Compiles a new AppleScript instance and runs it

Parameters:
cmd - AppleScript command to execute; do not surround command with extra quotation marks
Returns:
Output of the script
Throws:
java.io.IOException - If the script failed to execute

performOSAScript

protected static java.lang.String performOSAScript(java.lang.CharSequence[] cmds)
                                            throws java.io.IOException
Compiles a new AppleScript instance and runs it

Parameters:
cmds - AppleScript Sequence of commands to execute; do not surround command with extra quotation marks
Returns:
Output of the script
Throws:
java.io.IOException - If the script failed to execute

performOSAScript

protected static java.lang.String performOSAScript(java.io.File script)
                                            throws java.io.IOException
Compiles a new AppleScript instance and runs it

Parameters:
script - AppleScript file (.scpt) to execute
Returns:
Output of the script
Throws:
java.io.IOException - If the script failed to execute

compileOSAScript

protected static boolean compileOSAScript(java.lang.CharSequence cmd,
                                          java.io.File destination)
Compiles a new AppleScript instance to the specified location

Parameters:
cmd - Command to compile; do not surround command with extra quotation marks
destination - Destination location of the AppleScript file
Returns:
True if compiled successfully

compileOSAScript

protected static boolean compileOSAScript(java.lang.CharSequence[] cmds,
                                          java.io.File destination)
Compiles a new AppleScript instance to the specified location

Parameters:
cmds - Sequence of commands to compile; do not surround command with extra quotation marks
destination - Destination location of the AppleScript file
Returns:
True if compiled successfully

performRuntimeExec

protected static java.lang.Process performRuntimeExec(java.lang.String[] cmdargs)
                                               throws java.io.IOException
Throws:
java.io.IOException
See Also:
Runtime.exec(String[])

testNativeAvailability

public boolean testNativeAvailability(java.lang.String name)
                               throws PlatformManagerException
Throws:
PlatformManagerException

traceRoute

public void traceRoute(java.net.InetAddress interface_address,
                       java.net.InetAddress target,
                       PlatformManagerPingCallback callback)
                throws PlatformManagerException
Throws:
PlatformManagerException

ping

public void ping(java.net.InetAddress interface_address,
                 java.net.InetAddress target,
                 PlatformManagerPingCallback callback)
          throws PlatformManagerException
Throws:
PlatformManagerException

getMaxOpenFiles

public int getMaxOpenFiles()
                    throws PlatformManagerException
Description copied from interface: PlatformManager
This max-open-files concept here is from linux/osx where network connections are treated as 'files'

Returns:
Throws:
PlatformManagerException

addListener

public void addListener(PlatformManagerListener listener)

removeListener

public void removeListener(PlatformManagerListener listener)

generate

public void generate(IndentWriter writer)
Specified by:
generate in interface AEDiagnosticsEvidenceGenerator

getAzComputerID

public java.lang.String getAzComputerID()
                                 throws PlatformManagerException
Throws:
PlatformManagerException

requestUserAttention

public void requestUserAttention(int type,
                                 java.lang.Object data)
                          throws PlatformManagerException
If the application is not active causes the application icon at the bottom to bounce until the application becomes active If the application is already active then this method does nothing. Note: This is an undocumented feature from Apple so it's behavior may change without warning

Parameters:
type - one of USER_REQUEST_INFO, USER_REQUEST_WARNING
Throws:
PlatformManagerException

loadClass

public java.lang.Class<?> loadClass(java.lang.ClassLoader loader,
                                    java.lang.String class_name)
                             throws PlatformManagerException
Description copied from interface: PlatformManager
Gives a particular platform the ability to alter the class-loading method

Returns:
Throws:
PlatformManagerException

main

public static void main(java.lang.String[] args)