Starting to clean vendor structure

This commit is contained in:
2014-10-13 22:35:09 +01:00
parent 22fbc6edc5
commit 1b8a6bc544
225 changed files with 2 additions and 44440 deletions

Binary file not shown.

Binary file not shown.

View File

@@ -1,151 +0,0 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?fileVersion 4.0.0?><cproject storage_type_id="org.eclipse.cdt.core.XmlProjectDescriptionStorage">
<storageModule moduleId="org.eclipse.cdt.core.settings">
<cconfiguration id="cdt.managedbuild.config.gnu.mingw.exe.debug.1313294112">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.mingw.exe.debug.1313294112" moduleId="org.eclipse.cdt.core.settings" name="Debug">
<macros>
<stringMacro name="target" type="VALUE_TEXT" value="wiiscan"/>
</macros>
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.PE" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${target}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.debug,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.mingw.exe.debug.1313294112" name="Debug" parent="cdt.managedbuild.config.gnu.mingw.exe.debug">
<folderInfo id="cdt.managedbuild.config.gnu.mingw.exe.debug.1313294112." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.mingw.exe.debug.1606459632" name="MinGW GCC" superClass="cdt.managedbuild.toolchain.gnu.mingw.exe.debug">
<targetPlatform id="cdt.managedbuild.target.gnu.platform.mingw.exe.debug.1400801069" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.mingw.exe.debug"/>
<builder buildPath="${workspace_loc:/Wiiscan/Debug}" id="cdt.managedbuild.tool.gnu.builder.mingw.base.1038745333" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="CDT Internal Builder" superClass="cdt.managedbuild.tool.gnu.builder.mingw.base"/>
<tool command="as" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" id="cdt.managedbuild.tool.gnu.assembler.mingw.exe.debug.312047017" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.mingw.exe.debug">
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.1633887679" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.archiver.mingw.base.467778333" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.mingw.base"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.compiler.mingw.exe.debug.480343089" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.mingw.exe.debug">
<option id="gnu.cpp.compiler.mingw.exe.debug.option.optimization.level.1217318328" name="Optimization Level" superClass="gnu.cpp.compiler.mingw.exe.debug.option.optimization.level" value="gnu.cpp.compiler.optimization.level.none" valueType="enumerated"/>
<option id="gnu.cpp.compiler.mingw.exe.debug.option.debugging.level.1686233059" name="Debug Level" superClass="gnu.cpp.compiler.mingw.exe.debug.option.debugging.level" value="gnu.cpp.compiler.debugging.level.max" valueType="enumerated"/>
<option id="gnu.cpp.compiler.option.include.paths.1929858827" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/include}&quot;"/>
</option>
<option id="gnu.cpp.compiler.option.other.other.1746557196" name="Other flags" superClass="gnu.cpp.compiler.option.other.other" value="-c -fmessage-length=0" valueType="string"/>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1020795710" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.debug.226403212" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.debug">
<option defaultValue="gnu.c.optimization.level.none" id="gnu.c.compiler.mingw.exe.debug.option.optimization.level.805230373" name="Optimization Level" superClass="gnu.c.compiler.mingw.exe.debug.option.optimization.level" valueType="enumerated"/>
<option id="gnu.c.compiler.mingw.exe.debug.option.debugging.level.958575927" name="Debug Level" superClass="gnu.c.compiler.mingw.exe.debug.option.debugging.level" value="gnu.c.debugging.level.max" valueType="enumerated"/>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.15033032" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.mingw.exe.debug.1193975353" name="MinGW C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.mingw.exe.debug"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.mingw.exe.debug.945221910" name="MinGW C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.mingw.exe.debug">
<option id="gnu.cpp.link.option.paths.1277553684" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths" valueType="libPaths">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/lib}&quot;"/>
</option>
<option id="gnu.cpp.link.option.libs.683496236" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" valueType="libs">
<listOptionValue builtIn="false" value="odbccp32"/>
<listOptionValue builtIn="false" value="wiiuse"/>
<listOptionValue builtIn="false" value="irprops"/>
<listOptionValue builtIn="false" value="libcpmt"/>
</option>
<option id="gnu.cpp.link.option.flags.941494999" name="Linker flags" superClass="gnu.cpp.link.option.flags" value="" valueType="string"/>
<option id="gnu.cpp.link.option.strip.132174675" name="Omit all symbol information (-s)" superClass="gnu.cpp.link.option.strip" value="false" valueType="boolean"/>
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1294514710" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
<cconfiguration id="cdt.managedbuild.config.gnu.mingw.exe.release.1147005981">
<storageModule buildSystemId="org.eclipse.cdt.managedbuilder.core.configurationDataProvider" id="cdt.managedbuild.config.gnu.mingw.exe.release.1147005981" moduleId="org.eclipse.cdt.core.settings" name="Release">
<macros>
<stringMacro name="target" type="VALUE_TEXT" value="wiiscan"/>
</macros>
<externalSettings/>
<extensions>
<extension id="org.eclipse.cdt.core.GCCErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GASErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.GLDErrorParser" point="org.eclipse.cdt.core.ErrorParser"/>
<extension id="org.eclipse.cdt.core.PE" point="org.eclipse.cdt.core.BinaryParser"/>
</extensions>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<configuration artifactName="${target}" buildArtefactType="org.eclipse.cdt.build.core.buildArtefactType.exe" buildProperties="org.eclipse.cdt.build.core.buildType=org.eclipse.cdt.build.core.buildType.release,org.eclipse.cdt.build.core.buildArtefactType=org.eclipse.cdt.build.core.buildArtefactType.exe" cleanCommand="rm -rf" description="" id="cdt.managedbuild.config.gnu.mingw.exe.release.1147005981" name="Release" parent="cdt.managedbuild.config.gnu.mingw.exe.release">
<folderInfo id="cdt.managedbuild.config.gnu.mingw.exe.release.1147005981." name="/" resourcePath="">
<toolChain id="cdt.managedbuild.toolchain.gnu.mingw.exe.release.1457737133" name="MinGW GCC" superClass="cdt.managedbuild.toolchain.gnu.mingw.exe.release">
<targetPlatform id="cdt.managedbuild.target.gnu.platform.mingw.exe.release.1320357259" name="Debug Platform" superClass="cdt.managedbuild.target.gnu.platform.mingw.exe.release"/>
<builder buildPath="${workspace_loc:/Wiiscan/Release}" id="cdt.managedbuild.tool.gnu.builder.mingw.base.1900936223" keepEnvironmentInBuildfile="false" managedBuildOn="true" name="CDT Internal Builder" superClass="cdt.managedbuild.tool.gnu.builder.mingw.base"/>
<tool command="as" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" id="cdt.managedbuild.tool.gnu.assembler.mingw.exe.release.1320132974" name="GCC Assembler" superClass="cdt.managedbuild.tool.gnu.assembler.mingw.exe.release">
<inputType id="cdt.managedbuild.tool.gnu.assembler.input.2118467120" superClass="cdt.managedbuild.tool.gnu.assembler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.archiver.mingw.base.24300882" name="GCC Archiver" superClass="cdt.managedbuild.tool.gnu.archiver.mingw.base"/>
<tool command="g++" commandLinePattern="${COMMAND} ${FLAGS} ${OUTPUT_FLAG} ${OUTPUT_PREFIX}${OUTPUT} ${INPUTS}" id="cdt.managedbuild.tool.gnu.cpp.compiler.mingw.exe.release.1597340797" name="GCC C++ Compiler" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.mingw.exe.release">
<option id="gnu.cpp.compiler.mingw.exe.release.option.optimization.level.434289127" name="Optimization Level" superClass="gnu.cpp.compiler.mingw.exe.release.option.optimization.level" value="gnu.cpp.compiler.optimization.level.most" valueType="enumerated"/>
<option id="gnu.cpp.compiler.mingw.exe.release.option.debugging.level.925028123" name="Debug Level" superClass="gnu.cpp.compiler.mingw.exe.release.option.debugging.level" value="gnu.cpp.compiler.debugging.level.none" valueType="enumerated"/>
<option id="gnu.cpp.compiler.option.include.paths.1857921938" name="Include paths (-I)" superClass="gnu.cpp.compiler.option.include.paths" valueType="includePath">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/include}&quot;"/>
</option>
<option id="gnu.cpp.compiler.option.other.other.1784522890" name="Other flags" superClass="gnu.cpp.compiler.option.other.other" value="-c -fmessage-length=0" valueType="string"/>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.1090014067" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.release.481111125" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.release">
<option defaultValue="gnu.c.optimization.level.most" id="gnu.c.compiler.mingw.exe.release.option.optimization.level.1533075923" name="Optimization Level" superClass="gnu.c.compiler.mingw.exe.release.option.optimization.level" valueType="enumerated"/>
<option id="gnu.c.compiler.mingw.exe.release.option.debugging.level.1946013826" name="Debug Level" superClass="gnu.c.compiler.mingw.exe.release.option.debugging.level" value="gnu.c.debugging.level.none" valueType="enumerated"/>
<inputType id="cdt.managedbuild.tool.gnu.c.compiler.input.1764704290" superClass="cdt.managedbuild.tool.gnu.c.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.linker.mingw.exe.release.98347709" name="MinGW C Linker" superClass="cdt.managedbuild.tool.gnu.c.linker.mingw.exe.release"/>
<tool id="cdt.managedbuild.tool.gnu.cpp.linker.mingw.exe.release.1801877662" name="MinGW C++ Linker" superClass="cdt.managedbuild.tool.gnu.cpp.linker.mingw.exe.release">
<option id="gnu.cpp.link.option.libs.1604900232" name="Libraries (-l)" superClass="gnu.cpp.link.option.libs" valueType="libs">
<listOptionValue builtIn="false" value="odbccp32"/>
<listOptionValue builtIn="false" value="wiiuse"/>
<listOptionValue builtIn="false" value="irprops"/>
<listOptionValue builtIn="false" value="libcpmt"/>
</option>
<option id="gnu.cpp.link.option.paths.1267841202" name="Library search path (-L)" superClass="gnu.cpp.link.option.paths" valueType="libPaths">
<listOptionValue builtIn="false" value="&quot;${workspace_loc:/${ProjName}/lib}&quot;"/>
</option>
<option id="gnu.cpp.link.option.flags.755517020" name="Linker flags" superClass="gnu.cpp.link.option.flags" value="" valueType="string"/>
<option id="gnu.cpp.link.option.strip.1519066152" name="Omit all symbol information (-s)" superClass="gnu.cpp.link.option.strip" value="false" valueType="boolean"/>
<inputType id="cdt.managedbuild.tool.gnu.cpp.linker.input.1431555461" superClass="cdt.managedbuild.tool.gnu.cpp.linker.input">
<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
<additionalInput kind="additionalinput" paths="$(LIBS)"/>
</inputType>
</tool>
</toolChain>
</folderInfo>
</configuration>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.externalSettings"/>
</cconfiguration>
</storageModule>
<storageModule moduleId="cdtBuildSystem" version="4.0.0">
<project id="Wiiscan.cdt.managedbuild.target.gnu.mingw.exe.1693973787" name="Executable" projectType="cdt.managedbuild.target.gnu.mingw.exe"/>
</storageModule>
<storageModule moduleId="scannerConfiguration">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId=""/>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.mingw.exe.debug.1313294112;cdt.managedbuild.config.gnu.mingw.exe.debug.1313294112.;cdt.managedbuild.tool.gnu.cpp.compiler.mingw.exe.debug.480343089;cdt.managedbuild.tool.gnu.cpp.compiler.input.1020795710">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP"/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.mingw.exe.release.1147005981;cdt.managedbuild.config.gnu.mingw.exe.release.1147005981.;cdt.managedbuild.tool.gnu.cpp.compiler.mingw.exe.release.1597340797;cdt.managedbuild.tool.gnu.cpp.compiler.input.1090014067">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileCPP"/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.mingw.exe.debug.1313294112;cdt.managedbuild.config.gnu.mingw.exe.debug.1313294112.;cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.debug.226403212;cdt.managedbuild.tool.gnu.c.compiler.input.15033032">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/>
</scannerConfigBuildInfo>
<scannerConfigBuildInfo instanceId="cdt.managedbuild.config.gnu.mingw.exe.release.1147005981;cdt.managedbuild.config.gnu.mingw.exe.release.1147005981.;cdt.managedbuild.tool.gnu.c.compiler.mingw.exe.release.481111125;cdt.managedbuild.tool.gnu.c.compiler.input.1764704290">
<autodiscovery enabled="true" problemReportingEnabled="true" selectedProfileId="org.eclipse.cdt.managedbuilder.core.GCCManagedMakePerProjectProfileC"/>
</scannerConfigBuildInfo>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.core.pathentry"/>
<storageModule moduleId="refreshScope" versionNumber="1">
<resource resourceType="PROJECT" workspacePath="/Wiiscan"/>
</storageModule>
<storageModule moduleId="org.eclipse.cdt.internal.ui.text.commentOwnerProjectMappings"/>
<storageModule moduleId="org.eclipse.cdt.core.LanguageSettingsProviders"/>
</cproject>

View File

@@ -1,71 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>cpp.wiiscan</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
<triggers>clean,full,incremental,</triggers>
<arguments>
<dictionary>
<key>?name?</key>
<value></value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.append_environment</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.buildArguments</key>
<value></value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.buildCommand</key>
<value>make</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.buildLocation</key>
<value>${workspace_loc:/Wiiscan/Release}</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.contents</key>
<value>org.eclipse.cdt.make.core.activeConfigSettings</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableAutoBuild</key>
<value>false</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableCleanBuild</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.enableFullBuild</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.stopOnError</key>
<value>true</value>
</dictionary>
<dictionary>
<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
<value>true</value>
</dictionary>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
<triggers>full,incremental,</triggers>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.cdt.core.cnature</nature>
<nature>org.eclipse.cdt.core.ccnature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
</natures>
</projectDescription>

File diff suppressed because it is too large Load Diff

View File

@@ -1,125 +0,0 @@
// Delcom Engineering
// DelcomDLL.h
// Version 0.6
// 02/11/07
#ifndef DELCOMDLL_HEADER
#define DELCOMDLL_HEADER 1
// defines
#define OFF 0
#define ON 1
#define FLASH 2
#define USBIODS 1
#define USBDELVI 2
#define USBNDSPY 3
#define GREENLED 0
#define REDLED 1
#define BLUELED 2
#define MaxDeviceLen 512
// Typedef
typedef struct _DeviceNameStruct{
char DeviceName[MaxDeviceLen];
} DeviceNameStruct, *pDeviceNameStruct;
typedef unsigned long DWORD;
typedef int BOOL;
typedef unsigned char BYTE;
typedef char CHAR;
typedef unsigned short WORD;
typedef void * HANDLE;
typedef CHAR *LPSTR, *PSTR;
typedef unsigned char uchar;
typedef unsigned int uint;
typedef struct _PacketStruct{
uchar Recipient;
uchar DeviceModel;
uchar MajorCmd;
uchar MinorCmd;
uchar DataLSB;
uchar DataMSB;
short Length;
uchar ExtData[8];
} PacketStruct,*pPacketStruct;
// DLL Generic Functions
HANDLE DelcomGetDLLHandle(void);
double __stdcall DelcomGetDLLVersion(void);
DWORD __stdcall DelcomGetDLLDate(LPSTR);
DWORD __stdcall DelcomVerboseControl( DWORD Mode, LPSTR Header );
DWORD __stdcall DelcomGetNthDevice(DWORD, DWORD, LPSTR);
DWORD __stdcall DelcomScanDevices( DWORD, DeviceNameStruct[], DWORD );
HANDLE __stdcall DelcomOpenDevice( LPSTR, DWORD);
DWORD __stdcall DelcomCloseDevice(HANDLE);
DWORD __stdcall DelcomGetDeviceCount( DWORD Type );
DWORD __stdcall DelcomReadDeviceVersion(HANDLE );
DWORD __stdcall DelcomReadDeviceSerialNum(LPSTR, HANDLE );
DWORD __stdcall DelcomSendPacket( HANDLE, pPacketStruct, pPacketStruct);
// USBDELVI - Visual Indicator Functions
DWORD __stdcall DelcomLEDControl( HANDLE hFile, DWORD Color, DWORD Mode );
DWORD __stdcall DelcomEnableAutoConfirm(HANDLE hUsb, DWORD Mode);
DWORD __stdcall DelcomEnableAutoClear(HANDLE hUsb, DWORD Mode);
DWORD __stdcall DelcomBuzzer(HANDLE hUsb, uchar Mode, uchar Freq, uchar Repeat, uchar OnTime, uchar OffTime);
DWORD __stdcall DelcomLoadInitialPhaseDelay(HANDLE hUsb, BYTE Color, BYTE Delay);
DWORD __stdcall DelcomSyncLeds(HANDLE hUsb);
DWORD __stdcall DelcomLoadPreScalar(HANDLE hUsb, BYTE PreScalar);
DWORD __stdcall DelcomLoadLedFreqDuty(HANDLE hUsb, BYTE Color, BYTE Low, BYTE High);
DWORD __stdcall DelcomGetButtonStatus(HANDLE hUsb );
DWORD __stdcall DelcomReadVersionNumber(HANDLE hUsb );
DWORD __stdcall DelcomReadSerialNumber(HANDLE hUsb );
DWORD __stdcall DelcomLEDPower( HANDLE hUsb, DWORD Color, DWORD Power );
// USBIODS - USB IO Functions
DWORD __stdcall DelcomWritePortPin(HANDLE hUsb, BYTE Port, BYTE Pin, BYTE Value );
DWORD __stdcall DelcomWritePorts(HANDLE hUsb, BYTE Port0, BYTE Port1 );
DWORD __stdcall DelcomReadPorts(HANDLE hUsb, BYTE* Port0, BYTE* Port1 );
DWORD __stdcall DelcomWrite64Bit(HANDLE hUsb, LPSTR DataExt );
DWORD __stdcall DelcomRead64Bit(HANDLE hUsb, LPSTR DataExt );
DWORD __stdcall DelcomWriteI2C(HANDLE hUsb, BYTE CmdAdd, BYTE Length, LPSTR DataExt );
DWORD __stdcall DelcomReadI2C(HANDLE hUsb, BYTE CmdAdd, BYTE Length, LPSTR DataExt );
DWORD __stdcall DelcomSelReadI2C(HANDLE hUsb, BYTE SetAddCmd, BYTE Address, BYTE ReadCmd, BYTE Length, LPSTR DataExt );
DWORD __stdcall DelcomWriteI2CEEPROM(HANDLE hUsb, DWORD Address, DWORD Length, BYTE CtrlCode, BYTE WriteDelay, LPSTR pData );
DWORD __stdcall DelcomReadI2CEEPROM(HANDLE hUsb, DWORD Address, DWORD Length, BYTE CtrlCode, LPSTR pData );
DWORD __stdcall DelcomRS232Ctrl(HANDLE hUsb, DWORD Mode, DWORD Value );
DWORD __stdcall DelcomWriteRS232(HANDLE hUsb, DWORD Length, LPSTR DataExt );
DWORD __stdcall DelcomReadRS232(HANDLE hUsb, LPSTR DataExt );
// SPI Commands
DWORD __stdcall DelcomSPIWrite( HANDLE hUsb, DWORD ClockCount, LPSTR pData);
DWORD __stdcall DelcomSPISetClock( HANDLE hUsb, DWORD ClockPeriod );
DWORD __stdcall DelcomSPIRead(HANDLE hUsb, LPSTR pData);
DWORD __stdcall DelcomSPIWr8Read64( HANDLE hUsb, DWORD WrData, DWORD ClockCount, LPSTR pData);
// USBNDSPY Functions
DWORD __stdcall DelcomNumericMode(HANDLE hUsb, BYTE Mode, BYTE Rate );
DWORD __stdcall DelcomNumericScanRate(HANDLE hUsb, BYTE ScanRate );
DWORD __stdcall DelcomNumericSetup(HANDLE hUsb, BYTE Digits );
DWORD __stdcall DelcomNumericRaw(HANDLE hUsb, LPSTR Str );
DWORD __stdcall DelcomNumericInteger(HANDLE hUsb, DWORD Number, DWORD Base );
DWORD __stdcall DelcomNumericHexaDecimal(HANDLE hUsb, DWORD Number, DWORD Base );
DWORD __stdcall DelcomNumericDouble(HANDLE hUsb, double Number, DWORD Base );
#endif

View File

@@ -1,858 +0,0 @@
/*++
Copyright (c) 2000 Microsoft Corporation
Module Name:
bthdef.h
Abstract:
This module contains the Bluetooth common structures and definitions
Author:
Notes:
Environment:
Kernel mode only
Revision History:
--*/
#ifndef __BTHDEF_H__
#define __BTHDEF_H__
#ifndef GUID_DEFS_ONLY
#ifndef NO_BTHSDPDEF_INC
#include "bthsdpdef.h"
#endif // NO_BTHSDPDEF_INC
#endif // GUID_DEFS_ONLY
#ifndef NO_GUID_DEFS
// {0850302A-B344-4fda-9BE9-90576B8D46F0}
DEFINE_GUID(GUID_BTHPORT_DEVICE_INTERFACE, 0x850302a, 0xb344, 0x4fda, 0x9b, 0xe9, 0x90, 0x57, 0x6b, 0x8d, 0x46, 0xf0);
// {EA3B5B82-26EE-450E-B0D8-D26FE30A3869}
DEFINE_GUID(GUID_BLUETOOTH_RADIO_IN_RANGE, 0xea3b5b82, 0x26ee, 0x450e, 0xb0, 0xd8, 0xd2, 0x6f, 0xe3, 0x0a, 0x38, 0x69);
// {E28867C9-C2AA-4CED-B969-4570866037C4}
DEFINE_GUID(GUID_BLUETOOTH_RADIO_OUT_OF_RANGE, 0xe28867c9, 0xc2aa, 0x4ced, 0xb9, 0x69, 0x45, 0x70, 0x86, 0x60, 0x37, 0xc4);
// BD198B7C-24AB-4B9A-8C0D-A8EA8349AA16
DEFINE_GUID(GUID_BLUETOOTH_PIN_REQUEST, 0xbd198b7c, 0x24ab, 0x4b9a, 0x8c, 0x0d, 0xa8, 0xea, 0x83, 0x49, 0xaa, 0x16);
// {7EAE4030-B709-4AA8-AC55-E953829C9DAA}
DEFINE_GUID(GUID_BLUETOOTH_L2CAP_EVENT, 0x7eae4030, 0xb709, 0x4aa8, 0xac, 0x55, 0xe9, 0x53, 0x82, 0x9c, 0x9d, 0xaa);
// {FC240062-1541-49BE-B463-84C4DCD7BF7F}
DEFINE_GUID(GUID_BLUETOOTH_HCI_EVENT, 0xfc240062, 0x1541, 0x49be, 0xb4, 0x63, 0x84, 0xc4, 0xdc, 0xd7, 0xbf, 0x7f);
//
// Bluetooth base UUID for service discovery
//
DEFINE_GUID(Bluetooth_Base_UUID, 0x00000000, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
//
// UUID for the root of the browse group list
//
DEFINE_GUID(SDP_PROTOCOL_UUID, 0x00000001, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(UDP_PROTOCOL_UUID, 0x00000002, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(RFCOMM_PROTOCOL_UUID, 0x00000003, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(TCP_PROTOCOL_UUID, 0x00000004, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(TCSBIN_PROTOCOL_UUID, 0x00000005, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(TCSAT_PROTOCOL_UUID, 0x00000006, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(OBEX_PROTOCOL_UUID, 0x00000008, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(IP_PROTOCOL_UUID, 0x00000009, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(FTP_PROTOCOL_UUID, 0x0000000A, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(HTTP_PROTOCOL_UUID, 0x0000000C, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(WSP_PROTOCOL_UUID, 0x0000000E, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(BNEP_PROTOCOL_UUID, 0x0000000F, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(UPNP_PROTOCOL_UUID, 0x00000010, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(HID_PROTOCOL_UUID, 0x00000011, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(HCCC_PROTOCOL_UUID, 0x00000012, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(HCDC_PROTOCOL_UUID, 0x00000014, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(HN_PROTOCOL_UUID, 0x00000016, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(AVCTP_PROTOCOL_UUID, 0x00000017, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(AVDTP_PROTOCOL_UUID, 0x00000019, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(CMPT_PROTOCOL_UUID, 0x0000001B, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(UDI_C_PLANE_PROTOCOL_UUID, 0x0000001D, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(L2CAP_PROTOCOL_UUID, 0x00000100, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
#define SDP_PROTOCOL_UUID16 (0x0001)
#define UDP_PROTOCOL_UUID16 (0x0002)
#define RFCOMM_PROTOCOL_UUID16 (0x0003)
#define TCP_PROTOCOL_UUID16 (0x0004)
#define TCSBIN_PROTOCOL_UUID16 (0x0005)
#define TCSAT_PROTOCOL_UUID16 (0x0006)
#define OBEX_PROTOCOL_UUID16 (0x0008)
#define IP_PROTOCOL_UUID16 (0x0009)
#define FTP_PROTOCOL_UUID16 (0x000A)
#define HTTP_PROTOCOL_UUID16 (0x000C)
#define WSP_PROTOCOL_UUID16 (0x000E)
#define BNEP_PROTOCOL_UUID16 (0x000F)
#define UPNP_PROTOCOL_UUID16 (0x0010)
#define HID_PROTOCOL_UUID16 (0x0011)
#define HCCC_PROTOCOL_UUID16 (0x0012)
#define HCDC_PROTOCOL_UUID16 (0x0014)
#define HCN_PROTOCOL_UUID16 (0x0016)
#define AVCTP_PROTOCOL_UUID16 (0x0017)
#define AVDTP_PROTOCOL_UUID16 (0x0019)
#define CMPT_PROTOCOL_UUID16 (0x001B)
#define UDI_C_PLANE_PROTOCOL_UUID16 (0x001D)
#define L2CAP_PROTOCOL_UUID16 (0x0100)
DEFINE_GUID(ServiceDiscoveryServerServiceClassID_UUID, 0x00001000, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(BrowseGroupDescriptorServiceClassID_UUID, 0x00001001, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(PublicBrowseGroupServiceClass_UUID, 0x00001002, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(SerialPortServiceClass_UUID, 0x00001101, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(LANAccessUsingPPPServiceClass_UUID, 0x00001102, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(DialupNetworkingServiceClass_UUID, 0x00001103, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(IrMCSyncServiceClass_UUID, 0x00001104, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(OBEXObjectPushServiceClass_UUID, 0x00001105, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(OBEXFileTransferServiceClass_UUID, 0x00001106, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(IrMCSyncCommandServiceClass_UUID, 0x00001107, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(HeadsetServiceClass_UUID, 0x00001108, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(CordlessTelephonyServiceClass_UUID, 0x00001109, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(AudioSourceServiceClass_UUID, 0x0000110A, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(AudioSinkServiceClass_UUID, 0x0000110B, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(AVRemoteControlTargetServiceClass_UUID, 0x0000110C, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(AdvancedAudioDistributionServiceClass_UUID,0x0000110D, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(AVRemoteControlServiceClass_UUID, 0x0000110E, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(VideoConferencingServiceClass_UUID, 0x0000110F, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(IntercomServiceClass_UUID, 0x00001110, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(FaxServiceClass_UUID, 0x00001111, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(HeadsetAudioGatewayServiceClass_UUID, 0x00001112, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(WAPServiceClass_UUID, 0x00001113, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(WAPClientServiceClass_UUID, 0x00001114, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(PANUServiceClass_UUID, 0x00001115, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(NAPServiceClass_UUID, 0x00001116, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(GNServiceClass_UUID, 0x00001117, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(DirectPrintingServiceClass_UUID, 0x00001118, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(ReferencePrintingServiceClass_UUID, 0x00001119, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(ImagingServiceClass_UUID, 0x0000111A, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(ImagingResponderServiceClass_UUID, 0x0000111B, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(ImagingAutomaticArchiveServiceClass_UUID, 0x0000111C, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(ImagingReferenceObjectsServiceClass_UUID, 0x0000111D, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(HandsfreeServiceClass_UUID, 0x0000111E, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(HandsfreeAudioGatewayServiceClass_UUID, 0x0000111F, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(DirectPrintingReferenceObjectsServiceClass_UUID,
0x00001120, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(ReflectedUIServiceClass_UUID, 0x00001121, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(BasicPringingServiceClass_UUID, 0x00001122, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(PrintingStatusServiceClass_UUID, 0x00001123, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(HumanInterfaceDeviceServiceClass_UUID, 0x00001124, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(HardcopyCableReplacementServiceClass_UUID, 0x00001125, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(HCRPrintServiceClass_UUID, 0x00001126, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(HCRScanServiceClass_UUID, 0x00001127, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(CommonISDNAccessServiceClass_UUID, 0x00001128, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(VideoConferencingGWServiceClass_UUID, 0x00001129, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(UDIMTServiceClass_UUID, 0x0000112A, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(UDITAServiceClass_UUID, 0x0000112B, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(AudioVideoServiceClass_UUID, 0x0000112C, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(PnPInformationServiceClass_UUID, 0x00001200, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(GenericNetworkingServiceClass_UUID, 0x00001201, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(GenericFileTransferServiceClass_UUID, 0x00001202, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(GenericAudioServiceClass_UUID, 0x00001203, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
DEFINE_GUID(GenericTelephonyServiceClass_UUID, 0x00001204, 0x0000, 0x1000, 0x80, 0x00, 0x00, 0x80, 0x5F, 0x9B, 0x34, 0xFB);
#define ServiceDiscoveryServerServiceClassID_UUID16 (0x1000)
#define BrowseGroupDescriptorServiceClassID_UUID16 (0x1001)
#define PublicBrowseGroupServiceClassID_UUID16 (0x1002)
#define SerialPortServiceClassID_UUID16 (0x1101)
#define LANAccessUsingPPPServiceClassID_UUID16 (0x1102)
#define DialupNetworkingServiceClassID_UUID16 (0x1103)
#define IrMCSyncServiceClassID_UUID16 (0x1104)
#define OBEXObjectPushServiceClassID_UUID16 (0x1105)
#define OBEXFileTransferServiceClassID_UUID16 (0x1106)
#define IrMcSyncCommandServiceClassID_UUID16 (0x1107)
#define HeadsetServiceClassID_UUID16 (0x1108)
#define CordlessServiceClassID_UUID16 (0x1109)
#define AudioSourceServiceClassID_UUID16 (0x110A)
#define AudioSinkSourceServiceClassID_UUID16 (0x110B)
#define AVRemoteControlTargetServiceClassID_UUID16 (0x110C)
#define AdvancedAudioDistributionServiceClassID_UUID16 (0x110D)
#define AVRemoteControlServiceClassID_UUID16 (0x110E)
#define VideoConferencingServiceClassID_UUID16 (0x110F)
#define IntercomServiceClassID_UUID16 (0x1110)
#define FaxServiceClassID_UUID16 (0x1111)
#define HeadsetAudioGatewayServiceClassID_UUID16 (0x1112)
#define WAPServiceClassID_UUID16 (0x1113)
#define WAPClientServiceClassID_UUID16 (0x1114)
#define PANUServiceClassID_UUID16 (0x1115)
#define NAPServiceClassID_UUID16 (0x1116)
#define GNServiceClassID_UUID16 (0x1117)
#define DirectPrintingServiceClassID_UUID16 (0x1118)
#define ReferencePrintingServiceClassID_UUID16 (0x1119)
#define ImagingServiceClassID_UUID16 (0x111A)
#define ImagingResponderServiceClassID_UUID16 (0x111B)
#define ImagingAutomaticArchiveServiceClassID_UUID16 (0x111C)
#define ImagingReferenceObjectsServiceClassID_UUID16 (0x111D)
#define HandsfreeServiceClassID_UUID16 (0x111E)
#define HandsfreeAudioGatewayServiceClassID_UUID16 (0x111F)
#define DirectPrintingReferenceObjectsServiceClassID_UUID16 \
(0x1120)
#define ReflectsUIServiceClassID_UUID16 (0x1121)
#define BasicPrintingServiceClassID_UUID16 (0x1122)
#define PrintingStatusServiceClassID_UUID16 (0x1123)
#define HumanInterfaceDeviceServiceClassID_UUID16 (0x1124)
#define HardcopyCableReplacementServiceClassID_UUID16 (0x1125)
#define HCRPrintServiceClassID_UUID16 (0x1126)
#define HCRScanServiceClassID_UUID16 (0x1127)
#define CommonISDNAccessServiceClass_UUID16 (0x1128)
#define VideoConferencingGWServiceClass_UUID16 (0x1129)
#define UDIMTServiceClass_UUID16 (0x112A)
#define UDITAServiceClass_UUID16 (0x112B)
#define AudioVideoServiceClass_UUID16 (0x112C)
#define PnPInformationServiceClassID_UUID16 (0x1200)
#define GenericNetworkingServiceClassID_UUID16 (0x1201)
#define GenericFileTransferServiceClassID_UUID16 (0x1202)
#define GenericAudioServiceClassID_UUID16 (0x1203)
#define GenericTelephonyServiceClassID_UUID16 (0x1204)
#endif // NO_GUID_DEFS
#ifndef GUID_DEFS_ONLY
//
// max length of device friendly name.
//
#define BTH_MAX_NAME_SIZE (248)
#define BTH_MAX_PIN_SIZE (16)
#define BTH_LINK_KEY_LENGTH (16)
#define BTH_MFG_ERICSSON (0)
#define BTH_MFG_NOKIA (1)
#define BTH_MFG_INTEL (2)
#define BTH_MFG_IBM (3)
#define BTH_MFG_TOSHIBA (4)
#define BTH_MFG_3COM (5)
#define BTH_MFG_MICROSOFT (6)
#define BTH_MFG_LUCENT (7)
#define BTH_MFG_MOTOROLA (8)
#define BTH_MFG_INFINEON (9)
#define BTH_MFG_CSR (10)
#define BTH_MFG_SILICONWAVE (11)
#define BTH_MFG_DIGIANSWER (12)
#define BTH_MFG_TI (13)
#define BTH_MFG_PARTHUS (14)
#define BTH_MFG_BROADCOM (15)
#define BTH_MFG_MITEL (16)
#define BTH_MFG_WIDCOMM (17)
#define BTH_MFG_ZEEVO (18)
#define BTH_MFG_ATMEL (19)
#define BTH_MFG_MITSIBUSHI (20)
#define BTH_MFG_RTX_TELECOM (21)
#define BTH_MFG_KC_TECHNOLOGY (22)
#define BTH_MFG_NEWLOGIC (23)
#define BTH_MFG_TRANSILICA (24)
#define BTH_MFG_ROHDE_SCHWARZ (25)
#define BTH_MFG_TTPCOM (26)
#define BTH_MFG_SIGNIA (27)
#define BTH_MFG_CONEXANT (28)
#define BTH_MFG_QUALCOMM (29)
#define BTH_MFG_INVENTEL (30)
#define BTH_MFG_AVM_BERLIN (31)
#define BTH_MFG_BANDSPEED (32)
#define BTH_MFG_MANSELLA (33)
#define BTH_MFG_NEC (34)
#define BTH_MFG_WAVEPLUS_TECHNOLOGY_CO (35)
#define BTH_MFG_ALCATEL (36)
#define BTH_MFG_PHILIPS_SEMICONDUCTOR (37)
#define BTH_MFG_C_TECHNOLOGIES (38)
#define BTH_MFG_OPEN_INTERFACE (39)
#define BTH_MFG_RF_MICRO_DEVICES (40)
#define BTH_MFG_HITACHI (41)
#define BTH_MFG_SYMBOL_TECHNOLOGIES (42)
#define BTH_MFG_TENOVIS (43)
#define BTH_MFG_MACRONIX_INTERNATIONAL (44)
#define BTH_MFG_INTERNAL_USE (65535)
typedef ULONGLONG BTH_ADDR, *PBTH_ADDR;
typedef ULONG BTH_COD, *PBTH_COD;
typedef ULONG BTH_LAP, *PBTH_LAP;
#define BTH_ADDR_NULL ((ULONGLONG) 0x0000000000000000)
#define NAP_MASK ((ULONGLONG) 0xFFFF00000000)
#define SAP_MASK ((ULONGLONG) 0x0000FFFFFFFF)
#define NAP_BIT_OFFSET (8 * 4)
#define SAP_BIT_OFFSET (0)
#define GET_NAP(_bth_addr) ((USHORT) (((_bth_addr) & NAP_MASK) >> NAP_BIT_OFFSET))
#define GET_SAP(_bth_addr) ((ULONG) (((_bth_addr) & SAP_MASK) >> SAP_BIT_OFFSET))
#define SET_NAP(_nap) (((ULONGLONG) ((USHORT) (_nap))) << NAP_BIT_OFFSET)
#define SET_SAP(_sap) (((ULONGLONG) ((ULONG) (_sap))) << SAP_BIT_OFFSET)
#define SET_NAP_SAP(_nap, _sap) (SET_NAP(_nap) | SET_SAP(_sap))
#define COD_FORMAT_BIT_OFFSET (0)
#define COD_MINOR_BIT_OFFSET (2)
#define COD_MAJOR_BIT_OFFSET (8 * 1)
#define COD_SERVICE_BIT_OFFSET (8 * 1 + 5)
#define COD_FORMAT_MASK (0x000003)
#define COD_MINOR_MASK (0x0000FC)
#define COD_MAJOR_MASK (0x001F00)
#define COD_SERVICE_MASK (0xFFE000)
#define GET_COD_FORMAT(_cod) ( (_cod) & COD_FORMAT_MASK >> COD_FORMAT_BIT_OFFSET)
#define GET_COD_MINOR(_cod) (((_cod) & COD_MINOR_MASK) >> COD_MINOR_BIT_OFFSET)
#define GET_COD_MAJOR(_cod) (((_cod) & COD_MAJOR_MASK) >> COD_MAJOR_BIT_OFFSET)
#define GET_COD_SERVICE(_cod) (((_cod) & COD_SERVICE_MASK) >> COD_SERVICE_BIT_OFFSET)
#define SET_COD_MINOR(_cod, _minor) (_cod) = ((_cod) & ~COD_MINOR_MASK) | ((_minor) << COD_MINOR_BIT_OFFSET)
#define SET_COD_MAJOR(_cod, _major) (_cod) = ((_cod) & ~COD_MAJOR_MASK) | ((_major) << COD_MAJOR_BIT_OFFSET)
#define SET_COD_SERVICE(_cod, _service) (_cod) = ((_cod) & ~COD_SERVICE_MASK) | ((_service) << COD_SERVICE_BIT_OFFSET)
#define COD_VERSION (0x0)
#define COD_SERVICE_LIMITED (0x0001)
#define COD_SERVICE_POSITIONING (0x0008)
#define COD_SERVICE_NETWORKING (0x0010)
#define COD_SERVICE_RENDERING (0x0020)
#define COD_SERVICE_CAPTURING (0x0040)
#define COD_SERVICE_OBJECT_XFER (0x0080)
#define COD_SERVICE_AUDIO (0x0100)
#define COD_SERVICE_TELEPHONY (0x0200)
#define COD_SERVICE_INFORMATION (0x0400)
#define COD_SERVICE_VALID_MASK (COD_SERVICE_LIMITED | \
COD_SERVICE_POSITIONING | \
COD_SERVICE_NETWORKING | \
COD_SERVICE_RENDERING | \
COD_SERVICE_CAPTURING | \
COD_SERVICE_OBJECT_XFER |\
COD_SERVICE_AUDIO |\
COD_SERVICE_TELEPHONY |\
COD_SERVICE_INFORMATION)
#define COD_SERVICE_MAX_COUNT (9)
//
// Major class codes
//
#define COD_MAJOR_MISCELLANEOUS (0x00)
#define COD_MAJOR_COMPUTER (0x01)
#define COD_MAJOR_PHONE (0x02)
#define COD_MAJOR_LAN_ACCESS (0x03)
#define COD_MAJOR_AUDIO (0x04)
#define COD_MAJOR_PERIPHERAL (0x05)
#define COD_MAJOR_IMAGING (0x06)
#define COD_MAJOR_UNCLASSIFIED (0x1F)
//
// Minor class codes specific to each major class
//
#define COD_COMPUTER_MINOR_UNCLASSIFIED (0x00)
#define COD_COMPUTER_MINOR_DESKTOP (0x01)
#define COD_COMPUTER_MINOR_SERVER (0x02)
#define COD_COMPUTER_MINOR_LAPTOP (0x03)
#define COD_COMPUTER_MINOR_HANDHELD (0x04)
#define COD_COMPUTER_MINOR_PALM (0x05)
#define COD_COMPUTER_MINOR_WEARABLE (0x06)
#define COD_PHONE_MINOR_UNCLASSIFIED (0x00)
#define COD_PHONE_MINOR_CELLULAR (0x01)
#define COD_PHONE_MINOR_CORDLESS (0x02)
#define COD_PHONE_MINOR_SMART (0x03)
#define COD_PHONE_MINOR_WIRED_MODEM (0x04)
#define COD_AUDIO_MINOR_UNCLASSIFIED (0x00)
#define COD_AUDIO_MINOR_HEADSET (0x01)
#define COD_AUDIO_MINOR_HANDS_FREE (0x02)
#define COD_AUDIO_MINOR_HEADSET_HANDS_FREE (0x03)
#define COD_AUDIO_MINOR_MICROPHONE (0x04)
#define COD_AUDIO_MINOR_LOUDSPEAKER (0x05)
#define COD_AUDIO_MINOR_HEADPHONES (0x06)
#define COD_AUDIO_MINOR_PORTABLE_AUDIO (0x07)
#define COD_AUDIO_MINOR_CAR_AUDIO (0x08)
#define COD_AUDIO_MINOR_SET_TOP_BOX (0x09)
#define COD_AUDIO_MINOR_HIFI_AUDIO (0x0A)
#define COD_AUDIO_MINOR_VCR (0x0B)
#define COD_AUDIO_MINOR_VIDEO_CAMERA (0x0C)
#define COD_AUDIO_MINOR_CAMCORDER (0x0D)
#define COD_AUDIO_MINOR_VIDEO_MONITOR (0x0E)
#define COD_AUDIO_MINOR_VIDEO_DISPLAY_LOUDSPEAKER \
(0x0F)
#define COD_AUDIO_MINOR_VIDEO_DISPLAY_CONFERENCING \
(0x10)
// #define COD_AUDIO_MINOR_RESERVED (0x11)
#define COD_AUDIO_MINOR_GAMING_TOY (0x12)
#define COD_PERIPHERAL_MINOR_KEYBOARD_MASK (0x10)
#define COD_PERIPHERAL_MINOR_POINTER_MASK (0x20)
#define COD_PERIPHERAL_MINOR_NO_CATEGORY (0x00)
#define COD_PERIPHERAL_MINOR_JOYSTICK (0x01)
#define COD_PERIPHERAL_MINOR_GAMEPAD (0x02)
#define COD_PERIPHERAL_MINOR_REMOTE_CONTROL (0x03)
#define COD_PERIPHERAL_MINOR_SENSING (0x04)
#define COD_IMAGING_MINOR_DISPLAY_MASK (0x04)
#define COD_IMAGING_MINOR_CAMERA_MASK (0x08)
#define COD_IMAGING_MINOR_SCANNER_MASK (0x10)
#define COD_IMAGING_MINOR_PRINTER_MASK (0x20)
//
// Cannot use GET_COD_MINOR for this b/c it is embedded in a different manner
// than the rest of the major classes
//
#define COD_LAN_ACCESS_BIT_OFFSET (5)
#define COD_LAN_MINOR_MASK (0x00001C)
#define COD_LAN_ACCESS_MASK (0x0000E0)
#define GET_COD_LAN_MINOR(_cod) (((_cod) & COD_LAN_MINOR_MASK) >> COD_MINOR_BIT_OFFSET)
#define GET_COD_LAN_ACCESS(_cod) (((_cod) & COD_LAN_ACCESS_MASK) >> COD_LAN_ACCESS_BIT_OFFSET)
//
// LAN access percent usage subcodes
//
#define COD_LAN_MINOR_UNCLASSIFIED (0x00)
#define COD_LAN_ACCESS_0_USED (0x00)
#define COD_LAN_ACCESS_17_USED (0x01)
#define COD_LAN_ACCESS_33_USED (0x02)
#define COD_LAN_ACCESS_50_USED (0x03)
#define COD_LAN_ACCESS_67_USED (0x04)
#define COD_LAN_ACCESS_83_USED (0x05)
#define COD_LAN_ACCESS_99_USED (0x06)
#define COD_LAN_ACCESS_FULL (0x07)
//
// Used as an initializer of LAP_DATA
//
#define LAP_GIAC_INIT { 0x33, 0x8B, 0x9E }
#define LAP_LIAC_INIT { 0x00, 0x8B, 0x9E }
//
// General Inquiry Access Code.
//
#define LAP_GIAC_VALUE (0x009E8B33)
//
// Limited Inquiry Access Code.
//
#define LAP_LIAC_VALUE (0x009E8B00)
#define BTH_ADDR_IAC_FIRST (0x9E8B00)
#define BTH_ADDR_IAC_LAST (0x9E8B3f)
#define BTH_ADDR_LIAC (0x9E8B00)
#define BTH_ADDR_GIAC (0x9E8B33)
typedef UCHAR BTHSTATUS, *PBTHSTATUS;
#define BTH_ERROR(_btStatus) ((_btStatus) != BTH_ERROR_SUCCESS)
#define BTH_SUCCESS(_btStatus) ((_btStatus) == BTH_ERROR_SUCCESS)
#define BTH_ERROR_SUCCESS (0x00)
#define BTH_ERROR_UNKNOWN_HCI_COMMAND (0x01)
#define BTH_ERROR_NO_CONNECTION (0x02)
#define BTH_ERROR_HARDWARE_FAILURE (0x03)
#define BTH_ERROR_PAGE_TIMEOUT (0x04)
#define BTH_ERROR_AUTHENTICATION_FAILURE (0x05)
#define BTH_ERROR_KEY_MISSING (0x06)
#define BTH_ERROR_MEMORY_FULL (0x07)
#define BTH_ERROR_CONNECTION_TIMEOUT (0x08)
#define BTH_ERROR_MAX_NUMBER_OF_CONNECTIONS (0x09)
#define BTH_ERROR_MAX_NUMBER_OF_SCO_CONNECTIONS (0x0a)
#define BTH_ERROR_ACL_CONNECTION_ALREADY_EXISTS (0x0b)
#define BTH_ERROR_COMMAND_DISALLOWED (0x0c)
#define BTH_ERROR_HOST_REJECTED_LIMITED_RESOURCES (0x0d)
#define BTH_ERROR_HOST_REJECTED_SECURITY_REASONS (0x0e)
#define BTH_ERROR_HOST_REJECTED_PERSONAL_DEVICE (0x0f)
#define BTH_ERROR_HOST_TIMEOUT (0x10)
#define BTH_ERROR_UNSUPPORTED_FEATURE_OR_PARAMETER (0x11)
#define BTH_ERROR_INVALID_HCI_PARAMETER (0x12)
#define BTH_ERROR_REMOTE_USER_ENDED_CONNECTION (0x13)
#define BTH_ERROR_REMOTE_LOW_RESOURCES (0x14)
#define BTH_ERROR_REMOTE_POWERING_OFF (0x15)
#define BTH_ERROR_LOCAL_HOST_TERMINATED_CONNECTION (0x16)
#define BTH_ERROR_REPEATED_ATTEMPTS (0x17)
#define BTH_ERROR_PAIRING_NOT_ALLOWED (0x18)
#define BTH_ERROR_UKNOWN_LMP_PDU (0x19)
#define BTH_ERROR_UNSUPPORTED_REMOTE_FEATURE (0x1a)
#define BTH_ERROR_SCO_OFFSET_REJECTED (0x1b)
#define BTH_ERROR_SCO_INTERVAL_REJECTED (0x1c)
#define BTH_ERROR_SCO_AIRMODE_REJECTED (0x1d)
#define BTH_ERROR_INVALID_LMP_PARAMETERS (0x1e)
#define BTH_ERROR_UNSPECIFIED_ERROR (0x1f)
#define BTH_ERROR_UNSUPPORTED_LMP_PARM_VALUE (0x20)
#define BTH_ERROR_ROLE_CHANGE_NOT_ALLOWED (0x21)
#define BTH_ERROR_LMP_RESPONSE_TIMEOUT (0x22)
#define BTH_ERROR_LMP_TRANSACTION_COLLISION (0x23)
#define BTH_ERROR_LMP_PDU_NOT_ALLOWED (0x24)
#define BTH_ERROR_ENCRYPTION_MODE_NOT_ACCEPTABLE (0x25)
#define BTH_ERROR_UNIT_KEY_NOT_USED (0x26)
#define BTH_ERROR_QOS_IS_NOT_SUPPORTED (0x27)
#define BTH_ERROR_INSTANT_PASSED (0x28)
#define BTH_ERROR_PAIRING_WITH_UNIT_KEY_NOT_SUPPORTED (0x29)
#define BTH_ERROR_UNSPECIFIED (0xFF)
//
// Min, max, and default L2cap MTU.
//
#define L2CAP_MIN_MTU (48)
#define L2CAP_MAX_MTU (0xFFFF)
#define L2CAP_DEFAULT_MTU (672)
//
// Max l2cap signal size (48) - size of signal header (4)
//
#define MAX_L2CAP_PING_DATA_LENGTH (44)
#define MAX_L2CAP_INFO_DATA_LENGTH (44)
//
// the following two structures provides information about
// disocvered remote radios.
//
#define BDIF_ADDRESS (0x00000001)
#define BDIF_COD (0x00000002)
#define BDIF_NAME (0x00000004)
#define BDIF_PAIRED (0x00000008)
#define BDIF_PERSONAL (0x00000010)
#define BDIF_CONNECTED (0x00000020)
#define BDIF_VALID_FLAGS \
(BDIF_ADDRESS | BDIF_COD | BDIF_NAME | BDIF_PAIRED | BDIF_PERSONAL | \
BDIF_CONNECTED)
typedef struct _BTH_DEVICE_INFO {
//
// Combination BDIF_Xxx flags
//
ULONG flags;
//
// Address of remote device.
//
BTH_ADDR address;
//
// Class Of Device.
//
BTH_COD classOfDevice;
//
// name of the device
//
CHAR name[BTH_MAX_NAME_SIZE];
} BTH_DEVICE_INFO, *PBTH_DEVICE_INFO;
//
// Buffer associated with GUID_BLUETOOTH_RADIO_IN_RANGE
//
typedef struct _BTH_RADIO_IN_RANGE {
//
// Information about the remote radio
//
BTH_DEVICE_INFO deviceInfo;
//
// The previous flags value for the BTH_DEVICE_INFO. The receiver of this
// notification can compare the deviceInfo.flags and previousDeviceFlags
// to determine what has changed about this remote radio.
//
// For instance, if BDIF_NAME is set in deviceInfo.flags and not in
// previousDeviceFlags, the remote radio's has just been retrieved.
//
ULONG previousDeviceFlags;
} BTH_RADIO_IN_RANGE, *PBTH_RADIO_IN_RANGE;
//
// Buffer associated with GUID_BLUETOOTH_L2CAP_EVENT
//
typedef struct _BTH_L2CAP_EVENT_INFO {
//
// Remote radio address which the L2CAP event is associated with
//
BTH_ADDR bthAddress;
//
// The PSM that is either being connected to or disconnected from
//
USHORT psm;
//
// If != 0, then the channel has just been established. If == 0, then the
// channel has been destroyed. Notifications for a destroyed channel will
// only be sent for channels successfully established.
//
UCHAR connected;
//
// If != 0, then the local host iniated the l2cap connection. If == 0, then
// the remote host initated the connection. This field is only valid if
// connect is != 0.
//
UCHAR initiated;
} BTH_L2CAP_EVENT_INFO, *PBTH_L2CAP_EVENT_INFO;
#define HCI_CONNNECTION_TYPE_ACL (1)
#define HCI_CONNNECTION_TYPE_SCO (2)
//
// Buffer associated with GUID_BLUETOOTH_HCI_EVENT
//
typedef struct _BTH_HCI_EVENT_INFO {
//
// Remote radio address which the HCI event is associated with
//
BTH_ADDR bthAddress;
//
// HCI_CONNNECTION_TYPE_XXX value
//
UCHAR connectionType;
//
// If != 0, then the underlying connection to the remote radio has just
// been estrablished. If == 0, then the underlying conneciton has just been
// destroyed.
//
UCHAR connected;
} BTH_HCI_EVENT_INFO, *PBTH_HCI_EVENT_INFO;
#define MAX_UUIDS_IN_QUERY (12)
#define BTH_VID_DEFAULT_VALUE (0xFFFF)
#define SDP_ERROR_INVALID_SDP_VERSION (0x0001)
#define SDP_ERROR_INVALID_RECORD_HANDLE (0x0002)
#define SDP_ERROR_INVALID_REQUEST_SYNTAX (0x0003)
#define SDP_ERROR_INVALID_PDU_SIZE (0x0004)
#define SDP_ERROR_INVALID_CONTINUATION_STATE (0x0005)
#define SDP_ERROR_INSUFFICIENT_RESOURCES (0x0006)
//
// Defined by windows to handle server errors that are not described by the
// above errors. Start at 0x0100 so we don't go anywhere near the spec
// defined values.
//
//
// Success, nothing went wrong
//
#define SDP_ERROR_SUCCESS ((SDP_ERROR) 0x0000)
//
// The SDP PDU or parameters other than the SDP stream response was not correct
//
#define SDP_ERROR_SERVER_INVALID_RESPONSE ((SDP_ERROR) 0x0100)
//
// The SDP response stream did not parse correctly.
//
#define SDP_ERROR_SERVER_RESPONSE_DID_NOT_PARSE ((SDP_ERROR) 0x0200)
//
// The SDP response stream was successfully parsed, but did not match the
// required format for the query.
//
#define SDP_ERROR_SERVER_BAD_FORMAT ((SDP_ERROR) 0x0300)
//
// SDP was unable to send a continued query back to the server
//
#define SDP_ERROR_COULD_NOT_SEND_CONTINUE ((SDP_ERROR) 0x0400)
//
// Server sent a response that was too large to fit in the caller's buffer.
//
#define SDP_ERROR_RESPONSE_TOO_LARGE ((SDP_ERROR) 0x0500)
#define SDP_ATTRIB_RECORD_HANDLE (0x0000)
#define SDP_ATTRIB_CLASS_ID_LIST (0x0001)
#define SDP_ATTRIB_RECORD_STATE (0x0002)
#define SDP_ATTRIB_SERVICE_ID (0x0003)
#define SDP_ATTRIB_PROTOCOL_DESCRIPTOR_LIST (0x0004)
#define SDP_ATTRIB_BROWSE_GROUP_LIST (0x0005)
#define SDP_ATTRIB_LANG_BASE_ATTRIB_ID_LIST (0x0006)
#define SDP_ATTRIB_INFO_TIME_TO_LIVE (0x0007)
#define SDP_ATTRIB_AVAILABILITY (0x0008)
#define SDP_ATTRIB_PROFILE_DESCRIPTOR_LIST (0x0009)
#define SDP_ATTRIB_DOCUMENTATION_URL (0x000A)
#define SDP_ATTRIB_CLIENT_EXECUTABLE_URL (0x000B)
#define SDP_ATTRIB_ICON_URL (0x000C)
#define SDP_ATTRIB_ADDITIONAL_PROTOCOL_DESCRIPTOR_LIST \
(0x000D)
//
// Attribute IDs in the range of 0x000D - 0x01FF are reserved for future use
//
#define SDP_ATTRIB_PROFILE_SPECIFIC (0x0200)
#define LANG_BASE_LANGUAGE_INDEX (0x0000)
#define LANG_BASE_ENCODING_INDEX (0x0001)
#define LANG_BASE_OFFSET_INDEX (0x0002)
#define LANG_DEFAULT_ID (0x0100)
#define STRING_NAME_OFFSET (0x0000)
#define STRING_DESCRIPTION_OFFSET (0x0001)
#define STRING_PROVIDER_NAME_OFFSET (0x0002)
#define SDP_ATTRIB_SDP_VERSION_NUMBER_LIST (0x0200)
#define SDP_ATTRIB_SDP_DATABASE_STATE (0x0201)
#define SDP_ATTRIB_BROWSE_GROUP_ID (0x0200)
#define SDP_ATTRIB_CORDLESS_EXTERNAL_NETWORK (0x0301)
#define SDP_ATTRIB_FAX_CLASS_1_SUPPORT (0x0302)
#define SDP_ATTRIB_FAX_CLASS_2_0_SUPPORT (0x0303)
#define SDP_ATTRIB_FAX_CLASS_2_SUPPORT (0x0304)
#define SDP_ATTRIB_FAX_AUDIO_FEEDBACK_SUPPORT (0x0305)
#define SDP_ATTRIB_HEADSET_REMOTE_AUDIO_VOLUME_CONTROL (0x0302)
#define SDP_ATTRIB_LAN_LPSUBNET (0x0200)
#define SDP_ATTRIB_OBJECT_PUSH_SUPPORTED_FORMATS_LIST (0x0303)
#define SDP_ATTRIB_SYNCH_SUPPORTED_DATA_STORES_LIST (0x0301)
// this is in the assigned numbers doc, but it does not show up in any profile
#define SDP_ATTRIB_SERVICE_VERSION (0x0300)
#define SDP_ATTRIB_PAN_NETWORK_ADDRESS (0x0306)
#define SDP_ATTRIB_PAN_WAP_GATEWAY (0x0307)
#define SDP_ATTRIB_PAN_HOME_PAGE_URL (0x0308)
#define SDP_ATTRIB_PAN_WAP_STACK_TYPE (0x0309)
#define SDP_ATTRIB_PAN_SECURITY_DESCRIPTION (0x030A)
#define SDP_ATTRIB_PAN_NET_ACCESS_TYPE (0x030B)
#define SDP_ATTRIB_PAN_MAX_NET_ACCESS_RATE (0x030C)
#define SDP_ATTRIB_IMAGING_SUPPORTED_CAPABILITIES (0x0310)
#define SDP_ATTRIB_IMAGING_SUPPORTED_FEATURES (0x0311)
#define SDP_ATTRIB_IMAGING_SUPPORTED_FUNCTIONS (0x0312)
#define SDP_ATTRIB_IMAGING_TOTAL_DATA_CAPACITY (0x0313)
#define SDP_ATTRIB_DI_SPECIFICATION_ID (0x0200)
#define SDP_ATTRIB_DI_VENDOR_ID (0x0201)
#define SDP_ATTRIB_DI_PRODUCT_ID (0x0202)
#define SDP_ATTRIB_DI_VERSION (0x0203)
#define SDP_ATTRIB_DI_PRIMARY_RECORD (0x0204)
#define SDP_ATTRIB_DI_VENDOR_ID_SOURCE (0x0205)
#define SDP_ATTRIB_HID_DEVICE_RELEASE_NUMBER (0x0200)
#define SDP_ATTRIB_HID_PARSER_VERSION (0x0201)
#define SDP_ATTRIB_HID_DEVICE_SUBCLASS (0x0202)
#define SDP_ATTRIB_HID_COUNTRY_CODE (0x0203)
#define SDP_ATTRIB_HID_VIRTUAL_CABLE (0x0204)
#define SDP_ATTRIB_HID_RECONNECT_INITIATE (0x0205)
#define SDP_ATTRIB_HID_DESCRIPTOR_LIST (0x0206)
#define SDP_ATTRIB_HID_LANG_ID_BASE_LIST (0x0207)
#define SDP_ATTRIB_HID_SDP_DISABLE (0x0208)
#define SDP_ATTRIB_HID_BATTERY_POWER (0x0209)
#define SDP_ATTRIB_HID_REMOTE_WAKE (0x020A)
#define SDP_ATTRIB_HID_REPORT_LIST (0x020B)
#define SDP_ATTRIB_HID_SUPERVISION_TIMEOUT (0x020C)
#define SDP_ATTRIB_HID_NORMALLY_CONNECTABLE (0x020D)
#define SDP_ATTRIB_HID_BOOT_DEVICE (0x020E)
//
// Profile specific values
//
#define CORDLESS_EXTERNAL_NETWORK_PSTN (0x01)
#define CORDLESS_EXTERNAL_NETWORK_ISDN (0x02)
#define CORDLESS_EXTERNAL_NETWORK_GSM (0x03)
#define CORDLESS_EXTERNAL_NETWORK_CDMA (0x04)
#define CORDLESS_EXTERNAL_NETWORK_ANALOG_CELLULAR (0x05)
#define CORDLESS_EXTERNAL_NETWORK_PACKET_SWITCHED (0x06)
#define CORDLESS_EXTERNAL_NETWORK_OTHER (0x07)
#define OBJECT_PUSH_FORMAT_VCARD_2_1 (0x01)
#define OBJECT_PUSH_FORMAT_VCARD_3_0 (0x02)
#define OBJECT_PUSH_FORMAT_VCAL_1_0 (0x03)
#define OBJECT_PUSH_FORMAT_ICAL_2_0 (0x04)
#define OBJECT_PUSH_FORMAT_VNOTE (0x05)
#define OBJECT_PUSH_FORMAT_VMESSAGE (0x06)
#define OBJECT_PUSH_FORMAT_ANY (0xFF)
#define SYNCH_DATA_STORE_PHONEBOOK (0x01)
#define SYNCH_DATA_STORE_CALENDAR (0x03)
#define SYNCH_DATA_STORE_NOTES (0x05)
#define SYNCH_DATA_STORE_MESSAGES (0x06)
#define DI_VENDOR_ID_SOURCE_BLUETOOTH_SIG (0x0001)
#define DI_VENDOR_ID_SOURCE_USB_IF (0x0002)
#define PSM_SDP (0x0001)
#define PSM_RFCOMM (0x0003)
#define PSM_TCS_BIN (0x0005)
#define PSM_TCS_BIN_CORDLESS (0x0007)
#define PSM_BNEP (0x000F)
#define PSM_HID_CONTROL (0x0011)
#define PSM_HID_INTERRUPT (0x0013)
#define PSM_AVCTP (0x0017)
#define PSM_AVDTP (0x0019)
#define PSM_UDI_C_PLANE (0x001D)
//
// Strings
//
#define STR_ADDR_FMTA "(%02x:%02x:%02x:%02x:%02x:%02x)"
#define STR_ADDR_FMTW L"(%02x:%02x:%02x:%02x:%02x:%02x)"
#define STR_ADDR_SHORT_FMTA "%04x%08x"
#define STR_ADDR_SHORT_FMTW L"%04x%08x"
#if defined(UNICODE) || defined(BTH_KERN)
#define STR_ADDR_FMT STR_ADDR_FMTW
#define STR_ADDR_SHORT_FMT STR_ADDR_SHORT_FMTW
#else // UNICODE
#define STR_ADDR_FMT STR_ADDR_FMTA
#define STR_ADDR_SHORT_FMT STR_ADDR_SHORT_FMTA
#endif // UNICODE
#define GET_BITS(field,offset,mask) ( ( (field) >> (offset) ) & (mask) )
#define GET_BIT(field,offset) ( GET_BITS(field,offset,0x1) )
#define LMP_3_SLOT_PACKETS(x) (GET_BIT(x, 0))
#define LMP_5_SLOT_PACKETS(x) (GET_BIT(x, 1))
#define LMP_ENCRYPTION(x) (GET_BIT(x, 2))
#define LMP_SLOT_OFFSET(x) (GET_BIT(x, 3))
#define LMP_TIMING_ACCURACY(x) (GET_BIT(x, 4))
#define LMP_SWITCH(x) (GET_BIT(x, 5))
#define LMP_HOLD_MODE(x) (GET_BIT(x, 6))
#define LMP_SNIFF_MODE(x) (GET_BIT(x, 7))
#define LMP_PARK_MODE(x) (GET_BIT(x, 8))
#define LMP_RSSI(x) (GET_BIT(x, 9))
#define LMP_CHANNEL_QUALITY_DRIVEN_MODE(x) (GET_BIT(x,10))
#define LMP_SCO_LINK(x) (GET_BIT(x,11))
#define LMP_HV2_PACKETS(x) (GET_BIT(x,12))
#define LMP_HV3_PACKETS(x) (GET_BIT(x,13))
#define LMP_MU_LAW_LOG(x) (GET_BIT(x,14))
#define LMP_A_LAW_LOG(x) (GET_BIT(x,15))
#define LMP_CVSD(x) (GET_BIT(x,16))
#define LMP_PAGING_SCHEME(x) (GET_BIT(x,17))
#define LMP_POWER_CONTROL(x) (GET_BIT(x,18))
#define LMP_TRANSPARENT_SCO_DATA(x) (GET_BIT(x,19))
#define LMP_FLOW_CONTROL_LAG(x) (GET_BITS(x,20,0x3))
#endif // GUID_DEFS_ONLY
#endif // __BTHDEF_H__

View File

@@ -1,111 +0,0 @@
#ifndef __BTHSDPDEF_H__
#define __BTHSDPDEF_H__
#ifdef __cplusplus
extern "C" {
#endif
struct SDP_LARGE_INTEGER_16 {
ULONGLONG LowPart;
LONGLONG HighPart;
};
struct SDP_ULARGE_INTEGER_16 {
ULONGLONG LowPart;
ULONGLONG HighPart;
};
typedef struct SDP_ULARGE_INTEGER_16 SDP_ULARGE_INTEGER_16, *PSDP_ULARGE_INTEGER_16, *LPSDP_ULARGE_INTEGER_16;
typedef struct SDP_LARGE_INTEGER_16 SDP_LARGE_INTEGER_16, *PSDP_LARGE_INTEGER_16, *LPSDP_LARGE_INTEGER_16;
enum NodeContainerType {
NodeContainerTypeSequence,
NodeContainerTypeAlternative
};
typedef enum NodeContainerType NodeContainerType;
typedef USHORT SDP_ERROR, *PSDP_ERROR;
enum SDP_TYPE {
SDP_TYPE_NIL = 0x00,
SDP_TYPE_UINT = 0x01,
SDP_TYPE_INT = 0x02,
SDP_TYPE_UUID = 0x03,
SDP_TYPE_STRING = 0x04,
SDP_TYPE_BOOLEAN = 0x05,
SDP_TYPE_SEQUENCE = 0x06,
SDP_TYPE_ALTERNATIVE = 0x07,
SDP_TYPE_URL = 0x08,
SDP_TYPE_CONTAINER = 0x20
};
// 9 - 31 are reserved
typedef enum SDP_TYPE SDP_TYPE;
// allow for a little easier type checking / sizing for integers and UUIDs
// ((SDP_ST_XXX & 0xF0) >> 4) == SDP_TYPE_XXX
// size of the data (in bytes) is encoded as ((SDP_ST_XXX & 0xF0) >> 8)
enum SDP_SPECIFICTYPE {
SDP_ST_NONE = 0x0000,
SDP_ST_UINT8 = 0x0010,
SDP_ST_UINT16 = 0x0110,
SDP_ST_UINT32 = 0x0210,
SDP_ST_UINT64 = 0x0310,
SDP_ST_UINT128 = 0x0410,
SDP_ST_INT8 = 0x0020,
SDP_ST_INT16 = 0x0120,
SDP_ST_INT32 = 0x0220,
SDP_ST_INT64 = 0x0320,
SDP_ST_INT128 = 0x0420,
SDP_ST_UUID16 = 0x0130,
SDP_ST_UUID32 = 0x0220,
SDP_ST_UUID128 = 0x0430
};
typedef enum SDP_SPECIFICTYPE SDP_SPECIFICTYPE;
typedef struct _SdpAttributeRange {
USHORT minAttribute;
USHORT maxAttribute;
} SdpAttributeRange;
typedef
#ifdef USE_MIDL_SYNTAX
[switch_type(unsigned short)]
#endif
union SdpQueryUuidUnion {
#ifdef USE_MIDL_SYNTAX
[case(SDP_ST_UUID128)]
#endif
GUID uuid128;
#ifdef USE_MIDL_SYNTAX
[case(SDP_ST_UUID32)]
#endif _NTDDK_
ULONG uuid32;
#ifdef USE_MIDL_SYNTAX
[case(SDP_ST_UUID16)]
#endif _NTDDK_
USHORT uuid16;
} SdpQueryUuidUnion;
typedef struct _SdpQueryUuid {
#ifdef USE_MIDL_SYNTAX
[switch_is(uuidType)]
#endif
SdpQueryUuidUnion u;
USHORT uuidType;
} SdpQueryUuid;
#ifdef __cplusplus
};
#endif
#endif // __BTHSDPDEF_H__

View File

@@ -1,710 +0,0 @@
/*
* wiiuse
*
* Written By:
* Michael Laforest < para >
* Email: < thepara (--AT--) g m a i l [--DOT--] com >
*
* Copyright 2006-2007
*
* This file is part of wiiuse.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* $Header$
*
*/
/**
* @file
*
* @brief API header file.
*
* If this file is included from inside the wiiuse source
* and not from a third party program, then wiimote_internal.h
* is also included which extends this file.
*/
#ifndef WIIUSE_H_INCLUDED
#define WIIUSE_H_INCLUDED
#ifdef _WIN32
/* windows */
#include <windows.h>
#else
/* nix */
#include <bluetooth/bluetooth.h>
#endif
#ifdef WIIUSE_INTERNAL_H_INCLUDED
#define WCONST
#else
#define WCONST const
#endif
/* led bit masks */
#define WIIMOTE_LED_NONE 0x00
#define WIIMOTE_LED_1 0x10
#define WIIMOTE_LED_2 0x20
#define WIIMOTE_LED_3 0x40
#define WIIMOTE_LED_4 0x80
/* button codes */
#define WIIMOTE_BUTTON_TWO 0x0001
#define WIIMOTE_BUTTON_ONE 0x0002
#define WIIMOTE_BUTTON_B 0x0004
#define WIIMOTE_BUTTON_A 0x0008
#define WIIMOTE_BUTTON_MINUS 0x0010
#define WIIMOTE_BUTTON_ZACCEL_BIT6 0x0020
#define WIIMOTE_BUTTON_ZACCEL_BIT7 0x0040
#define WIIMOTE_BUTTON_HOME 0x0080
#define WIIMOTE_BUTTON_LEFT 0x0100
#define WIIMOTE_BUTTON_RIGHT 0x0200
#define WIIMOTE_BUTTON_DOWN 0x0400
#define WIIMOTE_BUTTON_UP 0x0800
#define WIIMOTE_BUTTON_PLUS 0x1000
#define WIIMOTE_BUTTON_ZACCEL_BIT4 0x2000
#define WIIMOTE_BUTTON_ZACCEL_BIT5 0x4000
#define WIIMOTE_BUTTON_UNKNOWN 0x8000
#define WIIMOTE_BUTTON_ALL 0x1F9F
/* nunchul button codes */
#define NUNCHUK_BUTTON_Z 0x01
#define NUNCHUK_BUTTON_C 0x02
#define NUNCHUK_BUTTON_ALL 0x03
/* classic controller button codes */
#define CLASSIC_CTRL_BUTTON_UP 0x0001
#define CLASSIC_CTRL_BUTTON_LEFT 0x0002
#define CLASSIC_CTRL_BUTTON_ZR 0x0004
#define CLASSIC_CTRL_BUTTON_X 0x0008
#define CLASSIC_CTRL_BUTTON_A 0x0010
#define CLASSIC_CTRL_BUTTON_Y 0x0020
#define CLASSIC_CTRL_BUTTON_B 0x0040
#define CLASSIC_CTRL_BUTTON_ZL 0x0080
#define CLASSIC_CTRL_BUTTON_FULL_R 0x0200
#define CLASSIC_CTRL_BUTTON_PLUS 0x0400
#define CLASSIC_CTRL_BUTTON_HOME 0x0800
#define CLASSIC_CTRL_BUTTON_MINUS 0x1000
#define CLASSIC_CTRL_BUTTON_FULL_L 0x2000
#define CLASSIC_CTRL_BUTTON_DOWN 0x4000
#define CLASSIC_CTRL_BUTTON_RIGHT 0x8000
#define CLASSIC_CTRL_BUTTON_ALL 0xFEFF
/* guitar hero 3 button codes */
#define GUITAR_HERO_3_BUTTON_STRUM_UP 0x0001
#define GUITAR_HERO_3_BUTTON_YELLOW 0x0008
#define GUITAR_HERO_3_BUTTON_GREEN 0x0010
#define GUITAR_HERO_3_BUTTON_BLUE 0x0020
#define GUITAR_HERO_3_BUTTON_RED 0x0040
#define GUITAR_HERO_3_BUTTON_ORANGE 0x0080
#define GUITAR_HERO_3_BUTTON_PLUS 0x0400
#define GUITAR_HERO_3_BUTTON_MINUS 0x1000
#define GUITAR_HERO_3_BUTTON_STRUM_DOWN 0x4000
#define GUITAR_HERO_3_BUTTON_ALL 0xFEFF
/* wiimote option flags */
#define WIIUSE_SMOOTHING 0x01
#define WIIUSE_CONTINUOUS 0x02
#define WIIUSE_ORIENT_THRESH 0x04
#define WIIUSE_INIT_FLAGS (WIIUSE_SMOOTHING | WIIUSE_ORIENT_THRESH)
#define WIIUSE_ORIENT_PRECISION 100.0f
/* expansion codes */
#define EXP_NONE 0
#define EXP_NUNCHUK 1
#define EXP_CLASSIC 2
#define EXP_GUITAR_HERO_3 3
#define EXP_BALANCE_BOARD 4
/* IR correction types */
typedef enum ir_position_t {
WIIUSE_IR_ABOVE,
WIIUSE_IR_BELOW
} ir_position_t;
/**
* @brief Check if a button is pressed.
* @param dev Pointer to a wiimote_t or expansion structure.
* @param button The button you are interested in.
* @return 1 if the button is pressed, 0 if not.
*/
#define IS_PRESSED(dev, button) ((dev->btns & button) == button)
/**
* @brief Check if a button is being held.
* @param dev Pointer to a wiimote_t or expansion structure.
* @param button The button you are interested in.
* @return 1 if the button is held, 0 if not.
*/
#define IS_HELD(dev, button) ((dev->btns_held & button) == button)
/**
* @brief Check if a button is released on this event. \n\n
* This does not mean the button is not pressed, it means \n
* this button was just now released.
* @param dev Pointer to a wiimote_t or expansion structure.
* @param button The button you are interested in.
* @return 1 if the button is released, 0 if not.
*
*/
#define IS_RELEASED(dev, button) ((dev->btns_released & button) == button)
/**
* @brief Check if a button has just been pressed this event.
* @param dev Pointer to a wiimote_t or expansion structure.
* @param button The button you are interested in.
* @return 1 if the button is pressed, 0 if not.
*/
#define IS_JUST_PRESSED(dev, button) (IS_PRESSED(dev, button) && !IS_HELD(dev, button))
/**
* @brief Return the IR sensitivity level.
* @param wm Pointer to a wiimote_t structure.
* @param lvl [out] Pointer to an int that will hold the level setting.
* If no level is set 'lvl' will be set to 0.
*/
#define WIIUSE_GET_IR_SENSITIVITY(dev, lvl) \
do { \
if ((wm->state & 0x0200) == 0x0200) *lvl = 1; \
else if ((wm->state & 0x0400) == 0x0400) *lvl = 2; \
else if ((wm->state & 0x0800) == 0x0800) *lvl = 3; \
else if ((wm->state & 0x1000) == 0x1000) *lvl = 4; \
else if ((wm->state & 0x2000) == 0x2000) *lvl = 5; \
else *lvl = 0; \
} while (0)
#define WIIUSE_USING_ACC(wm) ((wm->state & 0x020) == 0x020)
#define WIIUSE_USING_EXP(wm) ((wm->state & 0x040) == 0x040)
#define WIIUSE_USING_IR(wm) ((wm->state & 0x080) == 0x080)
#define WIIUSE_USING_SPEAKER(wm) ((wm->state & 0x100) == 0x100)
#define WIIUSE_IS_LED_SET(wm, num) ((wm->leds & WIIMOTE_LED_##num) == WIIMOTE_LED_##num)
/*
* Largest known payload is 21 bytes.
* Add 2 for the prefix and round up to a power of 2.
*/
#define MAX_PAYLOAD 32
/*
* This is left over from an old hack, but it may actually
* be a useful feature to keep so it wasn't removed.
*/
#ifdef WIN32
#define WIIMOTE_DEFAULT_TIMEOUT 10
#define WIIMOTE_EXP_TIMEOUT 10
#endif
typedef unsigned char byte;
typedef char sbyte;
struct wiimote_t;
struct vec3b_t;
struct orient_t;
struct gforce_t;
/**
* @brief Callback that handles a read event.
*
* @param wm Pointer to a wiimote_t structure.
* @param data Pointer to the filled data block.
* @param len Length in bytes of the data block.
*
* @see wiiuse_init()
*
* A registered function of this type is called automatically by the wiiuse
* library when the wiimote has returned the full data requested by a previous
* call to wiiuse_read_data().
*/
typedef void (*wiiuse_read_cb)(struct wiimote_t* wm, byte* data, unsigned short len);
/**
* @struct read_req_t
* @brief Data read request structure.
*/
struct read_req_t {
wiiuse_read_cb cb; /**< read data callback */
byte* buf; /**< buffer where read data is written */
unsigned int addr; /**< the offset that the read started at */
unsigned short size; /**< the length of the data read */
unsigned short wait; /**< num bytes still needed to finish read */
byte dirty; /**< set to 1 if not using callback and needs to be cleaned up */
struct read_req_t* next; /**< next read request in the queue */
};
/**
* @struct vec2b_t
* @brief Unsigned x,y byte vector.
*/
typedef struct vec2b_t {
byte x, y;
} vec2b_t;
/**
* @struct vec3b_t
* @brief Unsigned x,y,z byte vector.
*/
typedef struct vec3b_t {
byte x, y, z;
} vec3b_t;
/**
* @struct vec3f_t
* @brief Signed x,y,z float struct.
*/
typedef struct vec3f_t {
float x, y, z;
} vec3f_t;
/**
* @struct orient_t
* @brief Orientation struct.
*
* Yaw, pitch, and roll range from -180 to 180 degrees.
*/
typedef struct orient_t {
float roll; /**< roll, this may be smoothed if enabled */
float pitch; /**< pitch, this may be smoothed if enabled */
float yaw;
float a_roll; /**< absolute roll, unsmoothed */
float a_pitch; /**< absolute pitch, unsmoothed */
} orient_t;
/**
* @struct gforce_t
* @brief Gravity force struct.
*/
typedef struct gforce_t {
float x, y, z;
} gforce_t;
/**
* @struct accel_t
* @brief Accelerometer struct. For any device with an accelerometer.
*/
typedef struct accel_t {
struct vec3b_t cal_zero; /**< zero calibration */
struct vec3b_t cal_g; /**< 1g difference around 0cal */
float st_roll; /**< last smoothed roll value */
float st_pitch; /**< last smoothed roll pitch */
float st_alpha; /**< alpha value for smoothing [0-1] */
} accel_t;
/**
* @struct ir_dot_t
* @brief A single IR source.
*/
typedef struct ir_dot_t {
byte visible; /**< if the IR source is visible */
unsigned int x; /**< interpolated X coordinate */
unsigned int y; /**< interpolated Y coordinate */
short rx; /**< raw X coordinate (0-1023) */
short ry; /**< raw Y coordinate (0-767) */
byte order; /**< increasing order by x-axis value */
byte size; /**< size of the IR dot (0-15) */
} ir_dot_t;
/**
* @enum aspect_t
* @brief Screen aspect ratio.
*/
typedef enum aspect_t {
WIIUSE_ASPECT_4_3,
WIIUSE_ASPECT_16_9
} aspect_t;
/**
* @struct ir_t
* @brief IR struct. Hold all data related to the IR tracking.
*/
typedef struct ir_t {
struct ir_dot_t dot[4]; /**< IR dots */
byte num_dots; /**< number of dots at this time */
enum aspect_t aspect; /**< aspect ratio of the screen */
enum ir_position_t pos; /**< IR sensor bar position */
unsigned int vres[2]; /**< IR virtual screen resolution */
int offset[2]; /**< IR XY correction offset */
int state; /**< keeps track of the IR state */
int ax; /**< absolute X coordinate */
int ay; /**< absolute Y coordinate */
int x; /**< calculated X coordinate */
int y; /**< calculated Y coordinate */
float distance; /**< pixel distance between first 2 dots*/
float z; /**< calculated distance */
} ir_t;
/**
* @struct speaker_t
*/
typedef struct speaker_t {
byte format;
byte rate;
byte freq;
byte vol;
} speaker_t;
/**
* @struct joystick_t
* @brief Joystick calibration structure.
*
* The angle \a ang is relative to the positive y-axis into quadrant I
* and ranges from 0 to 360 degrees. So if the joystick is held straight
* upwards then angle is 0 degrees. If it is held to the right it is 90,
* down is 180, and left is 270.
*
* The magnitude \a mag is the distance from the center to where the
* joystick is being held. The magnitude ranges from 0 to 1.
* If the joystick is only slightly tilted from the center the magnitude
* will be low, but if it is closer to the outter edge the value will
* be higher.
*/
typedef struct joystick_t {
struct vec2b_t max; /**< maximum joystick values */
struct vec2b_t min; /**< minimum joystick values */
struct vec2b_t center; /**< center joystick values */
float ang; /**< angle the joystick is being held */
float mag; /**< magnitude of the joystick (range 0-1) */
} joystick_t;
/**
* @struct nunchuk_t
* @brief Nunchuk expansion device.
*/
typedef struct nunchuk_t {
struct accel_t accel_calib; /**< nunchuk accelerometer calibration */
struct joystick_t js; /**< joystick calibration */
int* flags; /**< options flag (points to wiimote_t.flags) */
byte btns; /**< what buttons have just been pressed */
byte btns_held; /**< what buttons are being held down */
byte btns_released; /**< what buttons were just released this */
float orient_threshold; /**< threshold for orient to generate an event */
int accel_threshold; /**< threshold for accel to generate an event */
struct vec3b_t accel; /**< current raw acceleration data */
struct orient_t orient; /**< current orientation on each axis */
struct gforce_t gforce; /**< current gravity forces on each axis */
} nunchuk_t;
/**
* @struct classic_ctrl_t
* @brief Classic controller expansion device.
*/
typedef struct classic_ctrl_t {
short btns; /**< what buttons have just been pressed */
short btns_held; /**< what buttons are being held down */
short btns_released; /**< what buttons were just released this */
float r_shoulder; /**< right shoulder button (range 0-1) */
float l_shoulder; /**< left shoulder button (range 0-1) */
struct joystick_t ljs; /**< left joystick calibration */
struct joystick_t rjs; /**< right joystick calibration */
} classic_ctrl_t;
/**
* @struct guitar_hero_3_t
* @brief Guitar Hero 3 expansion device.
*/
typedef struct guitar_hero_3_t {
short btns; /**< what buttons have just been pressed */
short btns_held; /**< what buttons are being held down */
short btns_released; /**< what buttons were just released this */
float whammy_bar; /**< whammy bar (range 0-1) */
struct joystick_t js; /**< joystick calibration */
} guitar_hero_3_t;
/**
* @struct balance_board_data_t
* @brief Balance board l/r, t/b corner data data.
*/
typedef struct balance_board_data_t {
int tr;
int br;
int tl;
int bl;
} balance_board_data_t;
/**
* @struct balance_board_t
* @brief Balance board expansion device.
*/
typedef struct balance_board_t {
float tr; /** Top Right weight */
float br; /** Bottom Right weight */
float tl; /** Top Left weight */
float bl; /** Bottom Left weight */
struct balance_board_data_t raw; /** Raw actual values */
struct balance_board_data_t cal_0; /** Calibration values at 0kg */
struct balance_board_data_t cal_17; /** Calibration values at 17kg */
struct balance_board_data_t cal_34; /** Calibration values at 34kg */
} balance_board_t;
/**
* @struct expansion_t
* @brief Generic expansion device plugged into wiimote.
*/
typedef struct expansion_t {
int type; /**< type of expansion attached */
union {
struct nunchuk_t nunchuk;
struct classic_ctrl_t classic;
struct guitar_hero_3_t gh3;
struct balance_board_t bb;
};
} expansion_t;
/**
* @enum win32_bt_stack_t
* @brief Available bluetooth stacks for Windows.
*/
typedef enum win_bt_stack_t {
WIIUSE_STACK_UNKNOWN,
WIIUSE_STACK_MS,
WIIUSE_STACK_BLUESOLEIL
} win_bt_stack_t;
/**
* @struct wiimote_state_t
* @brief Significant data from the previous event.
*/
typedef struct wiimote_state_t {
/* expansion_t */
float exp_ljs_ang;
float exp_rjs_ang;
float exp_ljs_mag;
float exp_rjs_mag;
unsigned short exp_btns;
struct orient_t exp_orient;
struct vec3b_t exp_accel;
float exp_r_shoulder;
float exp_l_shoulder;
struct balance_board_data_t exp_bb_raw;
/* ir_t */
int ir_ax;
int ir_ay;
float ir_distance;
struct orient_t orient;
unsigned short btns;
struct vec3b_t accel;
} wiimote_state_t;
/**
* @enum WIIUSE_EVENT_TYPE
* @brief Events that wiiuse can generate from a poll.
*/
typedef enum WIIUSE_EVENT_TYPE {
WIIUSE_NONE = 0,
WIIUSE_EVENT,
WIIUSE_STATUS,
WIIUSE_CONNECT,
WIIUSE_DISCONNECT,
WIIUSE_UNEXPECTED_DISCONNECT,
WIIUSE_READ_DATA,
WIIUSE_NUNCHUK_INSERTED,
WIIUSE_NUNCHUK_REMOVED,
WIIUSE_CLASSIC_CTRL_INSERTED,
WIIUSE_CLASSIC_CTRL_REMOVED,
WIIUSE_GUITAR_HERO_3_CTRL_INSERTED,
WIIUSE_GUITAR_HERO_3_CTRL_REMOVED,
WIIUSE_BALANCE_BOARD_CTRL_INSERTED,
WIIUSE_BALANCE_BOARD_CTRL_REMOVED
} WIIUSE_EVENT_TYPE;
/**
* @struct wiimote_t
* @brief Wiimote structure.
*/
typedef struct wiimote_t {
WCONST int unid; /**< user specified id */
#ifndef WIN32
WCONST bdaddr_t bdaddr; /**< bt address */
WCONST char bdaddr_str[18]; /**< readable bt address */
WCONST int out_sock; /**< output socket */
WCONST int in_sock; /**< input socket */
#else
WCONST HANDLE dev_handle; /**< HID handle */
WCONST OVERLAPPED hid_overlap; /**< overlap handle */
WCONST enum win_bt_stack_t stack; /**< type of bluetooth stack to use */
WCONST int timeout; /**< read timeout */
WCONST byte normal_timeout; /**< normal timeout */
WCONST byte exp_timeout; /**< timeout for expansion handshake */
#endif
WCONST int state; /**< various state flags */
WCONST byte leds; /**< currently lit leds */
WCONST float battery_level; /**< battery level */
WCONST int flags; /**< options flag */
WCONST byte handshake_state; /**< the state of the connection handshake */
WCONST struct read_req_t* read_req; /**< list of data read requests */
WCONST struct accel_t accel_calib; /**< wiimote accelerometer calibration */
WCONST struct expansion_t exp; /**< wiimote expansion device */
WCONST struct vec3b_t accel; /**< current raw acceleration data */
WCONST struct orient_t orient; /**< current orientation on each axis */
WCONST struct gforce_t gforce; /**< current gravity forces on each axis */
WCONST struct ir_t ir; /**< IR data */
WCONST struct speaker_t speaker; /**< speaker */
WCONST unsigned short btns; /**< what buttons have just been pressed */
WCONST unsigned short btns_held; /**< what buttons are being held down */
WCONST unsigned short btns_released; /**< what buttons were just released this */
WCONST float orient_threshold; /**< threshold for orient to generate an event */
WCONST int accel_threshold; /**< threshold for accel to generate an event */
WCONST struct wiimote_state_t lstate; /**< last saved state */
WCONST WIIUSE_EVENT_TYPE event; /**< type of event that occured */
WCONST byte event_buf[MAX_PAYLOAD]; /**< event buffer */
} wiimote;
/*****************************************
*
* Include API specific stuff
*
*****************************************/
#ifdef _WIN32
#define WIIUSE_EXPORT_DECL __declspec(dllexport)
#define WIIUSE_IMPORT_DECL __declspec(dllimport)
#else
#define WIIUSE_EXPORT_DECL
#define WIIUSE_IMPORT_DECL
#endif
#ifdef WIIUSE_COMPILE_LIB
#define WIIUSE_EXPORT WIIUSE_EXPORT_DECL
#else
#define WIIUSE_EXPORT WIIUSE_IMPORT_DECL
#endif
#ifdef __cplusplus
extern "C" {
#endif
/* wiiuse.c */
WIIUSE_EXPORT extern const char* wiiuse_version();
WIIUSE_EXPORT extern struct wiimote_t** wiiuse_init(int wiimotes);
WIIUSE_EXPORT extern void wiiuse_disconnected(struct wiimote_t* wm);
WIIUSE_EXPORT extern void wiiuse_cleanup(struct wiimote_t** wm, int wiimotes);
WIIUSE_EXPORT extern void wiiuse_rumble(struct wiimote_t* wm, int status);
WIIUSE_EXPORT extern void wiiuse_toggle_rumble(struct wiimote_t* wm);
WIIUSE_EXPORT extern void wiiuse_set_leds(struct wiimote_t* wm, int leds);
WIIUSE_EXPORT extern void wiiuse_motion_sensing(struct wiimote_t* wm, int status);
WIIUSE_EXPORT extern int wiiuse_read_data(struct wiimote_t* wm, byte* buffer, unsigned int offset, unsigned short len);
WIIUSE_EXPORT extern int wiiuse_write_data(struct wiimote_t* wm, unsigned int addr, byte* data, byte len);
WIIUSE_EXPORT extern void wiiuse_status(struct wiimote_t* wm);
WIIUSE_EXPORT extern struct wiimote_t* wiiuse_get_by_id(struct wiimote_t** wm, int wiimotes, int unid);
WIIUSE_EXPORT extern int wiiuse_set_flags(struct wiimote_t* wm, int enable, int disable);
WIIUSE_EXPORT extern float wiiuse_set_smooth_alpha(struct wiimote_t* wm, float alpha);
WIIUSE_EXPORT extern void wiiuse_set_bluetooth_stack(struct wiimote_t** wm, int wiimotes, enum win_bt_stack_t type);
WIIUSE_EXPORT extern void wiiuse_set_orient_threshold(struct wiimote_t* wm, float threshold);
WIIUSE_EXPORT extern void wiiuse_resync(struct wiimote_t* wm);
WIIUSE_EXPORT extern void wiiuse_set_timeout(struct wiimote_t** wm, int wiimotes, byte normal_timeout, byte exp_timeout);
WIIUSE_EXPORT extern void wiiuse_set_accel_threshold(struct wiimote_t* wm, int threshold);
/* connect.c */
WIIUSE_EXPORT extern int wiiuse_find(struct wiimote_t** wm, int max_wiimotes, int timeout);
WIIUSE_EXPORT extern int wiiuse_connect(struct wiimote_t** wm, int wiimotes);
WIIUSE_EXPORT extern void wiiuse_disconnect(struct wiimote_t* wm);
/* events.c */
WIIUSE_EXPORT extern int wiiuse_poll(struct wiimote_t** wm, int wiimotes);
/* ir.c */
WIIUSE_EXPORT extern void wiiuse_set_ir(struct wiimote_t* wm, int status);
WIIUSE_EXPORT extern void wiiuse_set_ir_vres(struct wiimote_t* wm, unsigned int x, unsigned int y);
WIIUSE_EXPORT extern void wiiuse_set_ir_position(struct wiimote_t* wm, enum ir_position_t pos);
WIIUSE_EXPORT extern void wiiuse_set_aspect_ratio(struct wiimote_t* wm, enum aspect_t aspect);
WIIUSE_EXPORT extern void wiiuse_set_ir_sensitivity(struct wiimote_t* wm, int level);
/* nunchuk.c */
WIIUSE_EXPORT extern void wiiuse_set_nunchuk_orient_threshold(struct wiimote_t* wm, float threshold);
WIIUSE_EXPORT extern void wiiuse_set_nunchuk_accel_threshold(struct wiimote_t* wm, int threshold);
/* speaker.c */
WIIUSE_EXPORT extern void wiiuse_speaker_enable(struct wiimote_t* wm);
WIIUSE_EXPORT extern void wiiuse_speaker_disable(struct wiimote_t* wm);
WIIUSE_EXPORT extern void wiiuse_speaker_mute(struct wiimote_t* wm);
WIIUSE_EXPORT extern void wiiuse_speaker_unmute(struct wiimote_t* wm);
WIIUSE_EXPORT extern void wiiuse_speaker_activate(struct wiimote_t* wm);
WIIUSE_EXPORT extern void wiiuse_speaker_deactivate(struct wiimote_t* wm);
WIIUSE_EXPORT extern void wiiuse_speaker_format(struct wiimote_t* wm, byte format);
WIIUSE_EXPORT extern void wiiuse_speaker_volume(struct wiimote_t* wm, double vol);
WIIUSE_EXPORT extern void wiiuse_speaker_rate(struct wiimote_t* wm, byte rate, byte freq);
WIIUSE_EXPORT extern void wiiuse_speaker_config(struct wiimote_t* wm);
WIIUSE_EXPORT extern void wiiuse_speaker_data(struct wiimote_t* wm, byte* data, int len);
#ifdef __cplusplus
}
#endif
#endif /* WIIUSE_H_INCLUDED */

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@@ -1,143 +0,0 @@
// The code is copyrighted 2008 by Carsten Frigaard.
// All rights placed in public domain under GNU licence V2, 2008
//
// © 2008 Carsten Frigaard. Permission to use, copy, modify, and distribute this software
// and its documentation for any purpose and without fee is hereby granted, provided that
// the above copyright notice appear in all copies and that both that copyright notice
// and this permission notice appear in supporting documentation.
#ifndef __ARGS_H__
#define __ARGS_H__
class args{
private:
typedef vector<string> t_args;
t_args m_args;
void Remove(t_args::iterator itt1,int n)
{
t_args args2;
for(t_args::iterator itt2=m_args.begin();itt2!=m_args.end();++itt2) {
if(itt2!=itt1) args2.push_back(*itt2);
else {if (--n>0) ++itt1;}
}
m_args=args2;
}
t_args::iterator Find(const string& v)
{
for(t_args::iterator itt=m_args.begin();itt!=m_args.end();++itt) {
if (v==*itt) return itt;
}
return m_args.end();
}
t_args::const_iterator Find(const string& v) const
{
for(t_args::const_iterator itt=m_args.begin();itt!=m_args.end();++itt) {
if (v==*itt) return itt;
}
return m_args.end();
}
public:
args(const int argc,char **argv,const bool printargs=false)
{
for(int i=0;i<argc;++i) {m_args.push_back(argv[i]);}
if (printargs) cout << "% Call args: " << *this << endl;
}
string operator[](const size_t i) const
{
if(i>=size()) throw_("argument[] out of range");
return m_args[i];
}
size_t size() const {return m_args.size();}
bool hasopt(const string& tag) const {return Find(tag)!=m_args.end();}
template<class T> T Totype(const size_t i) const {return totype<T>((*this)[i]);}
template<class T> T Tounit(const size_t i) const {
const string& s=(*this)[i+1];
#ifndef USE_UNITS
// fake test of units, primitive test, must be one-of: kpc, per_kpc and msun1E10
if (s!="kpc/h" && s!="h/kpc" && s!="msun1E10/h") throw_("bad unit=<" + s + ">, can only handle units of type: kpc/h, h/kpc, and msun1E10/h");
#endif
return totype<T>((*this)[i] + " " + s);
}
template<class T>
T parseval(const string& tag,const T& defaultval)
{
t_args::iterator itt=Find(tag);
if (itt==m_args.end() || itt+1==m_args.end()) return defaultval;
const T v=totype<T>(*(++itt));
Remove(--itt,2);
return v;
}
template<class T,class R>
pair<T,R> parseval(const string& tag,const T& defaultval1,const R& defaultval2)
{
t_args::iterator itt=Find(tag);
if (itt==m_args.end() || itt+1==m_args.end() || itt+2==m_args.end()) return make_pair(defaultval1,defaultval2);
const T v1=totype<T>(*(++itt));
const R v2=totype<R>(*(++itt));
Remove(----itt,3);
return make_pair(v1,v2);
}
template<class T>
T parseunit(const string& tag,const T& defaultval)
{
t_args::iterator itt=Find(tag);
if (itt==m_args.end() || itt+2==m_args.end()) return defaultval;
const string s1=*(++itt);
const string s2=*(++itt);
const T v=totype<T>(s1 + " " + s2);
Remove(----itt,3);
return v;
}
bool parseopt(const string& tag)
{
t_args::iterator itt=Find(tag);
if (itt==m_args.end()) return false;
Remove(itt,1);
return true;
}
int getoptindex(const string& tag) const
{
int n=0;
for(t_args::const_iterator itt=m_args.begin();itt!=m_args.end();++itt,++n) {
if (tag==*itt) {
assert( n>=0 && size_t(n)<m_args.size());
return n;
}
}
return -1;
}
void remove(const size_t i,const size_t n=1)
{
if (i>m_args.size() || i+n>m_args.size()) throw_("out of range");
m_args.erase(m_args.begin()+i,m_args.begin()+i+n);
}
friend ostream& operator<<(ostream& s,const args& v)
{
for(t_args::const_iterator itt=v.m_args.begin();itt!=v.m_args.end();++itt){
s << *itt << " ";
}
return s;
}
};
#endif // __ARGS_H__

View File

@@ -1,143 +0,0 @@
// The code is copyrighted 2008 by Carsten Frigaard.
// All rights placed in public domain under GNU licence V2, 2008
//
// © 2008 Carsten Frigaard. Permission to use, copy, modify, and distribute this software
// and its documentation for any purpose and without fee is hereby granted, provided that
// the above copyright notice appear in all copies and that both that copyright notice
// and this permission notice appear in supporting documentation.
#ifndef __CONFIGFILE_H__
#define __CONFIGFILE_H__
class Configfile {
private:
typedef vector<string> t_value;
t_value m_text;
map<string,t_value> m_vals;
string m_rem;
string m_strip;
string m_file;
void Load(istream &s)
{
if (!s) throw_("bad stream in configfile input operator");
char buff[32*1024];
bool ini=true;
while(s.getline(buff,32*1024)) {
const string b(strip(buff));
if (ini && b!=m_rem + " Configfile_begin") throw_("bad stream in configfile input operator, missing begin tag");
if (b==m_rem + " Configfile_end") return;
const string t(strip(removerems(b,m_rem)));
if (t.size()>0){
m_text.push_back(t);
const size_t n=t.find_first_of("=");
istringstream s2(t.substr(0,n) + " " + (n==string::npos ? "" : t.substr(n+1)));
string v,k;
s2 >> k;
while ((s2 >> v)) m_vals[k].push_back(v);
}
ini=false;
}
throw_("bad stream in configfile input operator, missing end tag");
}
void Strip(const string& s) const
{
for(size_t i=0;i<m_strip.size();++i){
}
}
public:
Configfile() : m_rem("%") {}
Configfile(const string& filename,const string rem="%") : m_rem(rem), m_file(filename)
{
ifstream s(filename.c_str());
if (!s) throw_("File <" + filename + "> does not exist");
Load(s);
}
Configfile(istream& s,const string rem="%") : m_rem(rem)
{
if (!s) throw_("stream is invalid");
Load(s);
}
size_t size() const {return m_text.size();}
const string& operator[](const size_t n) const {assert(n<m_text.size()); return m_text[n];}
const t_value& operator()(const string& key) const {return Get(key);}
bool hasEntry (const string& key) const {map<string,t_value >::const_iterator itt=m_vals.find(key); return itt!=m_vals.end();}
void Save(const string& filename) {ofstream s(filename.c_str()); s << *this;}
bool operator==(const Configfile& c) const
{
if (m_text!=c.m_text) return false;
else if (m_vals!=c.m_vals) return false;
else if (m_rem!=c.m_rem) return false;
else if (m_strip!=c.m_strip) return false;
else if (m_file!=c.m_file) return false;
return true;
}
bool operator!=(const Configfile& c) const {return !this->operator==(c);}
void Checkfilechange()
{
if (m_file.empty()) return;
Configfile c(m_file);
if (c!=*this) *this=c;
}
const t_value& Get(const string& key) const
{
map<string,t_value >::const_iterator itt=m_vals.find(key);
if (itt==m_vals.end()) throw_("No such entry, <" + key + ">, in configfile");
return itt->second;
}
template<class T> const T Get(const string& key,const bool fullline=false) const
{
const t_value& v=Get(key);
assert( v.size()>0 );
string s=v[0];
if (fullline) for(size_t i=1;i<v.size();++i) s += " " + v[i];
T t=totype<T>(s);
return t;
}
template<class T> const T Initialize(const string& key,const T valiueifnotfound,const bool fullline=false) const
{
if (!hasEntry(key)) return valiueifnotfound;
else return Get<T>(key,fullline);
}
template<class T>
pair<bool,T> GetConfig(const string& e) const
{
if (!hasEntry(e)) return make_pair(false,T());
else return make_pair(true,Get<T>(e,true));
}
template<class T> void Set(const string& key,const T& v)
{
t_value val;
val.push_back(tostring(v));
m_vals[key]=val;
m_text.push_back(key + " " + val[0]);
}
friend ostream& operator<<(ostream& s,const Configfile& x)
{
s << x.m_rem << " Configfile_begin\n";
for(map<string,t_value>::const_iterator itt1=x.m_vals.begin();itt1!=x.m_vals.end();++itt1){
s << "\t" << itt1->first << " = ";
for(t_value::const_iterator itt2=itt1->second.begin();itt2!=itt1->second.end();++itt2) s << *itt2 << " ";
s << "\n";
}
s << x.m_rem << " Configfile_end\n";
// if (!s) throw_("bad stream in configfile output operator");, XXX throws in cout!?
return s;
}
friend istream& operator>>(istream& s,Configfile& x){x.Load(s); return s;}
};
#endif // __CONFIGFILE_H__

View File

@@ -1,197 +0,0 @@
// The code is copyrighted 2008 by Carsten Frigaard.
// All rights placed in public domain under GNU licence V2, 2008
//
// © 2008 Carsten Frigaard. Permission to use, copy, modify, and distribute this software
// and its documentation for any purpose and without fee is hereby granted, provided that
// the above copyright notice appear in all copies and that both that copyright notice
// and this permission notice appear in supporting documentation.
#ifndef __EXCEPTION_H__
#define __EXCEPTION_H__
// forward defs to funs.h
string Getlocaltime();
size_t GetThreadId();
int Message(const string& title,const string& msg,const int type=0);
// simple class for debugging call stack
#ifdef _DEBUG
struct Stackinfo : public vector<string> {
friend ostream& operator<<(ostream& s,const Stackinfo& x)
{
s << "Function stack {" << endl;
for(int i=x.size();i>0;--i){
const string& f=x[i-1];
s << " [" << i-1 << "]: " << f << "(...)" << endl;
}
return s << "}" << endl;
}
};
class Funstack {
private:
const string m_f;
static map<size_t,Stackinfo> m_s;
Funstack(const Funstack&);
void operator=(const Funstack&);
public:
Funstack(const string& f,const int line,const string& file) : m_f(f) {m_s[GetThreadId()].push_back(f);}
~Funstack()
{
const size_t tid=GetThreadId();
assert(m_s.find(tid)!=m_s.end());
assert(m_s[tid].size()>0 && m_s[tid].back()==m_f);
m_s[tid].pop_back();
}
static const Stackinfo GetStack()
{
const size_t tid=GetThreadId();
if (m_s.find(tid)==m_s.end()) return Stackinfo();
else return m_s[tid];
}
};
map<size_t,Stackinfo> Funstack::m_s; // initialize static var
#define FUNSTACK Funstack __f_stack__(__FUNCTION__,__LINE__,__FILE__)
#else
#define FUNSTACK
#define DUMPSTACK(s)
struct Stackinfo {
friend ostream& operator<<(ostream& s,const Stackinfo& x) {return s;}
};
class Funstack {
public:
static Stackinfo GetStack() {return Stackinfo();}
};
#endif
// tee like logger class
class Logger
{
private:
//ostream* m_log;
string m_logfilename;
ofstream m_logfile;
ostream* m_log;
const bool m_logstdout,m_logstderr;
Logger(const Logger&);
void operator=(const Logger&);
public:
Logger(ostream* log,const bool logstdout=true,const bool logstderr=false) : m_log(log), m_logstdout(logstdout), m_logstderr(logstderr) {}
void operator=(ostream* log){m_logfilename=""; m_logfile.close(); m_log=log;}
void open(const string& logfilename,const ios_base::openmode mode)
{
m_log=0;
if (m_logfile.is_open()) m_logfile.close();
m_logfilename=logfilename;
m_logfile.open(m_logfilename.c_str(),mode);
if (!m_logfile) throw("cannot write to logfile <" + logfilename + ">"); // Exception uses logger class, so do not throw a nice Exception class here, use a plain throw
m_log=&m_logfile;
}
void clear()
{
if (m_logfile.is_open()) m_logfile.close();
m_logfile.open(m_logfilename.c_str());
}
template<class T>
friend Logger& operator<<(Logger& log,const T& t)
{
if(log.m_logstdout) cout << t;
if(log.m_logstderr) cerr << t;
if(log.m_log!=0) (*(log.m_log)) << t;
return log;
}
// handle endl and like
friend Logger& operator<<(Logger& log,std::ostream& (*fn)(std::ostream&))
{
if(log.m_logstdout) fn(cout);
if(log.m_logstderr) fn(cerr);
if(log.m_log!=0) fn(*(log.m_log));
return log;
}
void writelogheader(const string& msg)
{
if(m_log==0) return;
else{
(*m_log) << "********************************************************" << endl;
(*m_log) << "** Logentry: " << msg << endl;
(*m_log) << "** Time: " << Getlocaltime();
(*m_log) << "********************************************************" << endl;
}
}
};
// static global logging, default standand out
static Logger g_log(0,true,false);
class Exception{
private:
const string m_msg;
const string m_file;
const int m_line;
const Stackinfo m_stack;
public:
Exception(const string msg,const string file,const int line,const Stackinfo s) : m_msg(msg), m_file(file), m_line(line), m_stack(s) {}
Exception(const char* msg,const string file,const int line,const Stackinfo s) : m_msg(msg), m_file(file), m_line(line), m_stack(s) {}
inline static string FormatCompilerMsg(const string& file,const int line,const bool warnonly=false)
{
#ifdef WIN32
return file + "(" + Exception::tostring(line) + ") : " + (warnonly ? "warning : " : "error : ");
#else
return file + ":" + Exception::tostring(line) + ": " + (warnonly ? "warning: " : "error: ");
#endif
}
inline static void throw_fun(const string& msg,const string& file,const int line)
{
const string msg2=Exception::FormatCompilerMsg(file,line) + "throwing exception: " + msg;
g_log << msg2;
#ifdef _WINDOWS_
const string f=tostring(Funstack::GetStack());
const string msg3=msg2 + (f.size()>0 ? "\n\n" : "") + f.substr(0,300) + (f.size()>300 ? "\n..." : "");
Message("Exception encountered...",msg3,0);
#endif
throw Exception(msg,file,line,Funstack::GetStack());
}
inline string Msg() const
{
return FormatCompilerMsg(m_file,m_line) + "Exception: " + m_msg;
}
friend ostream& operator<<(ostream& os,const Exception& e)
{
return os << e.Msg() << endl << e.m_stack;
}
template<typename T>
static string tostring(const T& x)
{
ostringstream os;
os << x;
return os.str();
}
};
#define throw_(msg) Exception::throw_fun(msg,__FILE__, __LINE__)
#define warn_(msg) cerr << Exception::FormatCompilerMsg(__FILE__, __LINE__,true) << msg << endl;
#define CATCH_ALL\
catch(const char* s) {cout.flush(); cerr << Exception::FormatCompilerMsg(__FILE__, __LINE__) << "caught exception chars: " << s;}\
catch(const string& s) {cout.flush(); cerr << Exception::FormatCompilerMsg(__FILE__, __LINE__) << "caught exception string: " << s;}\
catch(const Exception& s){cout.flush(); cerr << Exception::FormatCompilerMsg(__FILE__, __LINE__) << "caught Exception class: " << s;}\
catch(...) {cout.flush(); cerr << Exception::FormatCompilerMsg(__FILE__, __LINE__) << "caught unknown exception";}\
cerr << "...aborting" << endl;
#endif // __EXCEPTION_H__

View File

@@ -1,208 +0,0 @@
// The code is copyrighted 2008 by Carsten Frigaard.
// All rights placed in public domain under GNU licence V2, 2008
//
// © 2008 Carsten Frigaard. Permission to use, copy, modify, and distribute this software
// and its documentation for any purpose and without fee is hereby granted, provided that
// the above copyright notice appear in all copies and that both that copyright notice
// and this permission notice appear in supporting documentation.
#ifndef __FILE_H__
#define __FILE_H__
inline bool FileExists(const std::string& f)
{
ifstream s(f.c_str());
return (!s)==false;
}
inline void AssertFileExists(const std::string& f)
{
if (!FileExists(f)) throw_("File <" + f + "> does not exist");
}
inline size_t FileSize(const std::string& f)
{
AssertFileExists(f);
ifstream s(f.c_str());
if (!s) throw_("Stream is bad (file <" + f + ">)");
s.seekg(0,ios::end);
if (!s) throw_("Stream is bad (file <" + f + ">)");
return s.tellg();
}
inline void AssertFileNotEmpty(const std::string& f)
{
if (FileSize(f)==0) throw_("File <" + f + "> is empty");
}
inline size_t FileTime(const string& file)
{
AssertFileExists(file);
const string t=System("date -r " + file + " +%s",true,true); // seconds since 1970-01-01 00:00:00 UTC
return totype<size_t>(t);
// #include <sys/stat.h>
// #include <unistd.h>
// struct stat s;
// int n=stat(file.c_str(),&s);
// if (n!=0) throw_("cannot stat file <" + file + ">");
// assert( sizeof(time_t)==sizeof(size_t) );
// return s.st_mtime;
}
inline bool isFileNewer(const string& file0,const string& file1)
{
return FileTime(file0)>FileTime(file1);
}
inline bool DirExists(const std::string& f)
{
const string file=f + "/.dummy.txt";
ofstream s(file.c_str());
if(!s) return false;
s << "testfile";
if(!s) return false;
s.close();
return FileSize(file)==8;
}
inline string MakeSuffix(const int n)
{
assert(n>=0);
if (n<=9) return "00" + tostring(n);
else if (n<=99) return "0" + tostring(n);
else return tostring(n);
}
template<class T>
void Readdata(const string& tok,istream& is,T& t)
{
if (!is) throw_("Stream is bad");
is >> t;
if (!is) throw_("Reading {" + tok + "} settings");
}
inline string Readline(istream& is)
{
char buff[16*1024];
is.getline(buff,16*1024);
return string(buff);
}
template<class T>
inline T Readtyp(ifstream& s){
T x;
s.read(reinterpret_cast<char*>(&x),sizeof(x));
if(!s) throw_("bad stream");
return x;
}
inline string Readstring(ifstream& s){
char c=0;
string t;
do{
c=Readtyp<char>(s);
if(c!=0) t+=c;
}
while (c!=0);
return t;
}
template<class T>
inline vector<T> Readbin(std::ifstream& s,const int size)
{
if(!s) throw_("bad stream");
vector<T> x(size);
s.read(reinterpret_cast<char*>(&x.front()),x.size()*sizeof(T));
if(!s) throw_( "bad write");
return x;
}
template<class T>
inline void Writetyp(ofstream& s,const T& x){
s.write(reinterpret_cast<const char*>(&x),sizeof(x));
if(!s) throw_( "bad stream");
}
template<class T>
inline void Writebin(std::ofstream& s,const std::vector<T>& x,const bool writetag)
{
if(!s) throw_("bad stream");
const size_t sz=x.size()*sizeof(T);
if(writetag){
Writetyp(s,sz);
}
if(!s) throw_( "bad stream" );
s.write(reinterpret_cast<const char*>(&x.front()),sz);
if(!s) throw_( "bad write");
if (writetag) Writetyp(s,sz);
if(!s) throw_( "bad stream");
}
template<class T,class R>
inline void Writebin(std::ofstream& s,const std::map<T,R>& x,const bool writetag)
{
vector<T> t;
vector<R> r;
t.reserve(x.size());
r.reserve(x.size());
for(typename std::map<T,R>::const_iterator itt=x.begin();itt!=x.end();++itt){
t.push_back(itt->first);
r.push_back(itt->second);
}
if (writetag) {
Writetyp(s,x.size());
Writetyp(s,static_cast<unsigned int>(sizeof(T)));
Writetyp(s,static_cast<unsigned int>(sizeof(R)));
}
Writebin(s,t,writetag);
Writebin(s,r,writetag);
}
template<class T>
inline void Readbin(std::ifstream& s,vector<T>& x)
{
if(!s) throw_("bad stream");
const size_t sz=Readtyp<size_t>(s);
if(!s) throw_( "bad stream" );
if(sz%sizeof(T)!=0) throw_("bad size tag");
x.resize(sz/sizeof(T));
s.read(reinterpret_cast<char*>(&x.front()),sz);
if(!s) throw_( "bad write");
if (Readtyp<size_t>(s)!=sz) throw_("bad size tag");
if(!s) throw_( "bad stream");
}
template<class T,class R>
inline void Readbin(std::ifstream& s,map<T,R>& x)
{
vector<T> t;
vector<R> r;
const size_t sz=Readtyp<size_t>(s);
const size_t szT=Readtyp<unsigned int>(s);
const size_t szR=Readtyp<unsigned int>(s);
if (szT!=sizeof(T)) throw_("type T size mismatch in Readbin (map)");
if (szR!=sizeof(R)) throw_("type R size mismatch in Readbin (map)");
Readbin(s,t);
Readbin(s,r);
if (t.size()!=r.size()) throw_("size mismatch in Readbin (map)");
x.clear();
for(size_t i=0;i<t.size();++i){
x[t[i]]=r[i];
}
if (x.size()!=sz) throw_("map size mismatch in Readbin (map)");
}
template<class T>
inline void Writeascii(const string& filename,const std::vector<T>& x,const string& comment="",const char& newline='\n')
{
ofstream s(filename.c_str());
if(!s) throw_("bad file <" + filename + ">");
s << "% Writeascii: size=" << x.size() << " " << comment << "\n";
for(size_t i=0;i<x.size();++i) s << x[i] << newline;
if(!s) throw_( "bad writing to file <" + filename + ">");
}
#endif // __FILE_H__

View File

@@ -1,413 +0,0 @@
// The code is copyrighted 2008 by Carsten Frigaard.
// All rights placed in public domain under GNU licence V2, 2008
//
// © 2008 Carsten Frigaard. Permission to use, copy, modify, and distribute this software
// and its documentation for any purpose and without fee is hereby granted, provided that
// the above copyright notice appear in all copies and that both that copyright notice
// and this permission notice appear in supporting documentation.
#ifndef __FUNS_H__
#define __FUNS_H__
#include <stdlib.h>
#include <time.h>
#define Unimplemented throw_("Function unimplemented")
#define Dontgethere throw_("Dontgethere")
#ifndef NDEBUG
#define ON_DEBUG(a) a
#else
#define ON_DEBUG(a)
#endif
#ifdef USE_FFTW
extern int posix_memalign(void **__memptr, size_t __alignment, size_t __size);
#endif
// Small template funs
template<class T,class R> bool isinmap (const map<T,R>& m,const T& t) {return m.size()>=2 && m.begin()->first<=t && t<(--m.end())->first;}
template<class T> const size_t getsteps(const T& r0,const T& r1,const T& rstep,const bool logarithmic) {size_t N=0; for(T r=r0;r<r1;logarithmic ? r*=rstep/T(1) : r+=rstep) ++N; return N;}
inline std::string Version(){return string("VERSION: ") + VERSION + "." + VERSION_REV;}
inline std::string Config()
{
std::string s;
#ifdef NDEBUG
s+="NDEBUG";
#else
#ifdef PROFILE
s+="PROFILE";
#else
s+="DEBUG";
#endif
#endif
#ifdef USE_UNITS
s+= " USE_UNITS";
#endif
#ifdef USE_FLOAT_CHECKS
s+= " USE_FLOAT_CHECKS";
#endif
#ifdef USE_FFTW_IC
s+= " USE_FFTW_IC";
#endif
#ifdef USE_FFTW
s+= " USE_FFTW";
#endif
#ifdef USE_MPI
s+= " USE_MPI";
#endif
if (sizeof(void*)==4) s+=" 32BIT";
else if (sizeof(void*)==8) s+=" 64BIT";
else s+=" XXBIT";
const long one= 1;
const int big=!(*(reinterpret_cast<const char *>(&one)));
if (big) s+=" BIGENDIAN";
else s+=" LITENDIAN";
return s;
}
inline string FormatCompilerMsg(const string& file,const int line)
{
#ifdef WIN32
return file + ":" + line + ":";
#else
return file + "(" + line + ")";
#endif
}
#ifdef WIN32
extern "C"{
#ifdef _UNICODE
#pragma message("ERROR: toolsfun cannot handle unicode...giving up compilation");
ERROR_complier
#endif
#ifdef _AFXDLL
__declspec(dllimport) void* __stdcall GetCurrentThread();
__declspec(dllimport) void* __stdcall GetCurrentThreadId();
__declspec(dllimport) int __stdcall SetThreadPriority(void* hThread,int nPriority);
#else
//void* __stdcall GetCurrentThread();
//void* __stdcall GetCurrentThreadId();
//int __stdcall SetThreadPriority(void* hThread,int nPriority);
__declspec(dllimport) void* __stdcall GetCurrentThread();
__declspec(dllimport) unsigned long __stdcall GetCurrentThreadId();
__declspec(dllimport) int __stdcall SetThreadPriority(void* hThread,int nPriority);
__declspec(dllimport) int __stdcall GetThreadPriority(void* hThread);
__declspec(dllimport) unsigned int __stdcall WinExec(const char* lpCmdLine,unsigned int uCmdShow);
#ifndef _WINDOWS_
__declspec(dllimport) unsigned int __stdcall MessageBox(void* hWnd,const char* lpText,const char* lpCaption,unsigned int Type);
__declspec(dllimport) unsigned long __stdcall GetCurrentDirectory(unsigned long nBufferLength,char* lpBuffer);
#endif
#endif
}
#else
int nice(int inc);
#endif
inline int Message(const string& title,const string& msg,const int type)
{
#ifdef WIN32
// 0 = MB_OK
// 1 = MB_OKCANCEL
// 2 = MB_ABORTRETRYIGNORE
// 3 = MB_YESNOCANCEL
// 4 = MB_YESNO
// 5 = MB_RETRYCANCEL
// 6 = MB_CANCELTRYCONTINUE: if(WINVER >= 0x0500)
MessageBox(NULL,msg.c_str(),title.c_str(),type);
#else
Unimplemented;
#endif
return 1;
}
/*
string GetCurrentDir()
{
#ifdef WIN32
char buff[16*1024];
if(GetCurrentDirectory(16*1024,buff)==0) throw_("GetCurrentDirectory() failed");
return tostring(buff);
#else
Unimplemented;
return "";
#endif
}
*/
inline void SetNiceLevel(const int level)
{
#ifdef WIN32
// THREAD_PRIORITY_ABOVE_NORMAL 1 Priority 1 point above the priority class.
// THREAD_PRIORITY_BELOW_NORMAL -1 Priority 1 point below the priority class.
// THREAD_PRIORITY_HIGHEST 2 Priority 2 points above the priority class.
// THREAD_PRIORITY_IDLE -15 Base priority of 1 for IDLE_PRIORITY_CLASS,...
// THREAD_PRIORITY_LOWEST -2 Priority 2 points below the priority class.
// THREAD_PRIORITY_NORMAL 0 Normal priority for the priority class.
// THREAD_PRIORITY_TIME_CRITICAL 15 Base priority of 15 for IDLE_PRIORITY_CLASS,...
if (level!=0 && level!=1 && level!=-1 && level!=2 && level!=-2 && level!=15 && level!=-15) throw_("wrong Win32 nice level, must be oneof -15,-2,-1,0,1,2,15");
SetThreadPriority(GetCurrentThread(),-level);
assert( GetThreadPriority(GetCurrentThread())==-level );
#else
const int n=nice(level);
if (n<0) throw_("Could not set nice level");
#endif
}
inline size_t GetThreadId()
{
#ifdef WIN32
assert( sizeof(size_t)==sizeof(unsigned long) );
return GetCurrentThreadId();
#else
// may be replaced by return 0; if phtread not found!
assert( sizeof(size_t)==sizeof(pthread_t) );
const pthread_t p=pthread_self();
size_t q=0;
memcpy(&q,&p,sizeof(q));
return q;
#endif
}
#ifdef TOOLSFUN_QUIET_WIN32_SYSTEM
#ifdef WIN32
// make a special non-console system call, instead of the standard system()
// XXX SystemWin, does not wait for process to finish, CreatProc still create window
int SystemWin(const string& cmd)
{
//ShellExecute, CreateProcess, WinExec or system
// HINSTANCE hi=ShellExecute(NULL,NULL,cmdx,"","",SW_SHOSNOACTIVATE);
// if (reinterpret_cast<int>(hi)<32) MessageBox(NULL,(string("ShellExecute <") + cmd + "> failed").c_str(),"Error",0);
// const string cmd2="\\\"" + cmd + "\\\""; // fix problem with spaces in executable, not working yet
unsigned int r=WinExec(cmd.c_str(),4);
return r<32 ? -1 : 0;
}
bool CreateProc(const string& cmd,const bool throwexception=true,const bool waitforprocesstofinish=true)
{
STARTUPINFO s;
PROCESS_INFORMATION p;
memset(&s,0,sizeof(s));
memset(&p,0,sizeof(p));
s.cb=sizeof(s);
// to avoid const cast of char* in CreateProcess
char cmdx[16*1024];
strcpy_s(cmdx,16*1024,cmd.c_str());
const int r=CreateProcess(0,cmdx,0,0,false,CREATE_DEFAULT_ERROR_MODE,0,0,&s,&p);
if (r!=0) {if(waitforprocesstofinish) WaitForSingleObject(p.hProcess,INFINITE);}
else {
if (throwexception) throw_(string("CreateProcess() failed with return code <") + GetLastError() + ">");
else return false;
}
// Release handles
assert(r!=0);
CloseHandle(p.hProcess);
CloseHandle(p.hThread);
return true;
}
#endif
#endif
inline string System(const string& cmd,const bool throwexception=true,const bool captureoutput=false,int* pret=0)
{
if (!captureoutput){
#ifdef TOOLSFUN_QUIET_WIN32_SYSTEM
const int n=SystemWin(cmd);
#else
const int n=system(cmd.c_str());
#endif
if (n!=0 && throwexception) throw_(string("system command failed with code=") + n + " cmd=<" + cmd + ">");
if (pret!=0) *pret=n;
return "";
} else {
#ifdef WIN32
const string rm="del ";
char tmp[1024];
if (tmpnam(tmp)) throw_("error in creating win32 temp name");
const string file(tmp);
#else
const string rm="rm ";
const string file=tmpnam("tempfile");
#endif
ifstream s1(file.c_str());
if(s1) {
s1.close();
System((rm + file).c_str(),true,false);
}
System(cmd + " > " + file,throwexception,false,pret);
string t;
char buff[16*1024];
ifstream s2(file.c_str());
while(s2) {
s2.getline(buff,16*1024);
if (s2) t += buff;
}
s2.close();
System((rm + file).c_str(),true,false);
return t;
}
}
string Getlocaltime()
{
FUNSTACK;
time_t rawtime;
time(&rawtime);
struct tm* timeinfo;
timeinfo = localtime(&rawtime);
return asctime(timeinfo);
}
class timer
{
private:
double m_t,m_cpu_t;
double* m_addt;
mutable double m_last_t,m_last_eta;
static double gettime()
{
#ifdef WIN32
return 1.0*clock()/CLOCKS_PER_SEC; // use low-res clock
// FILETIME ft;
// unsigned __int64 tmpres = 0;
//
// GetSystemTimeAsFileTime(&ft);
//
// tmpres |= ft.dwHighDateTime;
// tmpres <<= 32;
// tmpres |= ft.dwLowDateTime;
//
// converting file time to unix epoch
// tmpres -= DELTA_EPOCH_IN_MICROSECS;
// tmpres /= 10; // convert into microseconds
// tv->tv_sec = (long)(tmpres / 1000000UL);
// tv->tv_usec = (long)(tmpres % 1000000UL);
#else
struct timeval tv;
gettimeofday(&tv,NULL);
return tv.tv_sec + static_cast<double>(tv.tv_usec)/1000000;
#endif
}
static double getcputime()
{
static const double f=1.0/CLOCKS_PER_SEC;
return f*clock();
}
template<class T>
static double Remaining(const double t,const T& n,const T& N)
{
if (n>=N || N<=T(0)) throw_("value out of range in timer::Remaining, n>=N or N<=0, n=" + tostring(n) + " N=" + tostring(N));
const double p=static_cast<double>(n/T(1)+1)/(N/T(1));
const double p2=p>0 ? t/p : 0;
return p2>t ? p2-t : 0;
}
public:
timer() : m_t(gettime()), m_cpu_t(getcputime()), m_addt(0), m_last_t(-1), m_last_eta(-1) {}
timer(double& t) : m_t(gettime()), m_cpu_t(getcputime()), m_addt(&t), m_last_t(-1), m_last_eta(-1) {}
~timer() {if (m_addt!=0) (*m_addt) += elapsed();}
void reset () {m_t=gettime(); m_cpu_t=getcputime(); m_last_t=-1; m_last_eta=-1;}
double elapsed() const {return gettime()-m_t;}
double cputime() const {return getcputime()-m_cpu_t;}
static string ToHMS(const double& t)
{
assert( t>=0 );
const unsigned int it=static_cast<unsigned int>(t+.5);
const unsigned int hours=it/(60*60);
const unsigned int mins=(it-hours*60*60)/(60);
const unsigned int secs=(it-hours*60*60-mins*60);
assert( secs<60 && mins<60);
return tostring(hours) + ":" + (mins<10 ? "0": "") + tostring(mins) + ":" + (secs<10 ? "0": "") + tostring(secs);
}
template<class T> static inline int Topercent(const T x,const T N,const int decimals=-1)
{
assert(x<N && N!=T(0));
float pf=static_cast<float>(x/T(1))/(N/T(1));
if (decimals>0) pf=static_cast<int>(pf*decimals)/(1.0*decimals);
return static_cast<int>(pf*100+.5);
}
template<class T> void ToEta(const T& n,const T& N,ostream& s,const double timeprintsteps=30,const bool verboseprint=false) const
{
if (n>=N) return;
assert( n<N );
const double t=gettime()-m_t;
if (n==T(0)) {
m_last_t=t;
return;
}
const double e=(t-m_last_t);
if (e>timeprintsteps) {
const double f=timeprintsteps*60;
const double r=Remaining(t,n,N);
if (m_last_eta<0 || r<f || (r>f && e>f) /*|| (m_last_eta>0 && r>1.2*m_last_eta) */ ){
time_t tm;
time(&tm);
const string systime=ctime(&tm);
if (m_last_eta<0) s << "Current system time: " << systime;
tm += static_cast<time_t>(r);
const string eta=ctime(&tm);
const bool extraday=(eta.substr(0,3)!=systime.substr(0,3));
const string eday=extraday ? " "+eta.substr(0,3)+" " : "";
s << "Time [h:m:s]=" << ToHMS(t) << ", R=" << ToHMS(r) << ", ETA=" << eday << eta.substr(11,8);
if(verboseprint) {
const string t=", n/N=" + tostring(n) + "/" + tostring(N) + "=" + tostring(Topercent(n,N,10)) + " percent,";
s << t;
for(size_t i=t.size();i<42;++i) s << " ";
s << " CPU=" << ToHMS(cputime());
}
s << endl;
m_last_t=t;
m_last_eta=r;
}
}
}
friend ostream& operator<<(ostream& s,const timer x)
{
return s << "Time [h:m:s]= " << x.ToHMS(x.elapsed()) << " CPU=" << x.ToHMS(x.cputime());
}
};
/*
int SwapEndian(void *data,const size_t size) {
short xs;
long xl;
switch (size){
case 2:
xs = *(short *)data;
*(short *)data = ( ((xs & 0x0000ff00) >> 8) | ((xs & 0x000000ff) << 8) );
break;
case 4:
xl = *(long *)data;
*(long *)data = ( ((xl & 0xff000000) >> 24) | ((xl & 0x00ff0000) >> 8) |
((xl & 0x0000ff00) << 8) | ((xl & 0x000000ff) << 24) );
break;
default: break;
}
return 0;
}
*/
#endif // __FUNS_H__

View File

@@ -1,282 +0,0 @@
#ifndef __PROCESS_H__
#define __PROCESS_H__
#include <tlhelp32.h>
pair<HANDLE,PROCESSENTRY32> ProcessWalkInit()
{
// Take a snapshot of all processes in the system.
HANDLE hProcessSnap = CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
if( hProcessSnap == INVALID_HANDLE_VALUE ) throw_("CreateToolhelp32Snapshot() returned invalid handle");
// Set the size of the structure before using it.
PROCESSENTRY32 pe32;
pe32.dwSize = sizeof(PROCESSENTRY32);
// Retrieve information about the first process,
// and exit if unsuccessful
if(!Process32First(hProcessSnap,&pe32)) {
CloseHandle(hProcessSnap); // clean the snapshot object
throw_("Process32First"); // show cause of failure
}
return make_pair(hProcessSnap,pe32);
}
DWORD GetProcessID(const string& processname)
{
pair<HANDLE,PROCESSENTRY32> h=ProcessWalkInit();
HANDLE hProcessSnap=h.first;
PROCESSENTRY32 pe32=h.second;
do {
if (pe32.szExeFile==processname) {
CloseHandle(hProcessSnap);
return pe32.th32ProcessID;
}
} while( Process32Next(hProcessSnap,&pe32) );
CloseHandle(hProcessSnap);
return 0;
}
PROCESSENTRY32 GetProcessInfo(const DWORD id)
{
pair<HANDLE,PROCESSENTRY32> h=ProcessWalkInit();
HANDLE hProcessSnap=h.first;
PROCESSENTRY32 pe32=h.second;
int n=0;
do {
if (pe32.th32ProcessID==id) {
CloseHandle(hProcessSnap);
return pe32;
}
} while( Process32Next(hProcessSnap,&pe32) );
CloseHandle(hProcessSnap);
ZeroMemory( &pe32, sizeof(pe32) );
pe32.dwSize = sizeof(PROCESSENTRY32);
return pe32;
}
DWORD GetProcessCount(const string& processname)
{
pair<HANDLE,PROCESSENTRY32> h=ProcessWalkInit();
HANDLE hProcessSnap=h.first;
PROCESSENTRY32 pe32=h.second;
int n=0;
do {
if (pe32.szExeFile==processname) ++n;
} while( Process32Next(hProcessSnap,&pe32) );
CloseHandle(hProcessSnap);
return n;
}
bool KillProcessID(const DWORD id)
{
HANDLE hProcess = OpenProcess( PROCESS_TERMINATE, FALSE, id);
if(hProcess==NULL) return false; // might have gone in the meantime, so no throw_("OpenProcess() got null handle");
const BOOL t=TerminateProcess(hProcess,-1);
CloseHandle(hProcess);
return t!=0;
}
void KillAllProcesses(const string& exe)
{
// kill existing polls
DWORD id=GetProcessID(exe);
while(id!=0){
KillProcessID(id);
id=GetProcessID(exe);
}
}
/*
#include <tchar.h>
#include <stdio.h>
#include <stdlib.h>
BOOL GetProcessList( );
BOOL ListProcessModules( DWORD dwPID );
BOOL ListProcessThreads( DWORD dwOwnerPID );
void printError( TCHAR* msg );
FILE* log=fopen("d:\\plog.txt","w");
BOOL GetProcessList( )
{
HANDLE hProcessSnap;
HANDLE hProcess;
PROCESSENTRY32 pe32;
DWORD dwPriorityClass;
// Take a snapshot of all processes in the system.
hProcessSnap = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
if( hProcessSnap == INVALID_HANDLE_VALUE )
{
printError( TEXT("CreateToolhelp32Snapshot (of processes)") );
return( FALSE );
}
// Set the size of the structure before using it.
pe32.dwSize = sizeof( PROCESSENTRY32 );
// Retrieve information about the first process,
// and exit if unsuccessful
if( !Process32First( hProcessSnap, &pe32 ) )
{
printError( TEXT("Process32First") ); // show cause of failure
CloseHandle( hProcessSnap ); // clean the snapshot object
return( FALSE );
}
// Now walk the snapshot of processes, and
// display information about each process in turn
do
{
fprintf(log, "\n\n=====================================================" );
fprintf(log, TEXT("\nPROCESS NAME: %s"), pe32.szExeFile );
fprintf(log, "\n-----------------------------------------------------" );
// Retrieve the priority class.
dwPriorityClass = 0;
hProcess = OpenProcess( PROCESS_ALL_ACCESS, FALSE, pe32.th32ProcessID );
if( hProcess == NULL )
printError( TEXT("OpenProcess") );
else
{
dwPriorityClass = GetPriorityClass( hProcess );
if( !dwPriorityClass )
printError( TEXT("GetPriorityClass") );
CloseHandle( hProcess );
}
fprintf(log, "\n Process ID = 0x%08X", pe32.th32ProcessID );
fprintf(log, "\n Thread count = %d", pe32.cntThreads );
fprintf(log, "\n Parent process ID = 0x%08X", pe32.th32ParentProcessID );
fprintf(log, "\n Priority base = %d", pe32.pcPriClassBase );
if( dwPriorityClass )
fprintf(log, "\n Priority class = %d", dwPriorityClass );
// List the modules and threads associated with this process
ListProcessModules( pe32.th32ProcessID );
ListProcessThreads( pe32.th32ProcessID );
} while( Process32Next( hProcessSnap, &pe32 ) );
CloseHandle( hProcessSnap );
return( TRUE );
}
BOOL ListProcessModules( DWORD dwPID )
{
HANDLE hModuleSnap = INVALID_HANDLE_VALUE;
MODULEENTRY32 me32;
// Take a snapshot of all modules in the specified process.
hModuleSnap = CreateToolhelp32Snapshot( TH32CS_SNAPMODULE, dwPID );
if( hModuleSnap == INVALID_HANDLE_VALUE )
{
printError( TEXT("CreateToolhelp32Snapshot (of modules)") );
return( FALSE );
}
// Set the size of the structure before using it.
me32.dwSize = sizeof( MODULEENTRY32 );
// Retrieve information about the first module,
// and exit if unsuccessful
if( !Module32First( hModuleSnap, &me32 ) )
{
printError( TEXT("Module32First") ); // show cause of failure
CloseHandle( hModuleSnap ); // clean the snapshot object
return( FALSE );
}
// Now walk the module list of the process,
// and display information about each module
do
{
fprintf(log, TEXT("\n\n MODULE NAME: %s"), me32.szModule );
fprintf(log, TEXT("\n Executable = %s"), me32.szExePath );
fprintf(log, "\n Process ID = 0x%08X", me32.th32ProcessID );
fprintf(log, "\n Ref count (g) = 0x%04X", me32.GlblcntUsage );
fprintf(log, "\n Ref count (p) = 0x%04X", me32.ProccntUsage );
fprintf(log, "\n Base address = 0x%08X", (DWORD) me32.modBaseAddr );
fprintf(log, "\n Base size = %d", me32.modBaseSize );
} while( Module32Next( hModuleSnap, &me32 ) );
CloseHandle( hModuleSnap );
return( TRUE );
}
BOOL ListProcessThreads( DWORD dwOwnerPID )
{
HANDLE hThreadSnap = INVALID_HANDLE_VALUE;
THREADENTRY32 te32;
// Take a snapshot of all running threads
hThreadSnap = CreateToolhelp32Snapshot( TH32CS_SNAPTHREAD, 0 );
if( hThreadSnap == INVALID_HANDLE_VALUE )
return( FALSE );
// Fill in the size of the structure before using it.
te32.dwSize = sizeof(THREADENTRY32);
// Retrieve information about the first thread,
// and exit if unsuccessful
if( !Thread32First( hThreadSnap, &te32 ) )
{
printError( TEXT("Thread32First") ); // show cause of failure
CloseHandle( hThreadSnap ); // clean the snapshot object
return( FALSE );
}
// Now walk the thread list of the system,
// and display information about each thread
// associated with the specified process
do
{
if( te32.th32OwnerProcessID == dwOwnerPID )
{
fprintf(log, "\n\n THREAD ID = 0x%08X", te32.th32ThreadID );
fprintf(log, "\n Base priority = %d", te32.tpBasePri );
fprintf(log, "\n Delta priority = %d", te32.tpDeltaPri );
}
} while( Thread32Next(hThreadSnap, &te32 ) );
CloseHandle( hThreadSnap );
return( TRUE );
}
void printError( TCHAR* msg )
{
DWORD eNum;
TCHAR sysMsg[256];
TCHAR* p;
eNum = GetLastError( );
FormatMessage( FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, eNum,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
sysMsg, 256, NULL );
// Trim the end of the line and terminate it with a null
p = sysMsg;
while( ( *p > 31 ) || ( *p == 9 ) )
++p;
do { *p-- = 0; } while( ( p >= sysMsg ) &&
( ( *p == '.' ) || ( *p < 33 ) ) );
// Display the message
fprintf(log, TEXT("\n WARNING: %s failed with error %d (%s)"), msg, eNum, sysMsg );
}
*/
#endif // __PROCESS_H__

View File

@@ -1,95 +0,0 @@
#ifndef __REGISTRY_H__
#define __REGISTRY_H__
#ifdef WIN32
#ifdef _WINDOWS
namespace Registry{
void* StringtoRoot(const string& t)
{
if (t=="HKEY_CLASSES_ROOT") return HKEY_CLASSES_ROOT;
else if (t=="HKEY_CURRENT_USER") return HKEY_CURRENT_USER;
else if (t=="HKEY_LOCAL_MACHINE") return HKEY_LOCAL_MACHINE;
else if (t=="HKEY_USERS") return HKEY_USERS;
else {throw_("bad root path in registry"); return 0;}
}
pair<void*,pair<string,string> > GetPath(const string& fullpath)
{
const int n=fullpath.find_first_of('\\');
if (n==string::npos) throw_("mallformated registry entry");
const string t=fullpath.substr(0,n);
void* root=StringtoRoot(t);
const string r=fullpath.substr(n+1,-1);
const int m=r.find_last_of('\\');
if (m==string::npos) throw_("mallformated registry entry");
const string path=r.substr(0,m);
const string key =r.substr(m+1,-1);
return make_pair(root,make_pair(path,key));
}
bool hasKey(void* root,const string& path,const string& key,string* val=0)
{
assert( sizeof(void*)==sizeof(HKEY) && root!=0 );
if (root!=HKEY_CLASSES_ROOT && root!=HKEY_CURRENT_USER && root!=HKEY_LOCAL_MACHINE && root!=HKEY_USERS) throw_("unknown root path in registry");
DWORD buffersize=1024*16;
char buff[1024*16];
buff[0]=0;
HKEY hKey;
if (ERROR_SUCCESS!=RegOpenKeyEx(static_cast<HKEY>(root),path.c_str(),NULL,KEY_READ,&hKey)) return false;
if (ERROR_SUCCESS!=RegQueryValueEx(hKey,key.c_str(),NULL,NULL,(LPBYTE)buff,&buffersize)) return false;
if (ERROR_SUCCESS!=RegCloseKey(hKey)) return false;
if (val!=0) *val=buff;
return true;
}
string GetKey(void* root,const string& path,const string& key)
{
string val;
if (!hasKey(root,path,key,&val)) throw_("could not read registry entry");
return val;
}
string GetKey(const string& fullpath)
{
const pair<void*,pair<string,string> > p=GetPath(fullpath);
return GetKey(p.first,p.second.first,p.second.second);
}
bool SetKey(void* root,const string& path,const string& key,const string& val)
{
assert( sizeof(void*)==sizeof(HKEY) && root!=0 );
if (root!=HKEY_CLASSES_ROOT && root!=HKEY_CURRENT_USER && root!=HKEY_LOCAL_MACHINE && root!=HKEY_USERS) throw_("unknown root path in registry");
if (val.size()+1>1024*16) throw_("lenght of value to long");
char buff[1024*16];
size_t i;
for(i=0;i<val.size();++i) buff[i]=val[i];
buff[i]=0;
const DWORD buffersize=i;
HKEY hKey;
if (ERROR_SUCCESS!=RegCreateKeyEx(static_cast<HKEY>(root),path.c_str(),0,NULL,REG_OPTION_VOLATILE,KEY_ALL_ACCESS,NULL,&hKey,NULL)) return false;
if (ERROR_SUCCESS!=RegSetValueEx(hKey,key.c_str(),NULL,REG_SZ,(LPBYTE)buff,buffersize)) return false;
if (ERROR_SUCCESS!=RegCloseKey(hKey)) return false;
return true;
}
bool SetKey(const string& fullpath,const string& val)
{
const pair<void*,pair<string,string> > p=GetPath(fullpath);
return SetKey(p.first,p.second.first,p.second.second,val);
}
}; // namespace Registry
#endif // _WINDOWS
#endif // WIN32
#endif // __REGISTRY_H__

View File

@@ -1,284 +0,0 @@
// The code is copyrighted 2008 by Carsten Frigaard.
// All rights placed in public domain under GNU licence V2, 2008
//
// © 2008 Carsten Frigaard. Permission to use, copy, modify, and distribute this software
// and its documentation for any purpose and without fee is hereby granted, provided that
// the above copyright notice appear in all copies and that both that copyright notice
// and this permission notice appear in supporting documentation.
#ifndef __STRINGFUN_H__
#define __STRINGFUN_H__
struct outputoperator_tags
{
string preline,endline;
int prewidth,postwidth,precision;
bool maptags,printnumbers,serialize;
outputoperator_tags()
: endline("\n"), prewidth(-1), postwidth(-1), precision(-1), maptags(false), printnumbers(false), serialize(false) {}
};
static outputoperator_tags g_tags;
inline ostream& operator<<(ostream& os,const outputoperator_tags& x){
g_tags=x;
if (g_tags.precision>0) os.precision(g_tags.precision);
return os;
}
template<typename T>
inline string tostring(const T& x)
{
ostringstream os;
outputoperator_tags t1=g_tags;
g_tags=outputoperator_tags();
g_tags.serialize=true;
g_tags.endline="";
os << x;
g_tags=t1;
return os.str();
}
template<typename T>
inline T totype(const string& s)
{
istringstream is(s);
T x;
is >> x;
return x;
}
inline string operator+ (const string& s,const char* c) {return s+string(c);}
inline string operator+ (const string& s,const short& c) {return s+tostring(c);}
inline string operator+ (const string& s,const unsigned short& c) {return s+tostring(c);}
inline string operator+ (const string& s,const int& c) {return s+tostring(c);}
inline string operator+ (const string& s,const long& c) {return s+tostring(c);}
inline string operator+ (const string& s,const unsigned long& c) {return s+tostring(c);}
inline string operator+ (const string& s,const float& c) {return s+tostring(c);}
inline string operator+ (const string& s,const double& c) {return s+tostring(c);}
inline string operator+ (const string& s,const long double& c) {return s+tostring(c);}
inline string operator+ (const char* a ,const string& b) {return string(a)+b;}
#ifdef OS_Linux
#ifdef __GCC_V4__
// does not work under some compilers where size_t==unsigned int
inline string operator+ (const string& s,const size_t& c) {return s+tostring(c);}
#endif
#endif
inline string tostring(const int argc,char** argv)
{
string s;
for(int i=0;i<argc;++i) s += string(argv[i]) + " ";
return s;
}
template<typename T>
inline string fwidth2(const T& x,const size_t wdt,const bool prefix)
{
string s=tostring(x);
if(wdt>1024 || s.size()>=wdt) return s;
size_t n=wdt-s.size();
while(n>0) {
if (prefix) s=' '+ s;
else s+=' ';
--n;
}
return s;
}
template<typename T>
inline string fwidth(const T& x,const size_t wdt=8,const size_t tailwdt=4)
{
string s=tostring(x);
if(wdt>1024 || tailwdt>1024 || s.size()>wdt+tailwdt) return s;
const size_t m=min(s.find('.'),s.find(' '));
if (m==string::npos) {
s=fwidth2(s,wdt,true);
return fwidth2(s,wdt+tailwdt,false);
}
else{
if(wdt<m) {
return s;
}
assert( wdt>=m );
size_t n1=wdt-m;
while(n1>0) {s= ' ' + s; --n1;}
return fwidth2(s,wdt+tailwdt,false);
}
}
inline string strip(const string& s,const char ch=' ')
{
const size_t n=s.find_first_not_of(ch);
const size_t m=s.find_last_not_of (ch);
if (n==string::npos || m==string::npos) return "";
return s.substr(n,m-n+1);
}
inline string replace(const string& s,const string& f,const string& r)
{
if (f.size()==0) return s;
const size_t n=s.find(f);
if (n==string::npos) return s;
else return replace(s.substr(0,n) + r + s.substr(n+f.size()),f,r);
}
inline string indent(const string& s,const string& indent)
{
string t,q=s;
while(q.size()){
const string::size_type n=q.find_first_of("\n");
t += indent + q.substr(0,n) + "\n";
if (n==string::npos) break;
assert(n+1<=q.size());
q = q.substr(n+1,q.size());
}
return t;
}
inline string removerems(const string& s,const string rem)
{
const size_t n=s.find_first_of(rem);
return s.substr(0,n);
}
inline string suffix(const int n)
{
assert(n>=0 && n<999);
if (n<=9) return "00" + tostring(n);
else if (n<=99) return "0" + tostring(n);
else return tostring(n);
}
string tail(const string& s,const string& delimiter)
{
const size_t n=s.find_last_of(delimiter);
if (n==string::npos) return s;
else return s.substr(n+delimiter.size(),-1);
}
string tail(const string& s,const char c) {
string t;
t.resize(1);
t[0]=c;
return tail(s,t);
}
template<typename T>
inline ostream& operator<<(ostream& os,const pair<T*,int> x)
{
for(int i=0;i<x.second;++i) os << x.first[i] << " ";
return os;
}
template<typename T>
inline istream& operator>>(istream& is,pair<T*,int> x)
{
for(int i=0;i<x.second;++i) is >> x.first[i];
return is;
}
template<typename T>
inline ostream& operator<<(ostream& s,const vector<T>& x)
{
int i=0;
if (g_tags.serialize) s << "vector: " << x.size() << " { ";
for(typename vector<T>::const_iterator itt=x.begin();itt!=x.end();++itt) {
s << g_tags.preline;
if(g_tags.printnumbers) s << "[" << fwidth(++i,3,0) << "] ";
s << *itt << " " << g_tags.endline;
}
if (g_tags.serialize) s << "} ";
return s;
}
template<typename T>
inline istream& operator>>(istream& s,vector<T>& x)
{
size_t n=0;
string t;
s >> t;
if (t!="vector:") throw_("bad format in vector serialization stream, tag missing");
s >> n >> t;
if (t!="{") throw_("bad format in vector serialization stream, missing begin brace");
x.resize(n);
for(size_t i=0;i<n;++i) s >> x[i];
s >> t;
if (t!="}") throw_("bad format in vector serialization stream, missing end brace");
return s;
}
template<typename T>
inline ostream& operator<<(ostream& s,const list<T>& x)
{
if (g_tags.serialize) s << "list: " << x.size() << " { ";
int i=0;
for(typename list<T>::const_iterator itt=x.begin();itt!=x.end();++itt){
s << g_tags.preline;
if(g_tags.printnumbers) s << "[" << fwidth(++i,3,0) << "] ";
s << *itt << " " << g_tags.endline;
}
if (g_tags.serialize) s << "} ";
return s;
}
template<typename T>
inline istream& operator>>(istream& s,list<T>& x)
{
size_t n=0;
string t;
s >> t;
if (t!="list:") throw_("bad format in list serialization stream, tag missing");
s >> n >> t;
if (t!="{") throw_("bad format in list serialization stream, missing begin brace");
for(size_t i=0;i<n;++i) {
T y;
s >> y;
x.push_back(y);
}
s >> t;
if (t!="}") throw_("bad format in list serialization stream, missing end brace");
return s;
}
template<typename T,typename R>
inline ostream& operator<<(ostream& s,const map<T,R>& x)
{
if (g_tags.serialize) s << "map: " << x.size() << " { ";
int i=0;
for(typename map<T,R>::const_iterator itt=x.begin();itt!=x.end();++itt) {
s << g_tags.preline;
if(g_tags.printnumbers) s << "[" << fwidth(++i,3,0) << "] ";
s << fwidth(itt->first,g_tags.prewidth,g_tags.postwidth) << (g_tags.maptags ? " |-> " : " ");
s << fwidth(itt->second,g_tags.prewidth,g_tags.postwidth) << " " << g_tags.endline;
}
if (g_tags.serialize) s << "} ";
return s;
}
template<typename T,typename R>
inline istream& operator>>(istream& s,map<T,R>& x)
{
size_t n=0;
string t;
s >> t;
if (t!="map:") throw_("bad format in map serialization stream, tag missing");
s >> n >> t;
if (t!="{") throw_("bad format in map serialization stream, missing begin brace");
for(size_t i=0;i<n;++i) {
T y;
R z;
s >> y >> z;
if (x.find(y)!=x.end()) throw_("bad stream, key value no unique");
x[y]=z;
}
s >> t;
if (t!="}") throw_("bad format in map serialization stream, missing end brace");
return s;
}
#endif // __STRINGFUNS_H__

View File

@@ -1,54 +0,0 @@
#ifndef __TEMPLATE_FUN__
#define __TEMPLATE_FUN__
#define __stdcall
template<class T>
class Autobool
{
private:
volatile T* m_b;
Autobool(const Autobool&);
void operator=(const Autobool&);
public:
Autobool(volatile T* b) : m_b(b) {assert(m_b && *m_b==false); *m_b=true;}
~Autobool() {assert(m_b && *m_b==true); *m_b=false; m_b=0;}
};
template<class T,class R>
class DeviceAutoClose
{
private:
T m_dev;
R (__stdcall *m_fun)(void *);
bool m_init;
// private Copy CTOR and assignment operator
DeviceAutoClose(const DeviceAutoClose<T,R>&);
void operator=(const DeviceAutoClose<T,R>&);
public:
DeviceAutoClose(T dev,R(__stdcall *fun)(void*)) : m_dev(dev), m_fun(fun), m_init(true)
{
FUNSTACK;
assert(m_fun!=NULL);
}
~DeviceAutoClose()
{
FUNSTACK;
assert(m_init);
assert(m_fun!=NULL);
if (m_dev!=NULL){
R r=m_fun(m_dev);
if (!r) throw_("DeviceClose() failed"); // throw in DTOR -> bad, bad!
}
m_dev=NULL;
m_fun=NULL;
m_init=false;
}
const T& operator()() const {FUNSTACK; assert(m_init); return m_dev;}
T& operator()() {FUNSTACK; assert(m_init); return m_dev;}
};
#endif // __TEMPLATE_FUN__

View File

@@ -1,34 +0,0 @@
// The code is copyrighted 2008 by Carsten Frigaard.
// All rights placed in public domain under GNU licence V2, 2008
//
// © 2008 Carsten Frigaard. Permission to use, copy, modify, and distribute this software
// and its documentation for any purpose and without fee is hereby granted, provided that
// the above copyright notice appear in all copies and that both that copyright notice
// and this permission notice appear in supporting documentation.
#ifndef __TOOLSFUN_H__
#define __TOOLSFUN__H__
#include <cassert>
#include <ctime>
#include <time.h>
#include <vector>
#include <list>
#include <map>
#include <string>
#include <iostream>
#include <sstream>
#include <fstream>
using namespace std;
#include "exception.h"
#include "stringfun.h"
#include "args.h"
#include "funs.h"
#include "file.h"
#include "configfile.h"
#include "templatefun.h"
#include "reg.h"
#endif // __TOOLSFUN_H__

View File

@@ -1,204 +0,0 @@
#ifndef __USBM_H__
#define __USBM_H__
class USBio
{
private:
HINSTANCE m_hDll;
// Discovery routine
typedef int (__stdcall *USBm_FindDevices_type) ();
// Info about devices
typedef int (__stdcall *USBm_NumberOfDevices_type) (void);
typedef int (__stdcall *USBm_DeviceValid_type) (unsigned char);
typedef int (__stdcall *USBm_DeviceVID_type) (unsigned char device);
typedef int (__stdcall *USBm_DevicePID_type) (unsigned char device);
typedef int (__stdcall *USBm_DeviceDID_type) (unsigned char device);
typedef int (__stdcall *USBm_DeviceMfr_type) (unsigned char, char *);
typedef int (__stdcall *USBm_DeviceProd_type) (unsigned char, char *);
typedef int (__stdcall *USBm_DeviceSer_type) (unsigned char, char *);
// General U4xx functions
typedef int (__stdcall *USBm_InitPorts_type) (unsigned char);
typedef int (__stdcall *USBm_WriteA_type) (unsigned char, unsigned char);
typedef int (__stdcall *USBm_WriteB_type) (unsigned char, unsigned char);
typedef int (__stdcall *USBm_WriteABit_type) (unsigned char, unsigned char, unsigned char);
typedef int (__stdcall *USBm_WriteBBit_type) (unsigned char, unsigned char, unsigned char);
typedef int (__stdcall *USBm_ReadA_type) (unsigned char, unsigned char *);
typedef int (__stdcall *USBm_ReadB_type) (unsigned char, unsigned char *);
typedef int (__stdcall *USBm_SetBit_type) (unsigned char, unsigned char);
typedef int (__stdcall *USBm_ResetBit_type) (unsigned char, unsigned char);
typedef int (__stdcall *USBm_DirectionA_type) (unsigned char, unsigned char, unsigned char);
typedef int (__stdcall *USBm_DirectionB_type) (unsigned char, unsigned char, unsigned char);
typedef int (__stdcall *USBm_StrobeWrite_type) (unsigned char, unsigned char, unsigned char, unsigned char);
typedef int (__stdcall *USBm_StrobeRead_type) (unsigned char, unsigned char *, unsigned char, unsigned char);
typedef int (__stdcall *USBm_StrobeWrite2_type) (unsigned char, unsigned char, unsigned char, unsigned char, unsigned char);
typedef int (__stdcall *USBm_StrobeRead2_type) (unsigned char, unsigned char *, unsigned char, unsigned char, unsigned char);
typedef int (__stdcall *USBm_StrobeWrites_type) (unsigned char, unsigned char *, unsigned char *);
typedef int (__stdcall *USBm_StrobeReads_type) (unsigned char, unsigned char *, unsigned char *);
typedef int (__stdcall *USBm_InitLCD_type) (unsigned char, unsigned char, unsigned char);
typedef int (__stdcall *USBm_LCDCmd_type) (unsigned char, unsigned char);
typedef int (__stdcall *USBm_LCDData_type) (unsigned char, unsigned char);
typedef int (__stdcall *USBm_InitSPI_type) (unsigned char, unsigned char);
typedef int (__stdcall *USBm_SPIMaster_type) (unsigned char, unsigned char *, unsigned char *);
typedef int (__stdcall *USBm_SPISlaveWrite_type) (unsigned char, unsigned char, unsigned char *);
typedef int (__stdcall *USBm_SPISlaveRead_type) (unsigned char, unsigned char *, unsigned char *);
typedef int (__stdcall *USBm_Stepper_type) (unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char, unsigned char);
typedef int (__stdcall *USBm_Reset1Wire_type) (unsigned char, unsigned char *);
typedef int (__stdcall *USBm_Write1Wire_type) (unsigned char, unsigned char);
typedef int (__stdcall *USBm_Read1Wire_type) (unsigned char, unsigned char *);
// DLL string info access
typedef int (__stdcall *USBm_RecentError_type) (char *);
typedef int (__stdcall *USBm_ClearRecentError_type) (void);
typedef int (__stdcall *USBm_DebugString_type) (char *);
typedef int (__stdcall *USBm_Copyright_type) (char *);
typedef int (__stdcall *USBm_About_type) (char *);
typedef int (__stdcall *USBm_Version_type) (char *);
public:
USBio() : m_hDll(0)
{
m_hDll = LoadLibrary("USBm.dll");
if (m_hDll==0) throw_("could not locate USBm.dll");
USBm_FindDevices = (USBm_FindDevices_type)GetProcAddress(m_hDll, "USBm_FindDevices");
USBm_NumberOfDevices = (USBm_NumberOfDevices_type)GetProcAddress(m_hDll, "USBm_NumberOfDevices");
USBm_DeviceValid = (USBm_DeviceValid_type)GetProcAddress(m_hDll, "USBm_DeviceValid");
USBm_DeviceVID = (USBm_DeviceVID_type)GetProcAddress(m_hDll, "USBm_DeviceVID");
USBm_DevicePID = (USBm_DevicePID_type)GetProcAddress(m_hDll, "USBm_DevicePID");
USBm_DeviceDID = (USBm_DeviceDID_type)GetProcAddress(m_hDll, "USBm_DeviceDID");
USBm_DeviceMfr = (USBm_DeviceMfr_type)GetProcAddress(m_hDll, "USBm_DeviceMfr");
USBm_DeviceProd = (USBm_DeviceProd_type)GetProcAddress(m_hDll, "USBm_DeviceProd");
USBm_DeviceSer = (USBm_DeviceSer_type)GetProcAddress(m_hDll, "USBm_DeviceSer");
USBm_InitPorts = (USBm_InitPorts_type)GetProcAddress(m_hDll, "USBm_InitPorts");
USBm_WriteA = (USBm_WriteA_type)GetProcAddress(m_hDll, "USBm_WriteA");
USBm_WriteB = (USBm_WriteB_type)GetProcAddress(m_hDll, "USBm_WriteB");
USBm_WriteABit = (USBm_WriteABit_type)GetProcAddress(m_hDll, "USBm_WriteABit");
USBm_WriteBBit = (USBm_WriteBBit_type)GetProcAddress(m_hDll, "USBm_WriteBBit");
USBm_ReadA = (USBm_ReadA_type)GetProcAddress(m_hDll, "USBm_ReadA");
USBm_ReadB = (USBm_ReadB_type)GetProcAddress(m_hDll, "USBm_ReadB");
USBm_SetBit = (USBm_SetBit_type)GetProcAddress(m_hDll, "USBm_SetBit");
USBm_ResetBit = (USBm_ResetBit_type)GetProcAddress(m_hDll, "USBm_ResetBit");
USBm_DirectionA = (USBm_DirectionA_type)GetProcAddress(m_hDll, "USBm_DirectionA");
USBm_DirectionB = (USBm_DirectionB_type)GetProcAddress(m_hDll, "USBm_DirectionB");
USBm_StrobeWrite = (USBm_StrobeWrite_type)GetProcAddress(m_hDll, "USBm_StrobeWrite");
USBm_StrobeRead = (USBm_StrobeRead_type)GetProcAddress(m_hDll, "USBm_StrobeRead");
USBm_StrobeWrite2 = (USBm_StrobeWrite2_type)GetProcAddress(m_hDll, "USBm_StrobeWrite2");
USBm_StrobeRead2 = (USBm_StrobeRead2_type)GetProcAddress(m_hDll, "USBm_StrobeRead2");
USBm_StrobeWrites = (USBm_StrobeWrites_type)GetProcAddress(m_hDll, "USBm_StrobeWrites");
USBm_StrobeReads = (USBm_StrobeReads_type)GetProcAddress(m_hDll, "USBm_StrobeReads");
USBm_InitLCD = (USBm_InitLCD_type)GetProcAddress(m_hDll, "USBm_InitLCD");
USBm_LCDCmd = (USBm_LCDCmd_type)GetProcAddress(m_hDll, "USBm_LCDCmd");
USBm_LCDData = (USBm_LCDData_type)GetProcAddress(m_hDll, "USBm_LCDData");
USBm_InitSPI = (USBm_InitSPI_type)GetProcAddress(m_hDll, "USBm_InitSPI");
USBm_SPIMaster = (USBm_SPIMaster_type)GetProcAddress(m_hDll, "USBm_SPIMaster");
USBm_SPISlaveWrite = (USBm_SPISlaveWrite_type)GetProcAddress(m_hDll, "USBm_SPISlaveWrite");
USBm_SPISlaveRead = (USBm_SPISlaveRead_type)GetProcAddress(m_hDll, "USBm_SPISlaveRead");
USBm_Stepper = (USBm_Stepper_type)GetProcAddress(m_hDll, "USBm_Stepper");
USBm_Reset1Wire = (USBm_Reset1Wire_type)GetProcAddress(m_hDll, "USBm_Reset1Wire");
USBm_Write1Wire = (USBm_Write1Wire_type)GetProcAddress(m_hDll, "USBm_Write1Wire");
USBm_Read1Wire = (USBm_Read1Wire_type)GetProcAddress(m_hDll, "USBm_Read1Wire");
USBm_RecentError = (USBm_RecentError_type)GetProcAddress(m_hDll, "USBm_RecentError");
USBm_ClearRecentError = (USBm_ClearRecentError_type)GetProcAddress(m_hDll, "USBm_ClearRecentError");
USBm_DebugString = (USBm_DebugString_type)GetProcAddress(m_hDll, "USBm_DebugString");
USBm_Copyright = (USBm_Copyright_type)GetProcAddress(m_hDll, "USBm_Copyright");
USBm_About = (USBm_About_type)GetProcAddress(m_hDll, "USBm_About");
USBm_Version = (USBm_Version_type)GetProcAddress(m_hDll, "USBm_Version");
}
~USBio()
{
assert( m_hDll );
// XXX FreeLibrary(m_hDll);
m_hDll=0;
}
int Devices() const
{
assert( m_hDll );
unsigned char numdev=USBm_NumberOfDevices();
return numdev;
}
string version() const
{
assert( m_hDll );
string s;
char textstr[300];
const int d=Devices();
s = string(" USBm.dll version = ") + USBm_Version(textstr) + "\n";
s += string(" USBm.dll version = ") + textstr + "\n";
USBm_Copyright(textstr);
s += string(" Copyright = ") + textstr + "\n";
USBm_About(textstr);
s += string(" About =") + textstr + "\n";
s += string(" Number of devices = ") + d + "\n";
// Gather info from each discovered device
for(int i=0;i<d;++i){
s += string(" Device[") + i + "]:\n";
s += string(" VID = ") + USBm_DeviceVID(i) + "\n";
USBm_DeviceMfr(i,textstr);
s += string(" Manuf = ") + textstr + "\n";
s += string(" PID = ") + USBm_DevicePID(i) + "\n";
USBm_DeviceProd(i,textstr);
s += string(" Prod = ") + textstr + "\n";
s += string(" DID = ") + USBm_DeviceDID(i) + "\n";
USBm_DeviceSer(i,textstr);
s += string(" Serial = ") + textstr + "\n";
}
return s;
}
USBm_FindDevices_type USBm_FindDevices;
USBm_NumberOfDevices_type USBm_NumberOfDevices;
USBm_DeviceValid_type USBm_DeviceValid;
USBm_DeviceVID_type USBm_DeviceVID;
USBm_DevicePID_type USBm_DevicePID;
USBm_DeviceDID_type USBm_DeviceDID;
USBm_DeviceMfr_type USBm_DeviceMfr;
USBm_DeviceProd_type USBm_DeviceProd;
USBm_DeviceSer_type USBm_DeviceSer;
USBm_InitPorts_type USBm_InitPorts;
USBm_WriteA_type USBm_WriteA;
USBm_WriteB_type USBm_WriteB;
USBm_WriteABit_type USBm_WriteABit;
USBm_WriteBBit_type USBm_WriteBBit;
USBm_ReadA_type USBm_ReadA;
USBm_ReadB_type USBm_ReadB;
USBm_SetBit_type USBm_SetBit;
USBm_ResetBit_type USBm_ResetBit;
USBm_DirectionA_type USBm_DirectionA;
USBm_DirectionB_type USBm_DirectionB;
USBm_StrobeWrite_type USBm_StrobeWrite;
USBm_StrobeRead_type USBm_StrobeRead;
USBm_StrobeWrite2_type USBm_StrobeWrite2;
USBm_StrobeRead2_type USBm_StrobeRead2;
USBm_StrobeWrites_type USBm_StrobeWrites;
USBm_StrobeReads_type USBm_StrobeReads;
USBm_InitLCD_type USBm_InitLCD;
USBm_LCDCmd_type USBm_LCDCmd;
USBm_LCDData_type USBm_LCDData;
USBm_InitSPI_type USBm_InitSPI;
USBm_SPIMaster_type USBm_SPIMaster;
USBm_SPISlaveWrite_type USBm_SPISlaveWrite;
USBm_SPISlaveRead_type USBm_SPISlaveRead;
USBm_Stepper_type USBm_Stepper;
USBm_Reset1Wire_type USBm_Reset1Wire;
USBm_Write1Wire_type USBm_Write1Wire;
USBm_Read1Wire_type USBm_Read1Wire;
USBm_RecentError_type USBm_RecentError;
USBm_ClearRecentError_type USBm_ClearRecentError;
USBm_DebugString_type USBm_DebugString;
USBm_Copyright_type USBm_Copyright;
USBm_About_type USBm_About;
USBm_Version_type USBm_Version;
};
#endif // __USBM_H__

View File

@@ -1,27 +0,0 @@
// Copyright © 2009 MergeIt, Aps.
//
// License LGPLv3+: GNU lesser LGPL version 3 or later <http://gnu.org/licenses/lgpl.html>.
// This is free software: you are free to change and redistribute it.
// There is NO WARRANTY, to the extent permitted by law.
//
// This file is part of wiiscan.
//
// wiiscan is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// any later version.
//
// wiiscan is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with wiiscan. If not, see <http://www.gnu.org/licenses/>.
#include "wiiscan.h"
int main(int argc,char** argv)
{
return Wiiscan::main(argc,argv);
}

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

Binary file not shown.

Binary file not shown.

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>java.itunescontroller</name>
<name>itunescontroller</name>
<comment></comment>
<projects>
</projects>

View File

@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>java.mimis</name>
<name>mimis</name>
<comment></comment>
<projects>
</projects>

View File

@@ -1,246 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.logging;
/**
* <p>A simple logging interface abstracting logging APIs. In order to be
* instantiated successfully by {@link LogFactory}, classes that implement
* this interface must have a constructor that takes a single String
* parameter representing the "name" of this Log.</p>
*
* <p> The six logging levels used by <code>Log</code> are (in order):
* <ol>
* <li>trace (the least serious)</li>
* <li>debug</li>
* <li>info</li>
* <li>warn</li>
* <li>error</li>
* <li>fatal (the most serious)</li>
* </ol>
* The mapping of these log levels to the concepts used by the underlying
* logging system is implementation dependent.
* The implemention should ensure, though, that this ordering behaves
* as expected.</p>
*
* <p>Performance is often a logging concern.
* By examining the appropriate property,
* a component can avoid expensive operations (producing information
* to be logged).</p>
*
* <p> For example,
* <code><pre>
* if (log.isDebugEnabled()) {
* ... do something expensive ...
* log.debug(theResult);
* }
* </pre></code>
* </p>
*
* <p>Configuration of the underlying logging system will generally be done
* external to the Logging APIs, through whatever mechanism is supported by
* that system.</p>
*
* @author <a href="mailto:sanders@apache.org">Scott Sanders</a>
* @author Rod Waldhoff
* @version $Id: Log.java 424107 2006-07-20 23:15:42Z skitching $
*/
public interface Log {
// ----------------------------------------------------- Logging Properties
/**
* <p> Is debug logging currently enabled? </p>
*
* <p> Call this method to prevent having to perform expensive operations
* (for example, <code>String</code> concatenation)
* when the log level is more than debug. </p>
*
* @return true if debug is enabled in the underlying logger.
*/
public boolean isDebugEnabled();
/**
* <p> Is error logging currently enabled? </p>
*
* <p> Call this method to prevent having to perform expensive operations
* (for example, <code>String</code> concatenation)
* when the log level is more than error. </p>
*
* @return true if error is enabled in the underlying logger.
*/
public boolean isErrorEnabled();
/**
* <p> Is fatal logging currently enabled? </p>
*
* <p> Call this method to prevent having to perform expensive operations
* (for example, <code>String</code> concatenation)
* when the log level is more than fatal. </p>
*
* @return true if fatal is enabled in the underlying logger.
*/
public boolean isFatalEnabled();
/**
* <p> Is info logging currently enabled? </p>
*
* <p> Call this method to prevent having to perform expensive operations
* (for example, <code>String</code> concatenation)
* when the log level is more than info. </p>
*
* @return true if info is enabled in the underlying logger.
*/
public boolean isInfoEnabled();
/**
* <p> Is trace logging currently enabled? </p>
*
* <p> Call this method to prevent having to perform expensive operations
* (for example, <code>String</code> concatenation)
* when the log level is more than trace. </p>
*
* @return true if trace is enabled in the underlying logger.
*/
public boolean isTraceEnabled();
/**
* <p> Is warn logging currently enabled? </p>
*
* <p> Call this method to prevent having to perform expensive operations
* (for example, <code>String</code> concatenation)
* when the log level is more than warn. </p>
*
* @return true if warn is enabled in the underlying logger.
*/
public boolean isWarnEnabled();
// -------------------------------------------------------- Logging Methods
/**
* <p> Log a message with trace log level. </p>
*
* @param message log this message
*/
public void trace(Object message);
/**
* <p> Log an error with trace log level. </p>
*
* @param message log this message
* @param t log this cause
*/
public void trace(Object message, Throwable t);
/**
* <p> Log a message with debug log level. </p>
*
* @param message log this message
*/
public void debug(Object message);
/**
* <p> Log an error with debug log level. </p>
*
* @param message log this message
* @param t log this cause
*/
public void debug(Object message, Throwable t);
/**
* <p> Log a message with info log level. </p>
*
* @param message log this message
*/
public void info(Object message);
/**
* <p> Log an error with info log level. </p>
*
* @param message log this message
* @param t log this cause
*/
public void info(Object message, Throwable t);
/**
* <p> Log a message with warn log level. </p>
*
* @param message log this message
*/
public void warn(Object message);
/**
* <p> Log an error with warn log level. </p>
*
* @param message log this message
* @param t log this cause
*/
public void warn(Object message, Throwable t);
/**
* <p> Log a message with error log level. </p>
*
* @param message log this message
*/
public void error(Object message);
/**
* <p> Log an error with error log level. </p>
*
* @param message log this message
* @param t log this cause
*/
public void error(Object message, Throwable t);
/**
* <p> Log a message with fatal log level. </p>
*
* @param message log this message
*/
public void fatal(Object message);
/**
* <p> Log an error with fatal log level. </p>
*
* @param message log this message
* @param t log this cause
*/
public void fatal(Object message, Throwable t);
}

View File

@@ -1,98 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.logging;
/**
* <p>An exception that is thrown only if a suitable <code>LogFactory</code>
* or <code>Log</code> instance cannot be created by the corresponding
* factory methods.</p>
*
* @author Craig R. McClanahan
* @version $Revision: 424107 $ $Date: 2006-07-21 01:15:42 +0200 (fr, 21 jul 2006) $
*/
public class LogConfigurationException extends RuntimeException {
/**
* Construct a new exception with <code>null</code> as its detail message.
*/
public LogConfigurationException() {
super();
}
/**
* Construct a new exception with the specified detail message.
*
* @param message The detail message
*/
public LogConfigurationException(String message) {
super(message);
}
/**
* Construct a new exception with the specified cause and a derived
* detail message.
*
* @param cause The underlying cause
*/
public LogConfigurationException(Throwable cause) {
this((cause == null) ? null : cause.toString(), cause);
}
/**
* Construct a new exception with the specified detail message and cause.
*
* @param message The detail message
* @param cause The underlying cause
*/
public LogConfigurationException(String message, Throwable cause) {
super(message + " (Caused by " + cause + ")");
this.cause = cause; // Two-argument version requires JDK 1.4 or later
}
/**
* The underlying cause of this exception.
*/
protected Throwable cause = null;
/**
* Return the underlying cause of this exception (if any).
*/
public Throwable getCause() {
return (this.cause);
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -1,262 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.logging;
import java.lang.reflect.Constructor;
import java.util.Hashtable;
import org.apache.commons.logging.impl.NoOpLog;
/**
* <p>Factory for creating {@link Log} instances. Applications should call
* the <code>makeNewLogInstance()</code> method to instantiate new instances
* of the configured {@link Log} implementation class.</p>
*
* <p>By default, calling <code>getInstance()</code> will use the following
* algorithm:</p>
* <ul>
* <li>If Log4J is available, return an instance of
* <code>org.apache.commons.logging.impl.Log4JLogger</code>.</li>
* <li>If JDK 1.4 or later is available, return an instance of
* <code>org.apache.commons.logging.impl.Jdk14Logger</code>.</li>
* <li>Otherwise, return an instance of
* <code>org.apache.commons.logging.impl.NoOpLog</code>.</li>
* </ul>
*
* <p>You can change the default behavior in one of two ways:</p>
* <ul>
* <li>On the startup command line, set the system property
* <code>org.apache.commons.logging.log</code> to the name of the
* <code>org.apache.commons.logging.Log</code> implementation class
* you want to use.</li>
* <li>At runtime, call <code>LogSource.setLogImplementation()</code>.</li>
* </ul>
*
* @deprecated Use {@link LogFactory} instead - The default factory
* implementation performs exactly the same algorithm as this class did
*
* @author Rod Waldhoff
* @version $Id: LogSource.java 424107 2006-07-20 23:15:42Z skitching $
*/
public class LogSource {
// ------------------------------------------------------- Class Attributes
static protected Hashtable logs = new Hashtable();
/** Is log4j available (in the current classpath) */
static protected boolean log4jIsAvailable = false;
/** Is JDK 1.4 logging available */
static protected boolean jdk14IsAvailable = false;
/** Constructor for current log class */
static protected Constructor logImplctor = null;
// ----------------------------------------------------- Class Initializers
static {
// Is Log4J Available?
try {
if (null != Class.forName("org.apache.log4j.Logger")) {
log4jIsAvailable = true;
} else {
log4jIsAvailable = false;
}
} catch (Throwable t) {
log4jIsAvailable = false;
}
// Is JDK 1.4 Logging Available?
try {
if ((null != Class.forName("java.util.logging.Logger")) &&
(null != Class.forName("org.apache.commons.logging.impl.Jdk14Logger"))) {
jdk14IsAvailable = true;
} else {
jdk14IsAvailable = false;
}
} catch (Throwable t) {
jdk14IsAvailable = false;
}
// Set the default Log implementation
String name = null;
try {
name = System.getProperty("org.apache.commons.logging.log");
if (name == null) {
name = System.getProperty("org.apache.commons.logging.Log");
}
} catch (Throwable t) {
}
if (name != null) {
try {
setLogImplementation(name);
} catch (Throwable t) {
try {
setLogImplementation
("org.apache.commons.logging.impl.NoOpLog");
} catch (Throwable u) {
;
}
}
} else {
try {
if (log4jIsAvailable) {
setLogImplementation
("org.apache.commons.logging.impl.Log4JLogger");
} else if (jdk14IsAvailable) {
setLogImplementation
("org.apache.commons.logging.impl.Jdk14Logger");
} else {
setLogImplementation
("org.apache.commons.logging.impl.NoOpLog");
}
} catch (Throwable t) {
try {
setLogImplementation
("org.apache.commons.logging.impl.NoOpLog");
} catch (Throwable u) {
;
}
}
}
}
// ------------------------------------------------------------ Constructor
/** Don't allow others to create instances */
private LogSource() {
}
// ---------------------------------------------------------- Class Methods
/**
* Set the log implementation/log implementation factory
* by the name of the class. The given class
* must implement {@link Log}, and provide a constructor that
* takes a single {@link String} argument (containing the name
* of the log).
*/
static public void setLogImplementation(String classname) throws
LinkageError, ExceptionInInitializerError,
NoSuchMethodException, SecurityException,
ClassNotFoundException {
try {
Class logclass = Class.forName(classname);
Class[] argtypes = new Class[1];
argtypes[0] = "".getClass();
logImplctor = logclass.getConstructor(argtypes);
} catch (Throwable t) {
logImplctor = null;
}
}
/**
* Set the log implementation/log implementation factory
* by class. The given class must implement {@link Log},
* and provide a constructor that takes a single {@link String}
* argument (containing the name of the log).
*/
static public void setLogImplementation(Class logclass) throws
LinkageError, ExceptionInInitializerError,
NoSuchMethodException, SecurityException {
Class[] argtypes = new Class[1];
argtypes[0] = "".getClass();
logImplctor = logclass.getConstructor(argtypes);
}
/** Get a <code>Log</code> instance by class name */
static public Log getInstance(String name) {
Log log = (Log) (logs.get(name));
if (null == log) {
log = makeNewLogInstance(name);
logs.put(name, log);
}
return log;
}
/** Get a <code>Log</code> instance by class */
static public Log getInstance(Class clazz) {
return getInstance(clazz.getName());
}
/**
* Create a new {@link Log} implementation, based
* on the given <i>name</i>.
* <p>
* The specific {@link Log} implementation returned
* is determined by the value of the
* <tt>org.apache.commons.logging.log</tt> property.
* The value of <tt>org.apache.commons.logging.log</tt> may be set to
* the fully specified name of a class that implements
* the {@link Log} interface. This class must also
* have a public constructor that takes a single
* {@link String} argument (containing the <i>name</i>
* of the {@link Log} to be constructed.
* <p>
* When <tt>org.apache.commons.logging.log</tt> is not set,
* or when no corresponding class can be found,
* this method will return a Log4JLogger
* if the log4j Logger class is
* available in the {@link LogSource}'s classpath, or a
* Jdk14Logger if we are on a JDK 1.4 or later system, or
* NoOpLog if neither of the above conditions is true.
*
* @param name the log name (or category)
*/
static public Log makeNewLogInstance(String name) {
Log log = null;
try {
Object[] args = new Object[1];
args[0] = name;
log = (Log) (logImplctor.newInstance(args));
} catch (Throwable t) {
log = null;
}
if (null == log) {
log = new NoOpLog(name);
}
return log;
}
/**
* Returns a {@link String} array containing the names of
* all logs known to me.
*/
static public String[] getLogNames() {
return (String[]) (logs.keySet().toArray(new String[logs.size()]));
}
}

View File

@@ -1,292 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.logging.impl;
import org.apache.avalon.framework.logger.Logger;
import org.apache.commons.logging.Log;
/**
* <p>Implementation of commons-logging Log interface that delegates all
* logging calls to the Avalon logging abstraction: the Logger interface.
* </p>
* <p>
* There are two ways in which this class can be used:
* </p>
* <ul>
* <li>the instance can be constructed with an Avalon logger
* (by calling {@link #AvalonLogger(Logger)}). In this case, it acts
* as a simple thin wrapping implementation over the logger. This is
* particularly useful when using a property setter.
* </li>
* <li>the {@link #setDefaultLogger} class property can be called which
* sets the ancesteral Avalon logger for this class. Any <code>AvalonLogger</code>
* instances created through the <code>LogFactory</code> mechanisms will output
* to child loggers of this <code>Logger</code>.
* </li>
* </ul>
* <p>
* <strong>Note:</strong> <code>AvalonLogger</code> does not implement Serializable
* because the constructors available for it make this impossible to achieve in all
* circumstances; there is no way to "reconnect" to an underlying Logger object on
* deserialization if one was just passed in to the constructor of the original
* object. This class <i>was</i> marked Serializable in the 1.0.4 release of
* commons-logging, but this never actually worked (a NullPointerException would
* be thrown as soon as the deserialized object was used), so removing this marker
* is not considered to be an incompatible change.
* </p>
* @author <a href="mailto:neeme@apache.org">Neeme Praks</a>
* @version $Revision: 424107 $ $Date: 2006-07-21 01:15:42 +0200 (fr, 21 jul 2006) $
*/
public class AvalonLogger implements Log {
/** Ancesteral avalon logger */
private static Logger defaultLogger = null;
/** Avalon logger used to perform log */
private transient Logger logger = null;
/**
* Constructs an <code>AvalonLogger</code> that outputs to the given
* <code>Logger</code> instance.
* @param logger the avalon logger implementation to delegate to
*/
public AvalonLogger(Logger logger) {
this.logger = logger;
}
/**
* Constructs an <code>AvalonLogger</code> that will log to a child
* of the <code>Logger</code> set by calling {@link #setDefaultLogger}.
* @param name the name of the avalon logger implementation to delegate to
*/
public AvalonLogger(String name) {
if (defaultLogger == null)
throw new NullPointerException("default logger has to be specified if this constructor is used!");
this.logger = defaultLogger.getChildLogger(name);
}
/**
* Gets the Avalon logger implementation used to perform logging.
* @return avalon logger implementation
*/
public Logger getLogger() {
return logger;
}
/**
* Sets the ancesteral Avalon logger from which the delegating loggers
* will descend.
* @param logger the default avalon logger,
* in case there is no logger instance supplied in constructor
*/
public static void setDefaultLogger(Logger logger) {
defaultLogger = logger;
}
/**
* Logs a message with
* <code>org.apache.avalon.framework.logger.Logger.debug</code>.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#debug(Object, Throwable)
*/
public void debug(Object message, Throwable t) {
if (getLogger().isDebugEnabled()) getLogger().debug(String.valueOf(message), t);
}
/**
* Logs a message with
* <code>org.apache.avalon.framework.logger.Logger.debug</code>.
*
* @param message to log.
* @see org.apache.commons.logging.Log#debug(Object)
*/
public void debug(Object message) {
if (getLogger().isDebugEnabled()) getLogger().debug(String.valueOf(message));
}
/**
* Logs a message with
* <code>org.apache.avalon.framework.logger.Logger.error</code>.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#error(Object, Throwable)
*/
public void error(Object message, Throwable t) {
if (getLogger().isErrorEnabled()) getLogger().error(String.valueOf(message), t);
}
/**
* Logs a message with
* <code>org.apache.avalon.framework.logger.Logger.error</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#error(Object)
*/
public void error(Object message) {
if (getLogger().isErrorEnabled()) getLogger().error(String.valueOf(message));
}
/**
* Logs a message with
* <code>org.apache.avalon.framework.logger.Logger.fatalError</code>.
*
* @param message to log.
* @param t log this cause.
* @see org.apache.commons.logging.Log#fatal(Object, Throwable)
*/
public void fatal(Object message, Throwable t) {
if (getLogger().isFatalErrorEnabled()) getLogger().fatalError(String.valueOf(message), t);
}
/**
* Logs a message with
* <code>org.apache.avalon.framework.logger.Logger.fatalError</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#fatal(Object)
*/
public void fatal(Object message) {
if (getLogger().isFatalErrorEnabled()) getLogger().fatalError(String.valueOf(message));
}
/**
* Logs a message with
* <code>org.apache.avalon.framework.logger.Logger.info</code>.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#info(Object, Throwable)
*/
public void info(Object message, Throwable t) {
if (getLogger().isInfoEnabled()) getLogger().info(String.valueOf(message), t);
}
/**
* Logs a message with
* <code>org.apache.avalon.framework.logger.Logger.info</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#info(Object)
*/
public void info(Object message) {
if (getLogger().isInfoEnabled()) getLogger().info(String.valueOf(message));
}
/**
* Is logging to
* <code>org.apache.avalon.framework.logger.Logger.debug</code> enabled?
* @see org.apache.commons.logging.Log#isDebugEnabled()
*/
public boolean isDebugEnabled() {
return getLogger().isDebugEnabled();
}
/**
* Is logging to
* <code>org.apache.avalon.framework.logger.Logger.error</code> enabled?
* @see org.apache.commons.logging.Log#isErrorEnabled()
*/
public boolean isErrorEnabled() {
return getLogger().isErrorEnabled();
}
/**
* Is logging to
* <code>org.apache.avalon.framework.logger.Logger.fatalError</code> enabled?
* @see org.apache.commons.logging.Log#isFatalEnabled()
*/
public boolean isFatalEnabled() {
return getLogger().isFatalErrorEnabled();
}
/**
* Is logging to
* <code>org.apache.avalon.framework.logger.Logger.info</code> enabled?
* @see org.apache.commons.logging.Log#isInfoEnabled()
*/
public boolean isInfoEnabled() {
return getLogger().isInfoEnabled();
}
/**
* Is logging to
* <code>org.apache.avalon.framework.logger.Logger.debug</code> enabled?
* @see org.apache.commons.logging.Log#isTraceEnabled()
*/
public boolean isTraceEnabled() {
return getLogger().isDebugEnabled();
}
/**
* Is logging to
* <code>org.apache.avalon.framework.logger.Logger.warn</code> enabled?
* @see org.apache.commons.logging.Log#isWarnEnabled()
*/
public boolean isWarnEnabled() {
return getLogger().isWarnEnabled();
}
/**
* Logs a message with
* <code>org.apache.avalon.framework.logger.Logger.debug</code>.
*
* @param message to log.
* @param t log this cause.
* @see org.apache.commons.logging.Log#trace(Object, Throwable)
*/
public void trace(Object message, Throwable t) {
if (getLogger().isDebugEnabled()) getLogger().debug(String.valueOf(message), t);
}
/**
* Logs a message with
* <code>org.apache.avalon.framework.logger.Logger.debug</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#trace(Object)
*/
public void trace(Object message) {
if (getLogger().isDebugEnabled()) getLogger().debug(String.valueOf(message));
}
/**
* Logs a message with
* <code>org.apache.avalon.framework.logger.Logger.warn</code>.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#warn(Object, Throwable)
*/
public void warn(Object message, Throwable t) {
if (getLogger().isWarnEnabled()) getLogger().warn(String.valueOf(message), t);
}
/**
* Logs a message with
* <code>org.apache.avalon.framework.logger.Logger.warn</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#warn(Object)
*/
public void warn(Object message) {
if (getLogger().isWarnEnabled()) getLogger().warn(String.valueOf(message));
}
}

View File

@@ -1,335 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.logging.impl;
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.LogRecord;
import java.util.StringTokenizer;
import java.io.PrintWriter;
import java.io.StringWriter;
import org.apache.commons.logging.Log;
/**
* <p>Implementation of the <code>org.apache.commons.logging.Log</code>
* interface that wraps the standard JDK logging mechanisms that are
* available in SourceForge's Lumberjack for JDKs prior to 1.4.</p>
*
* @author <a href="mailto:sanders@apache.org">Scott Sanders</a>
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
* @author <a href="mailto:vince256@comcast.net">Vince Eagen</a>
* @version $Revision: 424107 $ $Date: 2006-07-21 01:15:42 +0200 (fr, 21 jul 2006) $
* @since 1.1
*/
public class Jdk13LumberjackLogger implements Log, Serializable {
// ----------------------------------------------------- Instance Variables
/**
* The underlying Logger implementation we are using.
*/
protected transient Logger logger = null;
protected String name = null;
private String sourceClassName = "unknown";
private String sourceMethodName = "unknown";
private boolean classAndMethodFound = false;
/**
* This member variable simply ensures that any attempt to initialise
* this class in a pre-1.4 JVM will result in an ExceptionInInitializerError.
* It must not be private, as an optimising compiler could detect that it
* is not used and optimise it away.
*/
protected static final Level dummyLevel = Level.FINE;
// ----------------------------------------------------------- Constructors
/**
* Construct a named instance of this Logger.
*
* @param name Name of the logger to be constructed
*/
public Jdk13LumberjackLogger(String name) {
this.name = name;
logger = getLogger();
}
// --------------------------------------------------------- Public Methods
private void log( Level level, String msg, Throwable ex ) {
if( getLogger().isLoggable(level) ) {
LogRecord record = new LogRecord(level, msg);
if( !classAndMethodFound ) {
getClassAndMethod();
}
record.setSourceClassName(sourceClassName);
record.setSourceMethodName(sourceMethodName);
if( ex != null ) {
record.setThrown(ex);
}
getLogger().log(record);
}
}
/**
* <p>Gets the class and method by looking at the stack trace for the
* first entry that is not this class.</p>
*/
private void getClassAndMethod() {
try {
Throwable throwable = new Throwable();
throwable.fillInStackTrace();
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter( stringWriter );
throwable.printStackTrace( printWriter );
String traceString = stringWriter.getBuffer().toString();
StringTokenizer tokenizer =
new StringTokenizer( traceString, "\n" );
tokenizer.nextToken();
String line = tokenizer.nextToken();
while ( line.indexOf( this.getClass().getName() ) == -1 ) {
line = tokenizer.nextToken();
}
while ( line.indexOf( this.getClass().getName() ) >= 0 ) {
line = tokenizer.nextToken();
}
int start = line.indexOf( "at " ) + 3;
int end = line.indexOf( '(' );
String temp = line.substring( start, end );
int lastPeriod = temp.lastIndexOf( '.' );
sourceClassName = temp.substring( 0, lastPeriod );
sourceMethodName = temp.substring( lastPeriod + 1 );
} catch ( Exception ex ) {
// ignore - leave class and methodname unknown
}
classAndMethodFound = true;
}
/**
* Logs a message with <code>java.util.logging.Level.FINE</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#debug(Object)
*/
public void debug(Object message) {
log(Level.FINE, String.valueOf(message), null);
}
/**
* Logs a message with <code>java.util.logging.Level.FINE</code>.
*
* @param message to log
* @param exception log this cause
* @see org.apache.commons.logging.Log#debug(Object, Throwable)
*/
public void debug(Object message, Throwable exception) {
log(Level.FINE, String.valueOf(message), exception);
}
/**
* Logs a message with <code>java.util.logging.Level.SEVERE</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#error(Object)
*/
public void error(Object message) {
log(Level.SEVERE, String.valueOf(message), null);
}
/**
* Logs a message with <code>java.util.logging.Level.SEVERE</code>.
*
* @param message to log
* @param exception log this cause
* @see org.apache.commons.logging.Log#error(Object, Throwable)
*/
public void error(Object message, Throwable exception) {
log(Level.SEVERE, String.valueOf(message), exception);
}
/**
* Logs a message with <code>java.util.logging.Level.SEVERE</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#fatal(Object)
*/
public void fatal(Object message) {
log(Level.SEVERE, String.valueOf(message), null);
}
/**
* Logs a message with <code>java.util.logging.Level.SEVERE</code>.
*
* @param message to log
* @param exception log this cause
* @see org.apache.commons.logging.Log#fatal(Object, Throwable)
*/
public void fatal(Object message, Throwable exception) {
log(Level.SEVERE, String.valueOf(message), exception);
}
/**
* Return the native Logger instance we are using.
*/
public Logger getLogger() {
if (logger == null) {
logger = Logger.getLogger(name);
}
return (logger);
}
/**
* Logs a message with <code>java.util.logging.Level.INFO</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#info(Object)
*/
public void info(Object message) {
log(Level.INFO, String.valueOf(message), null);
}
/**
* Logs a message with <code>java.util.logging.Level.INFO</code>.
*
* @param message to log
* @param exception log this cause
* @see org.apache.commons.logging.Log#info(Object, Throwable)
*/
public void info(Object message, Throwable exception) {
log(Level.INFO, String.valueOf(message), exception);
}
/**
* Is debug logging currently enabled?
*/
public boolean isDebugEnabled() {
return (getLogger().isLoggable(Level.FINE));
}
/**
* Is error logging currently enabled?
*/
public boolean isErrorEnabled() {
return (getLogger().isLoggable(Level.SEVERE));
}
/**
* Is fatal logging currently enabled?
*/
public boolean isFatalEnabled() {
return (getLogger().isLoggable(Level.SEVERE));
}
/**
* Is info logging currently enabled?
*/
public boolean isInfoEnabled() {
return (getLogger().isLoggable(Level.INFO));
}
/**
* Is trace logging currently enabled?
*/
public boolean isTraceEnabled() {
return (getLogger().isLoggable(Level.FINEST));
}
/**
* Is warn logging currently enabled?
*/
public boolean isWarnEnabled() {
return (getLogger().isLoggable(Level.WARNING));
}
/**
* Logs a message with <code>java.util.logging.Level.FINEST</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#trace(Object)
*/
public void trace(Object message) {
log(Level.FINEST, String.valueOf(message), null);
}
/**
* Logs a message with <code>java.util.logging.Level.FINEST</code>.
*
* @param message to log
* @param exception log this cause
* @see org.apache.commons.logging.Log#trace(Object, Throwable)
*/
public void trace(Object message, Throwable exception) {
log(Level.FINEST, String.valueOf(message), exception);
}
/**
* Logs a message with <code>java.util.logging.Level.WARNING</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#warn(Object)
*/
public void warn(Object message) {
log(Level.WARNING, String.valueOf(message), null);
}
/**
* Logs a message with <code>java.util.logging.Level.WARNING</code>.
*
* @param message to log
* @param exception log this cause
* @see org.apache.commons.logging.Log#warn(Object, Throwable)
*/
public void warn(Object message, Throwable exception) {
log(Level.WARNING, String.valueOf(message), exception);
}
}

View File

@@ -1,304 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.logging.impl;
import java.io.Serializable;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.logging.Log;
/**
* <p>Implementation of the <code>org.apache.commons.logging.Log</code>
* interface that wraps the standard JDK logging mechanisms that were
* introduced in the Merlin release (JDK 1.4).</p>
*
* @author <a href="mailto:sanders@apache.org">Scott Sanders</a>
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
* @author <a href="mailto:donaldp@apache.org">Peter Donald</a>
* @version $Revision: 424107 $ $Date: 2006-07-21 01:15:42 +0200 (fr, 21 jul 2006) $
*/
public class Jdk14Logger implements Log, Serializable {
/**
* This member variable simply ensures that any attempt to initialise
* this class in a pre-1.4 JVM will result in an ExceptionInInitializerError.
* It must not be private, as an optimising compiler could detect that it
* is not used and optimise it away.
*/
protected static final Level dummyLevel = Level.FINE;
// ----------------------------------------------------------- Constructors
/**
* Construct a named instance of this Logger.
*
* @param name Name of the logger to be constructed
*/
public Jdk14Logger(String name) {
this.name = name;
logger = getLogger();
}
// ----------------------------------------------------- Instance Variables
/**
* The underlying Logger implementation we are using.
*/
protected transient Logger logger = null;
/**
* The name of the logger we are wrapping.
*/
protected String name = null;
// --------------------------------------------------------- Public Methods
private void log( Level level, String msg, Throwable ex ) {
Logger logger = getLogger();
if (logger.isLoggable(level)) {
// Hack (?) to get the stack trace.
Throwable dummyException=new Throwable();
StackTraceElement locations[]=dummyException.getStackTrace();
// Caller will be the third element
String cname="unknown";
String method="unknown";
if( locations!=null && locations.length >2 ) {
StackTraceElement caller=locations[2];
cname=caller.getClassName();
method=caller.getMethodName();
}
if( ex==null ) {
logger.logp( level, cname, method, msg );
} else {
logger.logp( level, cname, method, msg, ex );
}
}
}
/**
* Logs a message with <code>java.util.logging.Level.FINE</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#debug(Object)
*/
public void debug(Object message) {
log(Level.FINE, String.valueOf(message), null);
}
/**
* Logs a message with <code>java.util.logging.Level.FINE</code>.
*
* @param message to log
* @param exception log this cause
* @see org.apache.commons.logging.Log#debug(Object, Throwable)
*/
public void debug(Object message, Throwable exception) {
log(Level.FINE, String.valueOf(message), exception);
}
/**
* Logs a message with <code>java.util.logging.Level.SEVERE</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#error(Object)
*/
public void error(Object message) {
log(Level.SEVERE, String.valueOf(message), null);
}
/**
* Logs a message with <code>java.util.logging.Level.SEVERE</code>.
*
* @param message to log
* @param exception log this cause
* @see org.apache.commons.logging.Log#error(Object, Throwable)
*/
public void error(Object message, Throwable exception) {
log(Level.SEVERE, String.valueOf(message), exception);
}
/**
* Logs a message with <code>java.util.logging.Level.SEVERE</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#fatal(Object)
*/
public void fatal(Object message) {
log(Level.SEVERE, String.valueOf(message), null);
}
/**
* Logs a message with <code>java.util.logging.Level.SEVERE</code>.
*
* @param message to log
* @param exception log this cause
* @see org.apache.commons.logging.Log#fatal(Object, Throwable)
*/
public void fatal(Object message, Throwable exception) {
log(Level.SEVERE, String.valueOf(message), exception);
}
/**
* Return the native Logger instance we are using.
*/
public Logger getLogger() {
if (logger == null) {
logger = Logger.getLogger(name);
}
return (logger);
}
/**
* Logs a message with <code>java.util.logging.Level.INFO</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#info(Object)
*/
public void info(Object message) {
log(Level.INFO, String.valueOf(message), null);
}
/**
* Logs a message with <code>java.util.logging.Level.INFO</code>.
*
* @param message to log
* @param exception log this cause
* @see org.apache.commons.logging.Log#info(Object, Throwable)
*/
public void info(Object message, Throwable exception) {
log(Level.INFO, String.valueOf(message), exception);
}
/**
* Is debug logging currently enabled?
*/
public boolean isDebugEnabled() {
return (getLogger().isLoggable(Level.FINE));
}
/**
* Is error logging currently enabled?
*/
public boolean isErrorEnabled() {
return (getLogger().isLoggable(Level.SEVERE));
}
/**
* Is fatal logging currently enabled?
*/
public boolean isFatalEnabled() {
return (getLogger().isLoggable(Level.SEVERE));
}
/**
* Is info logging currently enabled?
*/
public boolean isInfoEnabled() {
return (getLogger().isLoggable(Level.INFO));
}
/**
* Is trace logging currently enabled?
*/
public boolean isTraceEnabled() {
return (getLogger().isLoggable(Level.FINEST));
}
/**
* Is warn logging currently enabled?
*/
public boolean isWarnEnabled() {
return (getLogger().isLoggable(Level.WARNING));
}
/**
* Logs a message with <code>java.util.logging.Level.FINEST</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#trace(Object)
*/
public void trace(Object message) {
log(Level.FINEST, String.valueOf(message), null);
}
/**
* Logs a message with <code>java.util.logging.Level.FINEST</code>.
*
* @param message to log
* @param exception log this cause
* @see org.apache.commons.logging.Log#trace(Object, Throwable)
*/
public void trace(Object message, Throwable exception) {
log(Level.FINEST, String.valueOf(message), exception);
}
/**
* Logs a message with <code>java.util.logging.Level.WARNING</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#warn(Object)
*/
public void warn(Object message) {
log(Level.WARNING, String.valueOf(message), null);
}
/**
* Logs a message with <code>java.util.logging.Level.WARNING</code>.
*
* @param message to log
* @param exception log this cause
* @see org.apache.commons.logging.Log#warn(Object, Throwable)
*/
public void warn(Object message, Throwable exception) {
log(Level.WARNING, String.valueOf(message), exception);
}
}

View File

@@ -1,342 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.logging.impl;
import java.io.Serializable;
import org.apache.commons.logging.Log;
import org.apache.log4j.Logger;
import org.apache.log4j.Priority;
import org.apache.log4j.Level;
/**
* Implementation of {@link Log} that maps directly to a
* <strong>Logger</strong> for log4J version 1.2.
* <p>
* Initial configuration of the corresponding Logger instances should be done
* in the usual manner, as outlined in the Log4J documentation.
* <p>
* The reason this logger is distinct from the 1.3 logger is that in version 1.2
* of Log4J:
* <ul>
* <li>class Logger takes Priority parameters not Level parameters.
* <li>class Level extends Priority
* </ul>
* Log4J1.3 is expected to change Level so it no longer extends Priority, which is
* a non-binary-compatible change. The class generated by compiling this code against
* log4j 1.2 will therefore not run against log4j 1.3.
*
* @author <a href="mailto:sanders@apache.org">Scott Sanders</a>
* @author Rod Waldhoff
* @author Robert Burrell Donkin
* @version $Id: Log4JLogger.java 479747 2006-11-27 20:15:01Z dennisl $
*/
public class Log4JLogger implements Log, Serializable {
// ------------------------------------------------------------- Attributes
/** The fully qualified name of the Log4JLogger class. */
private static final String FQCN = Log4JLogger.class.getName();
/** Log to this logger */
private transient Logger logger = null;
/** Logger name */
private String name = null;
private static Priority traceLevel;
// ------------------------------------------------------------
// Static Initializer.
//
// Note that this must come after the static variable declarations
// otherwise initialiser expressions associated with those variables
// will override any settings done here.
//
// Verify that log4j is available, and that it is version 1.2.
// If an ExceptionInInitializerError is generated, then LogFactoryImpl
// will treat that as meaning that the appropriate underlying logging
// library is just not present - if discovery is in progress then
// discovery will continue.
// ------------------------------------------------------------
static {
if (!Priority.class.isAssignableFrom(Level.class)) {
// nope, this is log4j 1.3, so force an ExceptionInInitializerError
throw new InstantiationError("Log4J 1.2 not available");
}
// Releases of log4j1.2 >= 1.2.12 have Priority.TRACE available, earlier
// versions do not. If TRACE is not available, then we have to map
// calls to Log.trace(...) onto the DEBUG level.
try {
traceLevel = (Priority) Level.class.getDeclaredField("TRACE").get(null);
} catch(Exception ex) {
// ok, trace not available
traceLevel = Priority.DEBUG;
}
}
// ------------------------------------------------------------ Constructor
public Log4JLogger() {
}
/**
* Base constructor.
*/
public Log4JLogger(String name) {
this.name = name;
this.logger = getLogger();
}
/**
* For use with a log4j factory.
*/
public Log4JLogger(Logger logger ) {
if (logger == null) {
throw new IllegalArgumentException(
"Warning - null logger in constructor; possible log4j misconfiguration.");
}
this.name = logger.getName();
this.logger=logger;
}
// ---------------------------------------------------------
// Implementation
//
// Note that in the methods below the Priority class is used to define
// levels even though the Level class is supported in 1.2. This is done
// so that at compile time the call definitely resolves to a call to
// a method that takes a Priority rather than one that takes a Level.
//
// The Category class (and hence its subclass Logger) in version 1.2 only
// has methods that take Priority objects. The Category class (and hence
// Logger class) in version 1.3 has methods that take both Priority and
// Level objects. This means that if we use Level here, and compile
// against log4j 1.3 then calls would be bound to the versions of
// methods taking Level objects and then would fail to run against
// version 1.2 of log4j.
// ---------------------------------------------------------
/**
* Logs a message with <code>org.apache.log4j.Priority.TRACE</code>.
* When using a log4j version that does not support the <code>TRACE</code>
* level, the message will be logged at the <code>DEBUG</code> level.
*
* @param message to log
* @see org.apache.commons.logging.Log#trace(Object)
*/
public void trace(Object message) {
getLogger().log(FQCN, traceLevel, message, null );
}
/**
* Logs a message with <code>org.apache.log4j.Priority.TRACE</code>.
* When using a log4j version that does not support the <code>TRACE</code>
* level, the message will be logged at the <code>DEBUG</code> level.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#trace(Object, Throwable)
*/
public void trace(Object message, Throwable t) {
getLogger().log(FQCN, traceLevel, message, t );
}
/**
* Logs a message with <code>org.apache.log4j.Priority.DEBUG</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#debug(Object)
*/
public void debug(Object message) {
getLogger().log(FQCN, Priority.DEBUG, message, null );
}
/**
* Logs a message with <code>org.apache.log4j.Priority.DEBUG</code>.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#debug(Object, Throwable)
*/
public void debug(Object message, Throwable t) {
getLogger().log(FQCN, Priority.DEBUG, message, t );
}
/**
* Logs a message with <code>org.apache.log4j.Priority.INFO</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#info(Object)
*/
public void info(Object message) {
getLogger().log(FQCN, Priority.INFO, message, null );
}
/**
* Logs a message with <code>org.apache.log4j.Priority.INFO</code>.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#info(Object, Throwable)
*/
public void info(Object message, Throwable t) {
getLogger().log(FQCN, Priority.INFO, message, t );
}
/**
* Logs a message with <code>org.apache.log4j.Priority.WARN</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#warn(Object)
*/
public void warn(Object message) {
getLogger().log(FQCN, Priority.WARN, message, null );
}
/**
* Logs a message with <code>org.apache.log4j.Priority.WARN</code>.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#warn(Object, Throwable)
*/
public void warn(Object message, Throwable t) {
getLogger().log(FQCN, Priority.WARN, message, t );
}
/**
* Logs a message with <code>org.apache.log4j.Priority.ERROR</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#error(Object)
*/
public void error(Object message) {
getLogger().log(FQCN, Priority.ERROR, message, null );
}
/**
* Logs a message with <code>org.apache.log4j.Priority.ERROR</code>.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#error(Object, Throwable)
*/
public void error(Object message, Throwable t) {
getLogger().log(FQCN, Priority.ERROR, message, t );
}
/**
* Logs a message with <code>org.apache.log4j.Priority.FATAL</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#fatal(Object)
*/
public void fatal(Object message) {
getLogger().log(FQCN, Priority.FATAL, message, null );
}
/**
* Logs a message with <code>org.apache.log4j.Priority.FATAL</code>.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#fatal(Object, Throwable)
*/
public void fatal(Object message, Throwable t) {
getLogger().log(FQCN, Priority.FATAL, message, t );
}
/**
* Return the native Logger instance we are using.
*/
public Logger getLogger() {
if (logger == null) {
logger = Logger.getLogger(name);
}
return (this.logger);
}
/**
* Check whether the Log4j Logger used is enabled for <code>DEBUG</code> priority.
*/
public boolean isDebugEnabled() {
return getLogger().isDebugEnabled();
}
/**
* Check whether the Log4j Logger used is enabled for <code>ERROR</code> priority.
*/
public boolean isErrorEnabled() {
return getLogger().isEnabledFor(Priority.ERROR);
}
/**
* Check whether the Log4j Logger used is enabled for <code>FATAL</code> priority.
*/
public boolean isFatalEnabled() {
return getLogger().isEnabledFor(Priority.FATAL);
}
/**
* Check whether the Log4j Logger used is enabled for <code>INFO</code> priority.
*/
public boolean isInfoEnabled() {
return getLogger().isInfoEnabled();
}
/**
* Check whether the Log4j Logger used is enabled for <code>TRACE</code> priority.
* When using a log4j version that does not support the TRACE level, this call
* will report whether <code>DEBUG</code> is enabled or not.
*/
public boolean isTraceEnabled() {
return getLogger().isEnabledFor(traceLevel);
}
/**
* Check whether the Log4j Logger used is enabled for <code>WARN</code> priority.
*/
public boolean isWarnEnabled() {
return getLogger().isEnabledFor(Priority.WARN);
}
}

View File

@@ -1,294 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.logging.impl;
import java.io.Serializable;
import org.apache.log.Logger;
import org.apache.log.Hierarchy;
import org.apache.commons.logging.Log;
/**
* <p>Implementation of <code>org.apache.commons.logging.Log</code>
* that wraps the <a href="http://avalon.apache.org/logkit/">avalon-logkit</a>
* logging system. Configuration of <code>LogKit</code> is left to the user.
* </p>
*
* <p><code>LogKit</code> accepts only <code>String</code> messages.
* Therefore, this implementation converts object messages into strings
* by called their <code>toString()</code> method before logging them.</p>
*
* @author <a href="mailto:sanders@apache.org">Scott Sanders</a>
* @author Robert Burrell Donkin
* @version $Id: LogKitLogger.java 424107 2006-07-20 23:15:42Z skitching $
*/
public class LogKitLogger implements Log, Serializable {
// ------------------------------------------------------------- Attributes
/** Logging goes to this <code>LogKit</code> logger */
protected transient Logger logger = null;
/** Name of this logger */
protected String name = null;
// ------------------------------------------------------------ Constructor
/**
* Construct <code>LogKitLogger</code> which wraps the <code>LogKit</code>
* logger with given name.
*
* @param name log name
*/
public LogKitLogger(String name) {
this.name = name;
this.logger = getLogger();
}
// --------------------------------------------------------- Public Methods
/**
* <p>Return the underlying Logger we are using.</p>
*/
public Logger getLogger() {
if (logger == null) {
logger = Hierarchy.getDefaultHierarchy().getLoggerFor(name);
}
return (logger);
}
// ----------------------------------------------------- Log Implementation
/**
* Logs a message with <code>org.apache.log.Priority.DEBUG</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#trace(Object)
*/
public void trace(Object message) {
debug(message);
}
/**
* Logs a message with <code>org.apache.log.Priority.DEBUG</code>.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#trace(Object, Throwable)
*/
public void trace(Object message, Throwable t) {
debug(message, t);
}
/**
* Logs a message with <code>org.apache.log.Priority.DEBUG</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#debug(Object)
*/
public void debug(Object message) {
if (message != null) {
getLogger().debug(String.valueOf(message));
}
}
/**
* Logs a message with <code>org.apache.log.Priority.DEBUG</code>.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#debug(Object, Throwable)
*/
public void debug(Object message, Throwable t) {
if (message != null) {
getLogger().debug(String.valueOf(message), t);
}
}
/**
* Logs a message with <code>org.apache.log.Priority.INFO</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#info(Object)
*/
public void info(Object message) {
if (message != null) {
getLogger().info(String.valueOf(message));
}
}
/**
* Logs a message with <code>org.apache.log.Priority.INFO</code>.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#info(Object, Throwable)
*/
public void info(Object message, Throwable t) {
if (message != null) {
getLogger().info(String.valueOf(message), t);
}
}
/**
* Logs a message with <code>org.apache.log.Priority.WARN</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#warn(Object)
*/
public void warn(Object message) {
if (message != null) {
getLogger().warn(String.valueOf(message));
}
}
/**
* Logs a message with <code>org.apache.log.Priority.WARN</code>.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#warn(Object, Throwable)
*/
public void warn(Object message, Throwable t) {
if (message != null) {
getLogger().warn(String.valueOf(message), t);
}
}
/**
* Logs a message with <code>org.apache.log.Priority.ERROR</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#error(Object)
*/
public void error(Object message) {
if (message != null) {
getLogger().error(String.valueOf(message));
}
}
/**
* Logs a message with <code>org.apache.log.Priority.ERROR</code>.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#error(Object, Throwable)
*/
public void error(Object message, Throwable t) {
if (message != null) {
getLogger().error(String.valueOf(message), t);
}
}
/**
* Logs a message with <code>org.apache.log.Priority.FATAL_ERROR</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#fatal(Object)
*/
public void fatal(Object message) {
if (message != null) {
getLogger().fatalError(String.valueOf(message));
}
}
/**
* Logs a message with <code>org.apache.log.Priority.FATAL_ERROR</code>.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#fatal(Object, Throwable)
*/
public void fatal(Object message, Throwable t) {
if (message != null) {
getLogger().fatalError(String.valueOf(message), t);
}
}
/**
* Checks whether the <code>LogKit</code> logger will log messages of priority <code>DEBUG</code>.
*/
public boolean isDebugEnabled() {
return getLogger().isDebugEnabled();
}
/**
* Checks whether the <code>LogKit</code> logger will log messages of priority <code>ERROR</code>.
*/
public boolean isErrorEnabled() {
return getLogger().isErrorEnabled();
}
/**
* Checks whether the <code>LogKit</code> logger will log messages of priority <code>FATAL_ERROR</code>.
*/
public boolean isFatalEnabled() {
return getLogger().isFatalErrorEnabled();
}
/**
* Checks whether the <code>LogKit</code> logger will log messages of priority <code>INFO</code>.
*/
public boolean isInfoEnabled() {
return getLogger().isInfoEnabled();
}
/**
* Checks whether the <code>LogKit</code> logger will log messages of priority <code>DEBUG</code>.
*/
public boolean isTraceEnabled() {
return getLogger().isDebugEnabled();
}
/**
* Checks whether the <code>LogKit</code> logger will log messages of priority <code>WARN</code>.
*/
public boolean isWarnEnabled() {
return getLogger().isWarnEnabled();
}
}

View File

@@ -1,107 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.logging.impl;
import java.io.Serializable;
import org.apache.commons.logging.Log;
/**
* <p>Trivial implementation of Log that throws away all messages. No
* configurable system properties are supported.</p>
*
* @author <a href="mailto:sanders@apache.org">Scott Sanders</a>
* @author Rod Waldhoff
* @version $Id: NoOpLog.java 424107 2006-07-20 23:15:42Z skitching $
*/
public class NoOpLog implements Log, Serializable {
/** Convenience constructor */
public NoOpLog() { }
/** Base constructor */
public NoOpLog(String name) { }
/** Do nothing */
public void trace(Object message) { }
/** Do nothing */
public void trace(Object message, Throwable t) { }
/** Do nothing */
public void debug(Object message) { }
/** Do nothing */
public void debug(Object message, Throwable t) { }
/** Do nothing */
public void info(Object message) { }
/** Do nothing */
public void info(Object message, Throwable t) { }
/** Do nothing */
public void warn(Object message) { }
/** Do nothing */
public void warn(Object message, Throwable t) { }
/** Do nothing */
public void error(Object message) { }
/** Do nothing */
public void error(Object message, Throwable t) { }
/** Do nothing */
public void fatal(Object message) { }
/** Do nothing */
public void fatal(Object message, Throwable t) { }
/**
* Debug is never enabled.
*
* @return false
*/
public final boolean isDebugEnabled() { return false; }
/**
* Error is never enabled.
*
* @return false
*/
public final boolean isErrorEnabled() { return false; }
/**
* Fatal is never enabled.
*
* @return false
*/
public final boolean isFatalEnabled() { return false; }
/**
* Info is never enabled.
*
* @return false
*/
public final boolean isInfoEnabled() { return false; }
/**
* Trace is never enabled.
*
* @return false
*/
public final boolean isTraceEnabled() { return false; }
/**
* Warn is never enabled.
*
* @return false
*/
public final boolean isWarnEnabled() { return false; }
}

View File

@@ -1,138 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.logging.impl;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import org.apache.commons.logging.LogFactory;
/**
* This class is capable of receiving notifications about the undeployment of
* a webapp, and responds by ensuring that commons-logging releases all
* memory associated with the undeployed webapp.
* <p>
* In general, the WeakHashtable support added in commons-logging release 1.1
* ensures that logging classes do not hold references that prevent an
* undeployed webapp's memory from being garbage-collected even when multiple
* copies of commons-logging are deployed via multiple classloaders (a
* situation that earlier versions had problems with). However there are
* some rare cases where the WeakHashtable approach does not work; in these
* situations specifying this class as a listener for the web application will
* ensure that all references held by commons-logging are fully released.
* <p>
* To use this class, configure the webapp deployment descriptor to call
* this class on webapp undeploy; the contextDestroyed method will tell
* every accessable LogFactory class that the entry in its map for the
* current webapp's context classloader should be cleared.
*
* @since 1.1
*/
public class ServletContextCleaner implements ServletContextListener {
private Class[] RELEASE_SIGNATURE = {ClassLoader.class};
/**
* Invoked when a webapp is undeployed, this tells the LogFactory
* class to release any logging information related to the current
* contextClassloader.
*/
public void contextDestroyed(ServletContextEvent sce) {
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
Object[] params = new Object[1];
params[0] = tccl;
// Walk up the tree of classloaders, finding all the available
// LogFactory classes and releasing any objects associated with
// the tccl (ie the webapp).
//
// When there is only one LogFactory in the classpath, and it
// is within the webapp being undeployed then there is no problem;
// garbage collection works fine.
//
// When there are multiple LogFactory classes in the classpath but
// parent-first classloading is used everywhere, this loop is really
// short. The first instance of LogFactory found will
// be the highest in the classpath, and then no more will be found.
// This is ok, as with this setup this will be the only LogFactory
// holding any data associated with the tccl being released.
//
// When there are multiple LogFactory classes in the classpath and
// child-first classloading is used in any classloader, then multiple
// LogFactory instances may hold info about this TCCL; whenever the
// webapp makes a call into a class loaded via an ancestor classloader
// and that class calls LogFactory the tccl gets registered in
// the LogFactory instance that is visible from the ancestor
// classloader. However the concrete logging library it points
// to is expected to have been loaded via the TCCL, so the
// underlying logging lib is only initialised/configured once.
// These references from ancestor LogFactory classes down to
// TCCL classloaders are held via weak references and so should
// be released but there are circumstances where they may not.
// Walking up the classloader ancestry ladder releasing
// the current tccl at each level tree, though, will definitely
// clear any problem references.
ClassLoader loader = tccl;
while (loader != null) {
// Load via the current loader. Note that if the class is not accessable
// via this loader, but is accessable via some ancestor then that class
// will be returned.
try {
Class logFactoryClass = loader.loadClass("org.apache.commons.logging.LogFactory");
Method releaseMethod = logFactoryClass.getMethod("release", RELEASE_SIGNATURE);
releaseMethod.invoke(null, params);
loader = logFactoryClass.getClassLoader().getParent();
} catch(ClassNotFoundException ex) {
// Neither the current classloader nor any of its ancestors could find
// the LogFactory class, so we can stop now.
loader = null;
} catch(NoSuchMethodException ex) {
// This is not expected; every version of JCL has this method
System.err.println("LogFactory instance found which does not support release method!");
loader = null;
} catch(IllegalAccessException ex) {
// This is not expected; every ancestor class should be accessable
System.err.println("LogFactory instance found which is not accessable!");
loader = null;
} catch(InvocationTargetException ex) {
// This is not expected
System.err.println("LogFactory instance release method failed!");
loader = null;
}
}
// Just to be sure, invoke release on the LogFactory that is visible from
// this ServletContextCleaner class too. This should already have been caught
// by the above loop but just in case...
LogFactory.release(tccl);
}
/**
* Invoked when a webapp is deployed. Nothing needs to be done here.
*/
public void contextInitialized(ServletContextEvent sce) {
// do nothing
}
}

View File

@@ -1,721 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.logging.impl;
import java.io.InputStream;
import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Properties;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogConfigurationException;
/**
* <p>Simple implementation of Log that sends all enabled log messages,
* for all defined loggers, to System.err. The following system properties
* are supported to configure the behavior of this logger:</p>
* <ul>
* <li><code>org.apache.commons.logging.simplelog.defaultlog</code> -
* Default logging detail level for all instances of SimpleLog.
* Must be one of ("trace", "debug", "info", "warn", "error", or "fatal").
* If not specified, defaults to "info". </li>
* <li><code>org.apache.commons.logging.simplelog.log.xxxxx</code> -
* Logging detail level for a SimpleLog instance named "xxxxx".
* Must be one of ("trace", "debug", "info", "warn", "error", or "fatal").
* If not specified, the default logging detail level is used.</li>
* <li><code>org.apache.commons.logging.simplelog.showlogname</code> -
* Set to <code>true</code> if you want the Log instance name to be
* included in output messages. Defaults to <code>false</code>.</li>
* <li><code>org.apache.commons.logging.simplelog.showShortLogname</code> -
* Set to <code>true</code> if you want the last component of the name to be
* included in output messages. Defaults to <code>true</code>.</li>
* <li><code>org.apache.commons.logging.simplelog.showdatetime</code> -
* Set to <code>true</code> if you want the current date and time
* to be included in output messages. Default is <code>false</code>.</li>
* <li><code>org.apache.commons.logging.simplelog.dateTimeFormat</code> -
* The date and time format to be used in the output messages.
* The pattern describing the date and time format is the same that is
* used in <code>java.text.SimpleDateFormat</code>. If the format is not
* specified or is invalid, the default format is used.
* The default format is <code>yyyy/MM/dd HH:mm:ss:SSS zzz</code>.</li>
* </ul>
*
* <p>In addition to looking for system properties with the names specified
* above, this implementation also checks for a class loader resource named
* <code>"simplelog.properties"</code>, and includes any matching definitions
* from this resource (if it exists).</p>
*
* @author <a href="mailto:sanders@apache.org">Scott Sanders</a>
* @author Rod Waldhoff
* @author Robert Burrell Donkin
*
* @version $Id: SimpleLog.java 581090 2007-10-01 22:01:06Z dennisl $
*/
public class SimpleLog implements Log, Serializable {
// ------------------------------------------------------- Class Attributes
/** All system properties used by <code>SimpleLog</code> start with this */
static protected final String systemPrefix =
"org.apache.commons.logging.simplelog.";
/** Properties loaded from simplelog.properties */
static protected final Properties simpleLogProps = new Properties();
/** The default format to use when formating dates */
static protected final String DEFAULT_DATE_TIME_FORMAT =
"yyyy/MM/dd HH:mm:ss:SSS zzz";
/** Include the instance name in the log message? */
static protected boolean showLogName = false;
/** Include the short name ( last component ) of the logger in the log
* message. Defaults to true - otherwise we'll be lost in a flood of
* messages without knowing who sends them.
*/
static protected boolean showShortName = true;
/** Include the current time in the log message */
static protected boolean showDateTime = false;
/** The date and time format to use in the log message */
static protected String dateTimeFormat = DEFAULT_DATE_TIME_FORMAT;
/**
* Used to format times.
* <p>
* Any code that accesses this object should first obtain a lock on it,
* ie use synchronized(dateFormatter); this requirement was introduced
* in 1.1.1 to fix an existing thread safety bug (SimpleDateFormat.format
* is not thread-safe).
*/
static protected DateFormat dateFormatter = null;
// ---------------------------------------------------- Log Level Constants
/** "Trace" level logging. */
public static final int LOG_LEVEL_TRACE = 1;
/** "Debug" level logging. */
public static final int LOG_LEVEL_DEBUG = 2;
/** "Info" level logging. */
public static final int LOG_LEVEL_INFO = 3;
/** "Warn" level logging. */
public static final int LOG_LEVEL_WARN = 4;
/** "Error" level logging. */
public static final int LOG_LEVEL_ERROR = 5;
/** "Fatal" level logging. */
public static final int LOG_LEVEL_FATAL = 6;
/** Enable all logging levels */
public static final int LOG_LEVEL_ALL = (LOG_LEVEL_TRACE - 1);
/** Enable no logging levels */
public static final int LOG_LEVEL_OFF = (LOG_LEVEL_FATAL + 1);
// ------------------------------------------------------------ Initializer
private static String getStringProperty(String name) {
String prop = null;
try {
prop = System.getProperty(name);
} catch (SecurityException e) {
; // Ignore
}
return (prop == null) ? simpleLogProps.getProperty(name) : prop;
}
private static String getStringProperty(String name, String dephault) {
String prop = getStringProperty(name);
return (prop == null) ? dephault : prop;
}
private static boolean getBooleanProperty(String name, boolean dephault) {
String prop = getStringProperty(name);
return (prop == null) ? dephault : "true".equalsIgnoreCase(prop);
}
// Initialize class attributes.
// Load properties file, if found.
// Override with system properties.
static {
// Add props from the resource simplelog.properties
InputStream in = getResourceAsStream("simplelog.properties");
if(null != in) {
try {
simpleLogProps.load(in);
in.close();
} catch(java.io.IOException e) {
// ignored
}
}
showLogName = getBooleanProperty( systemPrefix + "showlogname", showLogName);
showShortName = getBooleanProperty( systemPrefix + "showShortLogname", showShortName);
showDateTime = getBooleanProperty( systemPrefix + "showdatetime", showDateTime);
if(showDateTime) {
dateTimeFormat = getStringProperty(systemPrefix + "dateTimeFormat",
dateTimeFormat);
try {
dateFormatter = new SimpleDateFormat(dateTimeFormat);
} catch(IllegalArgumentException e) {
// If the format pattern is invalid - use the default format
dateTimeFormat = DEFAULT_DATE_TIME_FORMAT;
dateFormatter = new SimpleDateFormat(dateTimeFormat);
}
}
}
// ------------------------------------------------------------- Attributes
/** The name of this simple log instance */
protected String logName = null;
/** The current log level */
protected int currentLogLevel;
/** The short name of this simple log instance */
private String shortLogName = null;
// ------------------------------------------------------------ Constructor
/**
* Construct a simple log with given name.
*
* @param name log name
*/
public SimpleLog(String name) {
logName = name;
// Set initial log level
// Used to be: set default log level to ERROR
// IMHO it should be lower, but at least info ( costin ).
setLevel(SimpleLog.LOG_LEVEL_INFO);
// Set log level from properties
String lvl = getStringProperty(systemPrefix + "log." + logName);
int i = String.valueOf(name).lastIndexOf(".");
while(null == lvl && i > -1) {
name = name.substring(0,i);
lvl = getStringProperty(systemPrefix + "log." + name);
i = String.valueOf(name).lastIndexOf(".");
}
if(null == lvl) {
lvl = getStringProperty(systemPrefix + "defaultlog");
}
if("all".equalsIgnoreCase(lvl)) {
setLevel(SimpleLog.LOG_LEVEL_ALL);
} else if("trace".equalsIgnoreCase(lvl)) {
setLevel(SimpleLog.LOG_LEVEL_TRACE);
} else if("debug".equalsIgnoreCase(lvl)) {
setLevel(SimpleLog.LOG_LEVEL_DEBUG);
} else if("info".equalsIgnoreCase(lvl)) {
setLevel(SimpleLog.LOG_LEVEL_INFO);
} else if("warn".equalsIgnoreCase(lvl)) {
setLevel(SimpleLog.LOG_LEVEL_WARN);
} else if("error".equalsIgnoreCase(lvl)) {
setLevel(SimpleLog.LOG_LEVEL_ERROR);
} else if("fatal".equalsIgnoreCase(lvl)) {
setLevel(SimpleLog.LOG_LEVEL_FATAL);
} else if("off".equalsIgnoreCase(lvl)) {
setLevel(SimpleLog.LOG_LEVEL_OFF);
}
}
// -------------------------------------------------------- Properties
/**
* <p> Set logging level. </p>
*
* @param currentLogLevel new logging level
*/
public void setLevel(int currentLogLevel) {
this.currentLogLevel = currentLogLevel;
}
/**
* <p> Get logging level. </p>
*/
public int getLevel() {
return currentLogLevel;
}
// -------------------------------------------------------- Logging Methods
/**
* <p> Do the actual logging.
* This method assembles the message
* and then calls <code>write()</code> to cause it to be written.</p>
*
* @param type One of the LOG_LEVEL_XXX constants defining the log level
* @param message The message itself (typically a String)
* @param t The exception whose stack trace should be logged
*/
protected void log(int type, Object message, Throwable t) {
// Use a string buffer for better performance
StringBuffer buf = new StringBuffer();
// Append date-time if so configured
if(showDateTime) {
Date now = new Date();
String dateText;
synchronized(dateFormatter) {
dateText = dateFormatter.format(now);
}
buf.append(dateText);
buf.append(" ");
}
// Append a readable representation of the log level
switch(type) {
case SimpleLog.LOG_LEVEL_TRACE: buf.append("[TRACE] "); break;
case SimpleLog.LOG_LEVEL_DEBUG: buf.append("[DEBUG] "); break;
case SimpleLog.LOG_LEVEL_INFO: buf.append("[INFO] "); break;
case SimpleLog.LOG_LEVEL_WARN: buf.append("[WARN] "); break;
case SimpleLog.LOG_LEVEL_ERROR: buf.append("[ERROR] "); break;
case SimpleLog.LOG_LEVEL_FATAL: buf.append("[FATAL] "); break;
}
// Append the name of the log instance if so configured
if( showShortName) {
if( shortLogName==null ) {
// Cut all but the last component of the name for both styles
shortLogName = logName.substring(logName.lastIndexOf(".") + 1);
shortLogName =
shortLogName.substring(shortLogName.lastIndexOf("/") + 1);
}
buf.append(String.valueOf(shortLogName)).append(" - ");
} else if(showLogName) {
buf.append(String.valueOf(logName)).append(" - ");
}
// Append the message
buf.append(String.valueOf(message));
// Append stack trace if not null
if(t != null) {
buf.append(" <");
buf.append(t.toString());
buf.append(">");
java.io.StringWriter sw= new java.io.StringWriter(1024);
java.io.PrintWriter pw= new java.io.PrintWriter(sw);
t.printStackTrace(pw);
pw.close();
buf.append(sw.toString());
}
// Print to the appropriate destination
write(buf);
}
/**
* <p>Write the content of the message accumulated in the specified
* <code>StringBuffer</code> to the appropriate output destination. The
* default implementation writes to <code>System.err</code>.</p>
*
* @param buffer A <code>StringBuffer</code> containing the accumulated
* text to be logged
*/
protected void write(StringBuffer buffer) {
System.err.println(buffer.toString());
}
/**
* Is the given log level currently enabled?
*
* @param logLevel is this level enabled?
*/
protected boolean isLevelEnabled(int logLevel) {
// log level are numerically ordered so can use simple numeric
// comparison
return (logLevel >= currentLogLevel);
}
// -------------------------------------------------------- Log Implementation
/**
* Logs a message with
* <code>org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_DEBUG</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#debug(Object)
*/
public final void debug(Object message) {
if (isLevelEnabled(SimpleLog.LOG_LEVEL_DEBUG)) {
log(SimpleLog.LOG_LEVEL_DEBUG, message, null);
}
}
/**
* Logs a message with
* <code>org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_DEBUG</code>.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#debug(Object, Throwable)
*/
public final void debug(Object message, Throwable t) {
if (isLevelEnabled(SimpleLog.LOG_LEVEL_DEBUG)) {
log(SimpleLog.LOG_LEVEL_DEBUG, message, t);
}
}
/**
* Logs a message with
* <code>org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_TRACE</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#trace(Object)
*/
public final void trace(Object message) {
if (isLevelEnabled(SimpleLog.LOG_LEVEL_TRACE)) {
log(SimpleLog.LOG_LEVEL_TRACE, message, null);
}
}
/**
* Logs a message with
* <code>org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_TRACE</code>.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#trace(Object, Throwable)
*/
public final void trace(Object message, Throwable t) {
if (isLevelEnabled(SimpleLog.LOG_LEVEL_TRACE)) {
log(SimpleLog.LOG_LEVEL_TRACE, message, t);
}
}
/**
* Logs a message with
* <code>org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_INFO</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#info(Object)
*/
public final void info(Object message) {
if (isLevelEnabled(SimpleLog.LOG_LEVEL_INFO)) {
log(SimpleLog.LOG_LEVEL_INFO,message,null);
}
}
/**
* Logs a message with
* <code>org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_INFO</code>.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#info(Object, Throwable)
*/
public final void info(Object message, Throwable t) {
if (isLevelEnabled(SimpleLog.LOG_LEVEL_INFO)) {
log(SimpleLog.LOG_LEVEL_INFO, message, t);
}
}
/**
* Logs a message with
* <code>org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_WARN</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#warn(Object)
*/
public final void warn(Object message) {
if (isLevelEnabled(SimpleLog.LOG_LEVEL_WARN)) {
log(SimpleLog.LOG_LEVEL_WARN, message, null);
}
}
/**
* Logs a message with
* <code>org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_WARN</code>.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#warn(Object, Throwable)
*/
public final void warn(Object message, Throwable t) {
if (isLevelEnabled(SimpleLog.LOG_LEVEL_WARN)) {
log(SimpleLog.LOG_LEVEL_WARN, message, t);
}
}
/**
* Logs a message with
* <code>org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_ERROR</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#error(Object)
*/
public final void error(Object message) {
if (isLevelEnabled(SimpleLog.LOG_LEVEL_ERROR)) {
log(SimpleLog.LOG_LEVEL_ERROR, message, null);
}
}
/**
* Logs a message with
* <code>org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_ERROR</code>.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#error(Object, Throwable)
*/
public final void error(Object message, Throwable t) {
if (isLevelEnabled(SimpleLog.LOG_LEVEL_ERROR)) {
log(SimpleLog.LOG_LEVEL_ERROR, message, t);
}
}
/**
* Log a message with
* <code>org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_FATAL</code>.
*
* @param message to log
* @see org.apache.commons.logging.Log#fatal(Object)
*/
public final void fatal(Object message) {
if (isLevelEnabled(SimpleLog.LOG_LEVEL_FATAL)) {
log(SimpleLog.LOG_LEVEL_FATAL, message, null);
}
}
/**
* Logs a message with
* <code>org.apache.commons.logging.impl.SimpleLog.LOG_LEVEL_FATAL</code>.
*
* @param message to log
* @param t log this cause
* @see org.apache.commons.logging.Log#fatal(Object, Throwable)
*/
public final void fatal(Object message, Throwable t) {
if (isLevelEnabled(SimpleLog.LOG_LEVEL_FATAL)) {
log(SimpleLog.LOG_LEVEL_FATAL, message, t);
}
}
/**
* <p> Are debug messages currently enabled? </p>
*
* <p> This allows expensive operations such as <code>String</code>
* concatenation to be avoided when the message will be ignored by the
* logger. </p>
*/
public final boolean isDebugEnabled() {
return isLevelEnabled(SimpleLog.LOG_LEVEL_DEBUG);
}
/**
* <p> Are error messages currently enabled? </p>
*
* <p> This allows expensive operations such as <code>String</code>
* concatenation to be avoided when the message will be ignored by the
* logger. </p>
*/
public final boolean isErrorEnabled() {
return isLevelEnabled(SimpleLog.LOG_LEVEL_ERROR);
}
/**
* <p> Are fatal messages currently enabled? </p>
*
* <p> This allows expensive operations such as <code>String</code>
* concatenation to be avoided when the message will be ignored by the
* logger. </p>
*/
public final boolean isFatalEnabled() {
return isLevelEnabled(SimpleLog.LOG_LEVEL_FATAL);
}
/**
* <p> Are info messages currently enabled? </p>
*
* <p> This allows expensive operations such as <code>String</code>
* concatenation to be avoided when the message will be ignored by the
* logger. </p>
*/
public final boolean isInfoEnabled() {
return isLevelEnabled(SimpleLog.LOG_LEVEL_INFO);
}
/**
* <p> Are trace messages currently enabled? </p>
*
* <p> This allows expensive operations such as <code>String</code>
* concatenation to be avoided when the message will be ignored by the
* logger. </p>
*/
public final boolean isTraceEnabled() {
return isLevelEnabled(SimpleLog.LOG_LEVEL_TRACE);
}
/**
* <p> Are warn messages currently enabled? </p>
*
* <p> This allows expensive operations such as <code>String</code>
* concatenation to be avoided when the message will be ignored by the
* logger. </p>
*/
public final boolean isWarnEnabled() {
return isLevelEnabled(SimpleLog.LOG_LEVEL_WARN);
}
/**
* Return the thread context class loader if available.
* Otherwise return null.
*
* The thread context class loader is available for JDK 1.2
* or later, if certain security conditions are met.
*
* @exception LogConfigurationException if a suitable class loader
* cannot be identified.
*/
private static ClassLoader getContextClassLoader()
{
ClassLoader classLoader = null;
if (classLoader == null) {
try {
// Are we running on a JDK 1.2 or later system?
Method method = Thread.class.getMethod("getContextClassLoader",
(Class[]) null);
// Get the thread context class loader (if there is one)
try {
classLoader = (ClassLoader)method.invoke(Thread.currentThread(),
(Class[]) null);
} catch (IllegalAccessException e) {
; // ignore
} catch (InvocationTargetException e) {
/**
* InvocationTargetException is thrown by 'invoke' when
* the method being invoked (getContextClassLoader) throws
* an exception.
*
* getContextClassLoader() throws SecurityException when
* the context class loader isn't an ancestor of the
* calling class's class loader, or if security
* permissions are restricted.
*
* In the first case (not related), we want to ignore and
* keep going. We cannot help but also ignore the second
* with the logic below, but other calls elsewhere (to
* obtain a class loader) will trigger this exception where
* we can make a distinction.
*/
if (e.getTargetException() instanceof SecurityException) {
; // ignore
} else {
// Capture 'e.getTargetException()' exception for details
// alternate: log 'e.getTargetException()', and pass back 'e'.
throw new LogConfigurationException
("Unexpected InvocationTargetException", e.getTargetException());
}
}
} catch (NoSuchMethodException e) {
// Assume we are running on JDK 1.1
; // ignore
}
}
if (classLoader == null) {
classLoader = SimpleLog.class.getClassLoader();
}
// Return the selected class loader
return classLoader;
}
private static InputStream getResourceAsStream(final String name)
{
return (InputStream)AccessController.doPrivileged(
new PrivilegedAction() {
public Object run() {
ClassLoader threadCL = getContextClassLoader();
if (threadCL != null) {
return threadCL.getResourceAsStream(name);
} else {
return ClassLoader.getSystemResourceAsStream(name);
}
}
});
}
}

View File

@@ -1,478 +0,0 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.commons.logging.impl;
import java.lang.ref.ReferenceQueue;
import java.lang.ref.WeakReference;
import java.util.*;
/**
* <p>Implementation of <code>Hashtable</code> that uses <code>WeakReference</code>'s
* to hold its keys thus allowing them to be reclaimed by the garbage collector.
* The associated values are retained using strong references.</p>
*
* <p>This class follows the symantics of <code>Hashtable</code> as closely as
* possible. It therefore does not accept null values or keys.</p>
*
* <p><strong>Note:</strong>
* This is <em>not</em> intended to be a general purpose hash table replacement.
* This implementation is also tuned towards a particular purpose: for use as a replacement
* for <code>Hashtable</code> in <code>LogFactory</code>. This application requires
* good liveliness for <code>get</code> and <code>put</code>. Various tradeoffs
* have been made with this in mind.
* </p>
* <p>
* <strong>Usage:</strong> typical use case is as a drop-in replacement
* for the <code>Hashtable</code> used in <code>LogFactory</code> for J2EE enviroments
* running 1.3+ JVMs. Use of this class <i>in most cases</i> (see below) will
* allow classloaders to be collected by the garbage collector without the need
* to call {@link org.apache.commons.logging.LogFactory#release(ClassLoader) LogFactory.release(ClassLoader)}.
* </p>
*
* <p><code>org.apache.commons.logging.LogFactory</code> checks whether this class
* can be supported by the current JVM, and if so then uses it to store
* references to the <code>LogFactory</code> implementationd it loads
* (rather than using a standard Hashtable instance).
* Having this class used instead of <code>Hashtable</code> solves
* certain issues related to dynamic reloading of applications in J2EE-style
* environments. However this class requires java 1.3 or later (due to its use
* of <code>java.lang.ref.WeakReference</code> and associates).
* And by the way, this extends <code>Hashtable</code> rather than <code>HashMap</code>
* for backwards compatibility reasons. See the documentation
* for method <code>LogFactory.createFactoryStore</code> for more details.</p>
*
* <p>The reason all this is necessary is due to a issue which
* arises during hot deploy in a J2EE-like containers.
* Each component running in the container owns one or more classloaders; when
* the component loads a LogFactory instance via the component classloader
* a reference to it gets stored in the static LogFactory.factories member,
* keyed by the component's classloader so different components don't
* stomp on each other. When the component is later unloaded, the container
* sets the component's classloader to null with the intent that all the
* component's classes get garbage-collected. However there's still a
* reference to the component's classloader from a key in the "global"
* <code>LogFactory</code>'s factories member! If <code>LogFactory.release()</code>
* is called whenever component is unloaded, the classloaders will be correctly
* garbage collected; this <i>should</i> be done by any container that
* bundles commons-logging by default. However, holding the classloader
* references weakly ensures that the classloader will be garbage collected
* without the container performing this step. </p>
*
* <p>
* <strong>Limitations:</strong>
* There is still one (unusual) scenario in which a component will not
* be correctly unloaded without an explicit release. Though weak references
* are used for its keys, it is necessary to use strong references for its values.
* </p>
*
* <p> If the abstract class <code>LogFactory</code> is
* loaded by the container classloader but a subclass of
* <code>LogFactory</code> [LogFactory1] is loaded by the component's
* classloader and an instance stored in the static map associated with the
* base LogFactory class, then there is a strong reference from the LogFactory
* class to the LogFactory1 instance (as normal) and a strong reference from
* the LogFactory1 instance to the component classloader via
* <code>getClass().getClassLoader()</code>. This chain of references will prevent
* collection of the child classloader.</p>
*
* <p>
* Such a situation occurs when the commons-logging.jar is
* loaded by a parent classloader (e.g. a server level classloader in a
* servlet container) and a custom <code>LogFactory</code> implementation is
* loaded by a child classloader (e.g. a web app classloader).</p>
*
* <p>To avoid this scenario, ensure
* that any custom LogFactory subclass is loaded by the same classloader as
* the base <code>LogFactory</code>. Creating custom LogFactory subclasses is,
* however, rare. The standard LogFactoryImpl class should be sufficient
* for most or all users.</p>
*
*
* @author Brian Stansberry
*
* @since 1.1
*/
public final class WeakHashtable extends Hashtable {
/**
* The maximum number of times put() or remove() can be called before
* the map will be purged of all cleared entries.
*/
private static final int MAX_CHANGES_BEFORE_PURGE = 100;
/**
* The maximum number of times put() or remove() can be called before
* the map will be purged of one cleared entry.
*/
private static final int PARTIAL_PURGE_COUNT = 10;
/* ReferenceQueue we check for gc'd keys */
private ReferenceQueue queue = new ReferenceQueue();
/* Counter used to control how often we purge gc'd entries */
private int changeCount = 0;
/**
* Constructs a WeakHashtable with the Hashtable default
* capacity and load factor.
*/
public WeakHashtable() {}
/**
*@see Hashtable
*/
public boolean containsKey(Object key) {
// purge should not be required
Referenced referenced = new Referenced(key);
return super.containsKey(referenced);
}
/**
*@see Hashtable
*/
public Enumeration elements() {
purge();
return super.elements();
}
/**
*@see Hashtable
*/
public Set entrySet() {
purge();
Set referencedEntries = super.entrySet();
Set unreferencedEntries = new HashSet();
for (Iterator it=referencedEntries.iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
Referenced referencedKey = (Referenced) entry.getKey();
Object key = referencedKey.getValue();
Object value = entry.getValue();
if (key != null) {
Entry dereferencedEntry = new Entry(key, value);
unreferencedEntries.add(dereferencedEntry);
}
}
return unreferencedEntries;
}
/**
*@see Hashtable
*/
public Object get(Object key) {
// for performance reasons, no purge
Referenced referenceKey = new Referenced(key);
return super.get(referenceKey);
}
/**
*@see Hashtable
*/
public Enumeration keys() {
purge();
final Enumeration enumer = super.keys();
return new Enumeration() {
public boolean hasMoreElements() {
return enumer.hasMoreElements();
}
public Object nextElement() {
Referenced nextReference = (Referenced) enumer.nextElement();
return nextReference.getValue();
}
};
}
/**
*@see Hashtable
*/
public Set keySet() {
purge();
Set referencedKeys = super.keySet();
Set unreferencedKeys = new HashSet();
for (Iterator it=referencedKeys.iterator(); it.hasNext();) {
Referenced referenceKey = (Referenced) it.next();
Object keyValue = referenceKey.getValue();
if (keyValue != null) {
unreferencedKeys.add(keyValue);
}
}
return unreferencedKeys;
}
/**
*@see Hashtable
*/
public Object put(Object key, Object value) {
// check for nulls, ensuring symantics match superclass
if (key == null) {
throw new NullPointerException("Null keys are not allowed");
}
if (value == null) {
throw new NullPointerException("Null values are not allowed");
}
// for performance reasons, only purge every
// MAX_CHANGES_BEFORE_PURGE times
if (changeCount++ > MAX_CHANGES_BEFORE_PURGE) {
purge();
changeCount = 0;
}
// do a partial purge more often
else if ((changeCount % PARTIAL_PURGE_COUNT) == 0) {
purgeOne();
}
Referenced keyRef = new Referenced(key, queue);
return super.put(keyRef, value);
}
/**
*@see Hashtable
*/
public void putAll(Map t) {
if (t != null) {
Set entrySet = t.entrySet();
for (Iterator it=entrySet.iterator(); it.hasNext();) {
Map.Entry entry = (Map.Entry) it.next();
put(entry.getKey(), entry.getValue());
}
}
}
/**
*@see Hashtable
*/
public Collection values() {
purge();
return super.values();
}
/**
*@see Hashtable
*/
public Object remove(Object key) {
// for performance reasons, only purge every
// MAX_CHANGES_BEFORE_PURGE times
if (changeCount++ > MAX_CHANGES_BEFORE_PURGE) {
purge();
changeCount = 0;
}
// do a partial purge more often
else if ((changeCount % PARTIAL_PURGE_COUNT) == 0) {
purgeOne();
}
return super.remove(new Referenced(key));
}
/**
*@see Hashtable
*/
public boolean isEmpty() {
purge();
return super.isEmpty();
}
/**
*@see Hashtable
*/
public int size() {
purge();
return super.size();
}
/**
*@see Hashtable
*/
public String toString() {
purge();
return super.toString();
}
/**
* @see Hashtable
*/
protected void rehash() {
// purge here to save the effort of rehashing dead entries
purge();
super.rehash();
}
/**
* Purges all entries whose wrapped keys
* have been garbage collected.
*/
private void purge() {
synchronized (queue) {
WeakKey key;
while ((key = (WeakKey) queue.poll()) != null) {
super.remove(key.getReferenced());
}
}
}
/**
* Purges one entry whose wrapped key
* has been garbage collected.
*/
private void purgeOne() {
synchronized (queue) {
WeakKey key = (WeakKey) queue.poll();
if (key != null) {
super.remove(key.getReferenced());
}
}
}
/** Entry implementation */
private final static class Entry implements Map.Entry {
private final Object key;
private final Object value;
private Entry(Object key, Object value) {
this.key = key;
this.value = value;
}
public boolean equals(Object o) {
boolean result = false;
if (o != null && o instanceof Map.Entry) {
Map.Entry entry = (Map.Entry) o;
result = (getKey()==null ?
entry.getKey() == null :
getKey().equals(entry.getKey()))
&&
(getValue()==null ?
entry.getValue() == null :
getValue().equals(entry.getValue()));
}
return result;
}
public int hashCode() {
return (getKey()==null ? 0 : getKey().hashCode()) ^
(getValue()==null ? 0 : getValue().hashCode());
}
public Object setValue(Object value) {
throw new UnsupportedOperationException("Entry.setValue is not supported.");
}
public Object getValue() {
return value;
}
public Object getKey() {
return key;
}
}
/** Wrapper giving correct symantics for equals and hashcode */
private final static class Referenced {
private final WeakReference reference;
private final int hashCode;
/**
*
* @throws NullPointerException if referant is <code>null</code>
*/
private Referenced(Object referant) {
reference = new WeakReference(referant);
// Calc a permanent hashCode so calls to Hashtable.remove()
// work if the WeakReference has been cleared
hashCode = referant.hashCode();
}
/**
*
* @throws NullPointerException if key is <code>null</code>
*/
private Referenced(Object key, ReferenceQueue queue) {
reference = new WeakKey(key, queue, this);
// Calc a permanent hashCode so calls to Hashtable.remove()
// work if the WeakReference has been cleared
hashCode = key.hashCode();
}
public int hashCode() {
return hashCode;
}
private Object getValue() {
return reference.get();
}
public boolean equals(Object o) {
boolean result = false;
if (o instanceof Referenced) {
Referenced otherKey = (Referenced) o;
Object thisKeyValue = getValue();
Object otherKeyValue = otherKey.getValue();
if (thisKeyValue == null) {
result = (otherKeyValue == null);
// Since our hashcode was calculated from the original
// non-null referant, the above check breaks the
// hashcode/equals contract, as two cleared Referenced
// objects could test equal but have different hashcodes.
// We can reduce (not eliminate) the chance of this
// happening by comparing hashcodes.
if (result == true) {
result = (this.hashCode() == otherKey.hashCode());
}
// In any case, as our c'tor does not allow null referants
// and Hashtable does not do equality checks between
// existing keys, normal hashtable operations should never
// result in an equals comparison between null referants
}
else
{
result = thisKeyValue.equals(otherKeyValue);
}
}
return result;
}
}
/**
* WeakReference subclass that holds a hard reference to an
* associated <code>value</code> and also makes accessible
* the Referenced object holding it.
*/
private final static class WeakKey extends WeakReference {
private final Referenced referenced;
private WeakKey(Object key,
ReferenceQueue queue,
Referenced referenced) {
super(key, queue);
this.referenced = referenced;
}
private Referenced getReferenced() {
return referenced;
}
}
}

View File

@@ -1,22 +0,0 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<body>
<p>Concrete implementations of commons-logging wrapper APIs.</p>
</body>

View File

@@ -1,255 +0,0 @@
<!--
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<body>
<p>Simple wrapper API around multiple logging APIs.</p>
<h3>Overview</h3>
<p>This package provides an API for logging in server-based applications that
can be used around a variety of different logging implementations, including
prebuilt support for the following:</p>
<ul>
<li><a href="http://logging.apache.org/log4j/">Log4J</a> (version 1.2 or later)
from Apache's Logging project. Each named <a href="Log.html">Log</a>
instance is connected to a corresponding Log4J Logger.</li>
<li><a href="http://java.sun.com/j2se/1.4/docs/guide/util/logging/index.html">
JDK Logging API</a>, included in JDK 1.4 or later systems. Each named
<a href="Log.html">Log</a> instance is connected to a corresponding
<code>java.util.logging.Logger</code> instance.</li>
<li><a href="http://avalon.apache.org/logkit/">LogKit</a> from Apache's
Avalon project. Each named <a href="Log.html">Log</a> instance is
connected to a corresponding LogKit <code>Logger</code>.</li>
<li><a href="impl/NoOpLog.html">NoOpLog</a> implementation that simply swallows
all log output, for all named <a href="Log.html">Log</a> instances.</li>
<li><a href="impl/SimpleLog.html">SimpleLog</a> implementation that writes all
log output, for all named <a href="Log.html">Log</a> instances, to
System.err.</li>
</ul>
<h3>Quick Start Guide</h3>
<p>For those impatient to just get on with it, the following example
illustrates the typical declaration and use of a logger that is named (by
convention) after the calling class:
<pre>
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class Foo {
private Log log = LogFactory.getLog(Foo.class);
public void foo() {
...
try {
if (log.isDebugEnabled()) {
log.debug("About to do something to object " + name);
}
name.bar();
} catch (IllegalStateException e) {
log.error("Something bad happened to " + name, e);
}
...
}
</pre>
<p>Unless you configure things differently, all log output will be written
to System.err. Therefore, you really will want to review the remainder of
this page in order to understand how to configure logging for your
application.</p>
<h3>Configuring the Commons Logging Package</h3>
<h4>Choosing a <code>LogFactory</code> Implementation</h4>
<p>From an application perspective, the first requirement is to retrieve an
object reference to the <code>LogFactory</code> instance that will be used
to create <code><a href="Log.html">Log</a></code> instances for this
application. This is normally accomplished by calling the static
<code>getFactory()</code> method. This method implements the following
discovery algorithm to select the name of the <code>LogFactory</code>
implementation class this application wants to use:</p>
<ul>
<li>Check for a system property named
<code>org.apache.commons.logging.LogFactory</code>.</li>
<li>Use the JDK 1.3 JAR Services Discovery mechanism (see
<a href="http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html">
http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html</a> for
more information) to look for a resource named
<code>META-INF/services/org.apache.commons.logging.LogFactory</code>
whose first line is assumed to contain the desired class name.</li>
<li>Look for a properties file named <code>commons-logging.properties</code>
visible in the application class path, with a property named
<code>org.apache.commons.logging.LogFactory</code> defining the
desired implementation class name.</li>
<li>Fall back to a default implementation, which is described
further below.</li>
</ul>
<p>If a <code>commons-logging.properties</code> file is found, all of the
properties defined there are also used to set configuration attributes on
the instantiated <code>LogFactory</code> instance.</p>
<p>Once an implementation class name is selected, the corresponding class is
loaded from the current Thread context class loader (if there is one), or
from the class loader that loaded the <code>LogFactory</code> class itself
otherwise. This allows a copy of <code>commons-logging.jar</code> to be
shared in a multiple class loader environment (such as a servlet container),
but still allow each web application to provide its own <code>LogFactory</code>
implementation, if it so desires. An instance of this class will then be
created, and cached per class loader.
<h4>The Default <code>LogFactory</code> Implementation</h4>
<p>The Logging Package APIs include a default <code>LogFactory</code>
implementation class (<a href="impl/LogFactoryImpl.html">
org.apache.commons.logging.impl.LogFactoryImpl</a>) that is selected if no
other implementation class name can be discovered. Its primary purpose is
to create (as necessary) and return <a href="Log.html">Log</a> instances
in response to calls to the <code>getInstance()</code> method. The default
implementation uses the following rules:</p>
<ul>
<li>At most one <code>Log</code> instance of the same name will be created.
Subsequent <code>getInstance()</code> calls to the same
<code>LogFactory</code> instance, with the same name or <code>Class</code>
parameter, will return the same <code>Log</code> instance.</li>
<li>When a new <code>Log</code> instance must be created, the default
<code>LogFactory</code> implementation uses the following discovery
process:
<ul>
<li>Look for a configuration attribute of this factory named
<code>org.apache.commons.logging.Log</code> (for backwards
compatibility to pre-1.0 versions of this API, an attribute
<code>org.apache.commons.logging.log</code> is also consulted).</li>
<li>Look for a system property named
<code>org.apache.commons.logging.Log</code> (for backwards
compatibility to pre-1.0 versions of this API, a system property
<code>org.apache.commons.logging.log</code> is also consulted).</li>
<li>If the Log4J logging system is available in the application
class path, use the corresponding wrapper class
(<a href="impl/Log4JLogger.html">Log4JLogger</a>).</li>
<li>If the application is executing on a JDK 1.4 system, use
the corresponding wrapper class
(<a href="impl/Jdk14Logger.html">Jdk14Logger</a>).</li>
<li>Fall back to the default simple logging implementation
(<a href="impl/SimpleLog.html">SimpleLog</a>).</li>
</ul></li>
<li>Load the class of the specified name from the thread context class
loader (if any), or from the class loader that loaded the
<code>LogFactory</code> class otherwise.</li>
<li>Instantiate an instance of the selected <code>Log</code>
implementation class, passing the specified name as the single
argument to its constructor.</li>
</ul>
<p>See the <a href="impl/SimpleLog.html">SimpleLog</a> JavaDocs for detailed
configuration information for this default implementation.</p>
<h4>Configuring the Underlying Logging System</h4>
<p>The basic principle is that the user is totally responsible for the
configuration of the underlying logging system.
Commons-logging should not change the existing configuration.</p>
<p>Each individual <a href="Log.html">Log</a> implementation may
support its own configuration properties. These will be documented in the
class descriptions for the corresponding implementation class.</p>
<p>Finally, some <code>Log</code> implementations (such as the one for Log4J)
require an external configuration file for the entire logging environment.
This file should be prepared in a manner that is specific to the actual logging
technology being used.</p>
<h3>Using the Logging Package APIs</h3>
<p>Use of the Logging Package APIs, from the perspective of an application
component, consists of the following steps:</p>
<ol>
<li>Acquire a reference to an instance of
<a href="Log.html">org.apache.commons.logging.Log</a>, by calling the
factory method
<a href="LogFactory.html#getInstance(java.lang.String)">
LogFactory.getInstance(String name)</a>. Your application can contain
references to multiple loggers that are used for different
purposes. A typical scenario for a server application is to have each
major component of the server use its own Log instance.</li>
<li>Cause messages to be logged (if the corresponding detail level is enabled)
by calling appropriate methods (<code>trace()</code>, <code>debug()</code>,
<code>info()</code>, <code>warn()</code>, <code>error</code>, and
<code>fatal()</code>).</li>
</ol>
<p>For convenience, <code>LogFactory</code> also offers a static method
<code>getLog()</code> that combines the typical two-step pattern:</p>
<pre>
Log log = LogFactory.getFactory().getInstance(Foo.class);
</pre>
<p>into a single method call:</p>
<pre>
Log log = LogFactory.getLog(Foo.class);
</pre>
<p>For example, you might use the following technique to initialize and
use a <a href="Log.html">Log</a> instance in an application component:</p>
<pre>
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class MyComponent {
protected Log log =
LogFactory.getLog(MyComponent.class);
// Called once at startup time
public void start() {
...
log.info("MyComponent started");
...
}
// Called once at shutdown time
public void stop() {
...
log.info("MyComponent stopped");
...
}
// Called repeatedly to process a particular argument value
// which you want logged if debugging is enabled
public void process(String value) {
...
// Do the string concatenation only if logging is enabled
if (log.isDebugEnabled())
log.debug("MyComponent processing " + value);
...
}
}
</pre>
</body>

View File

@@ -1,55 +0,0 @@
package com.dt.iTunesController;
import com.jacob.com.Dispatch;
/**
* Represents a artwork.
*
* Defines a single piece of artwork.
*
* Artwork is always associated with an individual track.
* To add a piece of artwork to a track, use IITTrack::AddArtworkFromFile().
* The IITTrack::Artwork property
*
* To get a collection of artwork associated with a track call
* <code>ITTrack.getArtwork()</code>.
*
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public class ITArtwork extends ITObject {
public ITArtwork (Dispatch d) {
super(d);
}
/**
* Delete this object.
*/
public void delete() {
Dispatch.call(object, "Delete");
}
/**
* Returns the kind of the object.
* @return Returns the kind of the object.
*/
public ITArtworkFormat getFormat() {
return ITArtworkFormat.values()[Dispatch.get(object, "Format").getInt()];
}
// TODO: Comments
public boolean getIsDownloadedArtwork() {
return Dispatch.get(object, "IsDownloadedArtwork").getBoolean();
}
public String getDescription() {
return Dispatch.get(object, "Description").getString();
}
public void SaveArtworkToFile(String filePath) {
Dispatch.call(object, "SaveArtworkToFile",filePath);
}
}

View File

@@ -1,55 +0,0 @@
package com.dt.iTunesController;
import com.jacob.com.Dispatch;
/**
* Represents a collection of Artwork objects.
*
* Note that collection indices are always 1-based.
*
* You can retrieve all the Artworks defined for a source using
* <code>ITSource.getArtwork()</code>.
*
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public class ITArtworkCollection {
protected Dispatch object;
public ITArtworkCollection(Dispatch d) {
object = d;
}
/**
* Returns the number of playlists in the collection.
* @return Returns the number of playlists in the collection.
*/
public int getCount() {
return Dispatch.get(object, "Count").getInt();
}
/**
* Returns an ITArtwork object corresponding to the given index (1-based).
* @param index Index of the playlist to retrieve, must be less than or
* equal to <code>ITArtworkCollection.getCount()</code>.
* @return Returns an ITArtwork object corresponding to the given index.
* Will be set to NULL if no playlist could be retrieved.
*/
public ITArtwork getItem (int index) {
Dispatch item = Dispatch.call(object, "Item", index).toDispatch();
return new ITArtwork(item);
}
/**
* Returns an ITArtwork object with the specified persistent ID. See the
* documentation on ITObject for more information on persistent IDs.
* @param highID The high 32 bits of the 64-bit persistent ID.
* @param lowID The low 32 bits of the 64-bit persistent ID.
* @return Returns an ITArtwork object with the specified persistent ID.
* Will be set to NULL if no playlist could be retrieved.
*/
public ITArtwork getItemByPersistentID (int highID, int lowID) {
Dispatch item = Dispatch.call(object, "ItemByPersistentID", highID, lowID).toDispatch();
return new ITArtwork(item);
}
}

View File

@@ -1,13 +0,0 @@
package com.dt.iTunesController;
/**
* Specifies the Artwork kind.
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public enum ITArtworkFormat {
ITArtworkFormatUnknown,
ITArtworkFormatJPEG,
ITArtworkFormatPNG,
ITArtworkFormatBMP;
}

View File

@@ -1,76 +0,0 @@
package com.dt.iTunesController;
import com.jacob.com.Dispatch;
/**
* Represents an audio CD playlist.
*
* An audio CD playlist is always associated with an IITSource of kind
* ITSourceKindAudioCD.
*
* You can retrieve all the playlists defined for a source using
* <code>ITSource.getPlaylists()</code>.
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public class ITAudioCDPlaylist extends ITPlaylist {
public ITAudioCDPlaylist(Dispatch d) {
super(d);
}
/**
* Returns the audio CD's artist.
* @return Returns the audio CD's artist.
*/
public String getArtist() {
return Dispatch.get(object, "Artist").getString();
}
/**
* Returns true if this audio CD is a compilation album.
* @return Returns true if this audio CD is a compilation album.
*/
public boolean isCompilation() {
return Dispatch.get(object, "Compilation").getBoolean();
}
/**
* Returns the audio CD's composer.
* @return Returns the audio CD's composer.
*/
public String getComposer() {
return Dispatch.get(object, "Composer").getString();
}
/**
* Returns the total number of discs in this CD's album.
* @return Returns the total number of discs in this CD's album.
*/
public long getDiscCount() {
return Dispatch.get(object, "DiscCount").getLong();
}
/**
* Returns the index of the CD disc in the source album.
* @return Returns the index of the CD disc in the source album.
*/
public long getDiscNumber() {
return Dispatch.get(object, "DiscNumber").getLong();
}
/**
* Returns the audio CD's genre.
* @return Returns the audio CD's genre.
*/
public String getGenre() {
return Dispatch.get(object, "Genre").getString();
}
/**
* Reveals the CD playlist in the main browser window.
*/
public void reveal() {
Dispatch.call(object, "Reveal");
}
}

View File

@@ -1,45 +0,0 @@
package com.dt.iTunesController;
import com.jacob.com.Dispatch;
/**
* Represents the main browser window.
*
* You can retrieve the main browser window using
* <code>iTunes.BrowserWindow()</code>.
*
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public class ITBrowserWindow extends ITWindow {
public ITBrowserWindow (Dispatch d) {
super(d);
}
/**
* Returns the kind of the object.
* @return Returns the kind of the object.
*/
public boolean getMiniPlayer() {
return Dispatch.get(object, "MiniPlayer").getBoolean();
}
// TODO: Comments
public ITTrackCollection getSelectedTracks() {
Dispatch collection = Dispatch.call(object, "SelectedTracks").getDispatch();
return new ITTrackCollection(collection);
}
public ITPlaylist getSelectedPlaylist() {
Dispatch playlist = Dispatch.get(object, "SelectedPlaylist").toDispatch();
return new ITPlaylist(playlist);
}
public void setSelectedPlaylist(ITPlaylist playlist) {
Dispatch dispatchRef = playlist.fetchDispatch();
Dispatch.put(object, "SelectedPlaylist", dispatchRef);
}
}

View File

@@ -1,12 +0,0 @@
package com.dt.iTunesController;
/**
* Specifies the reason the COM interface is being disabled.
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public enum ITCOMDisabledReason {
ITCOMDisabledReasonOther,
ITCOMDisabledReasonDialog,
ITCOMDisabledReasonQuitting;
}

View File

@@ -1,236 +0,0 @@
package com.dt.iTunesController;
import com.jacob.com.Dispatch;
/**
* Represents an equalizer preset.
* You can retrieve or set the currently selected EQ preset using the
* <code>iTunes.getCurrentEQPreset()<code> method.
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public class ITEQPreset {
protected Dispatch object;
public ITEQPreset(Dispatch d) {
object = d;
}
/**
* Returns the name of the EQ Preset (e.g. "Acoustic").
* @return Returns the name of the EQ Preset (e.g. "Acoustic").
*/
public String getName() {
return Dispatch.get(object, "Name").getString();
}
/**
* Returns true if the EQ preset can be modified.
* @return True if the EQ preset can be modified.
*/
public boolean getModifiable() {
return Dispatch.get(object, "Modifiable").getBoolean();
}
/**
* Set the equalizer preamp level (-12.0 db to +12.0 db).
* @param level The new equalizer preamp level (-12.0 db to +12.0 db).
*/
public void setPreamp(double level) {
Dispatch.put(object, "Preamp", level);
}
/**
* Returns the equalizer preamp level (-12.0db to +12.0db).
* @return Returns the equalizer preamp level (-12.0db to +12.0db).
*/
public double getPreamp() {
return Dispatch.get(object, "Preamp").getDouble();
}
/**
* Set the equalizer 32Hz level (-12.0 db to +12.0 db).
* @param level The new equalizer 32Hz level (-12.0 db to +12.0db).
*/
public void setBand1(double level) {
Dispatch.put(object, "Band1", level);
}
/**
* Returns the equalizer 32Hz level (-12.0 db to +12.0 db).
* @return Returns the equalizer 32Hz level (-12.0 db to +12.0 db).
*/
public double getBand1() {
return Dispatch.get(object, "Band1").getDouble();
}
/**
* Set the equalizer 64Hz level (-12.0 db to +12.0 db).
* @param level The new equalizer 64Hz level (-12.0 db to +12.0db).
*/
public void setBand2(double level) {
Dispatch.put(object, "Band2", level);
}
/**
* Returns the equalizer 64Hz level (-12.0 db to +12.0 db).
* @return Returns the equalizer 64Hz level (-12.0 db to +12.0 db).
*/
public double getBand2() {
return Dispatch.get(object, "Band2").getDouble();
}
/**
* Set the equalizer 125Hz level (-12.0 db to +12.0 db).
* @param level The new equalizer 125Hz level (-12.0 db to +12.0db).
*/
public void setBand3(double level) {
Dispatch.put(object, "Band3", level);
}
/**
* Returns the equalizer 125Hz level (-12.0 db to +12.0 db).
* @return Returns the equalizer 125Hz level (-12.0 db to +12.0 db).
*/
public double getBand3() {
return Dispatch.get(object, "Band3").getDouble();
}
/**
* Set the equalizer 250Hz level (-12.0 db to +12.0 db).
* @param level The new equalizer 250Hz level (-12.0 db to +12.0db).
*/
public void setBand4(double level) {
Dispatch.put(object, "Band4", level);
}
/**
* Returns the equalizer 250Hz level (-12.0 db to +12.0 db).
* @return Returns the equalizer 250Hz level (-12.0 db to +12.0 db).
*/
public double getBand4() {
return Dispatch.get(object, "Band4").getDouble();
}
/**
* Set the equalizer 500Hz level (-12.0 db to +12.0 db).
* @param level The new equalizer 500Hz level (-12.0 db to +12.0db).
*/
public void setBand5(double level) {
Dispatch.put(object, "Band5", level);
}
/**
* Returns the equalizer 500Hz level (-12.0 db to +12.0 db).
* @return Returns the equalizer 500Hz level (-12.0 db to +12.0 db).
*/
public double getBand5() {
return Dispatch.get(object, "Band5").getDouble();
}
/**
* Set the equalizer 1KHz level (-12.0 db to +12.0 db).
* @param level The new equalizer 1KHz level (-12.0 db to +12.0db).
*/
public void setBand6(double level) {
Dispatch.put(object, "Band6", level);
}
/**
* Returns the equalizer 1KHz level (-12.0 db to +12.0 db).
* @return Returns the equalizer 1KHz level (-12.0 db to +12.0 db).
*/
public double getBand6() {
return Dispatch.get(object, "Band6").getDouble();
}
/**
* Set the equalizer 2KHz level (-12.0 db to +12.0 db).
* @param level The new equalizer 2KHz level (-12.0 db to +12.0db).
*/
public void setBand7(double level) {
Dispatch.put(object, "Band7", level);
}
/**
* Returns the equalizer 2KHz level (-12.0 db to +12.0 db).
* @return Returns the equalizer 2KHz level (-12.0 db to +12.0 db).
*/
public double getBand7() {
return Dispatch.get(object, "Band7").getDouble();
}
/**
* Set the equalizer 4KHz level (-12.0 db to +12.0 db).
* @param level The new equalizer 4KHz level (-12.0 db to +12.0db).
*/
public void setBand8(double level) {
Dispatch.put(object, "Band8", level);
}
/**
* Returns the equalizer 4KHz level (-12.0 db to +12.0 db).
* @return Returns the equalizer 4KHz level (-12.0 db to +12.0 db).
*/
public double getBand8() {
return Dispatch.get(object, "Band8").getDouble();
}
/**
* Set the equalizer 8KHz level (-12.0 db to +12.0 db).
* @param level The new equalizer 8KHz level (-12.0 db to +12.0db).
*/
public void setBand9(double level) {
Dispatch.put(object, "Band9", level);
}
/**
* Returns the equalizer 8KHz level (-12.0 db to +12.0 db).
* @return Returns the equalizer 8KHz level (-12.0 db to +12.0 db).
*/
public double getBand9() {
return Dispatch.get(object, "Band9").getDouble();
}
/**
* Set the equalizer 16KHz level (-12.0 db to +12.0 db).
* @param level The new equalizer 16KHz level (-12.0 db to +12.0db).
*/
public void setBand10(double level) {
Dispatch.put(object, "Band10", level);
}
/**
* Returns the equalizer 16KHz level (-12.0 db to +12.0 db).
* @return Returns the equalizer 16KHz level (-12.0 db to +12.0 db).
*/
public double getBand10() {
return Dispatch.get(object, "Band10").getDouble();
}
/**
* Delete this EQ Preset.
* Any EQ preset can be deleted, including built-in presets, except for the
* Manual preset.
* @param updateAllTracks If true, any tracks that use this EQ preet will be
* set to have no assigned EQ preset.
*/
public void delete(boolean updateAllTracks) {
Dispatch.call(object, "Delete", updateAllTracks);
}
/**
* Rename this EQ Preset.
* The name of any EQ preset can be changed, including built-in presets,
* except for the Manual preset.
* EQ preset names cannot start with leading spaces. If you specify a name
* that starts with leading spaces they will be stripped out.
* @param updateAllTracks If true, any tracks that use this EQ preet will be
* updated with the new preset name.
*/
public void rename(String newName, boolean updateAllTracks) {
Dispatch.call(object, "Rename", newName, updateAllTracks);
}
}

View File

@@ -1,39 +0,0 @@
package com.dt.iTunesController;
import com.jacob.com.Dispatch;
/**
* Represents a file or CD track.
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public class ITFileOrCDTrack extends ITTrack {
public ITFileOrCDTrack (Dispatch d) {
super(d);
}
/**
* Reveals the track in the main browser window.
*/
public void reveal() {
Dispatch.call(object, "Reveal");
}
public ITVideoKind getVideoKind() {
return ITVideoKind.values()[Dispatch.get(object, "VideoKind").getInt()];
}
public ITRatingKind getRatingKind() {
return ITRatingKind.values()[Dispatch.get(object, "RatingKind").getInt()];
}
public String getLocation() {
return Dispatch.get(object, "Location").getString();
}
public ITArtworkCollection getArtworks() {
Dispatch artworks = Dispatch.get(object, "Artwork").toDispatch();
return new ITArtworkCollection(artworks);
}
}

View File

@@ -1,20 +0,0 @@
package com.dt.iTunesController;
import com.jacob.com.Dispatch;
/**
* Represents a library playlist.
*
* A library playlist consists of all the tracks in a user's library.
*
* For convenience, you can retrieve the main library playlist using
* <code>iTunes.getLibraryPlaylist()</code>.
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public class ITLibraryPlaylist extends ITPlaylist {
public ITLibraryPlaylist(Dispatch d) {
super(d);
}
}

View File

@@ -1,112 +0,0 @@
package com.dt.iTunesController;
import com.jacob.com.Dispatch;
/**
* Defines a source, playlist or track.
*
* An ITObject uniquely identifies a source, playlist, or track in iTunes using
* four separate IDs. These are runtime IDs, they are only valid while the
* current instance of iTunes is running.
*
* As of iTunes 7.7, you can also identify an ITObject using a 64-bit persistent
* ID, which is valid across multiple invocations of iTunes.
*
* The main use of the ITObject interface is to allow clients to track iTunes
* database changes using
* <code>iTunesEventsInterface.onDatabaseChangedEvent()</code>.
*
* You can retrieve an ITObject with a specified runtime ID using
* <code>iTunes.getITObjectByID()</code>.
*
* An ITObject will always have a valid, non-zero source ID.
*
* An ITObject corresponding to a playlist or track will always have a valid
* playlist ID. The playlist ID will be zero for a source.
*
* An ITObject corresponding to a track will always have a valid track and
* track database ID. These IDs will be zero for a source or playlist.
*
* A track ID is unique within the track's playlist. A track database ID is
* unique across all playlists. For example, if the same music file is in two
* different playlists, each of the tracks could have different track IDs, but
* they will have the same track database ID.
*
* An ITObject also has a 64-bit persistent ID which can be used to identify
* the ITObject across multiple invocations of iTunes.
*
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public class ITObject {
protected Dispatch object;
public ITObject(Dispatch d) {
object = d;
}
/**
* Returns the JACOB Dispatch object for this object.
* @return Returns the JACOB Dispatch object for this object.
*/
public Dispatch fetchDispatch() {
return object;
}
/**
* Set the name of the object.
* @param name The new name of the object.
*/
public void setName (String name) {
Dispatch.put(object, "Name", name);
}
/**
* Returns the name of the object.
* @return Returns the name of the object.
*/
public String getName() {
return Dispatch.get(object, "Name").getString();
}
/**
* Returns the index of the object in internal application order.
* @return The index of the object in internal application order.
*/
public int getIndex() {
return Dispatch.get(object, "Index").getInt();
}
/**
* Returns the ID that identifies the source.
* @return Returns the ID that identifies the source.
*/
public int getSourceID() {
return Dispatch.get(object, "SourceID").getInt();
}
/**
* Returns the ID that identifies the playlist.
* @return Returns the ID that identifies the playlist.
*/
public int getPlaylistID() {
return Dispatch.get(object, "PlaylistID").getInt();
}
/**
* Returns the ID that identifies the track within the playlist.
* @return Returns the ID that identifies the track within the playlist.
*/
public int getTrackID() {
return Dispatch.get(object, "TrackID").getInt();
}
/**
* Returns the ID that identifies the track, independent of its playlist.
* @return Returns the ID that identifies the track, independent of its playlist.
*/
public int getTrackDatabaseID() {
return Dispatch.get(object, "TrackDatabaseID").getInt();
}
}

View File

@@ -1,53 +0,0 @@
package com.dt.iTunesController;
/**
* Simple utility wrapper class to represent the persistent object identity
* ID numbers. Use the getHigh() and getLow() methods individually to get
* each ID, or the combined hex string through toString().
*
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public class ITObjectPersistentID {
private long High;
private long Low;
private String hexString;
/**
* Create the ITObjectPersistentID. This class is not intended to be created
* manually, and this function should only be used by classes implementing
* this utility.
* @param high The High Persistent ID
* @param low The Low Persistent ID
*/
public ITObjectPersistentID(long high, long low) {
this.High=high;
this.Low=low;
this.hexString = String.format("%8s%8s",Long.toHexString(this.High),Long.toHexString(this.Low)).toUpperCase().replace(' ','0');
}
/**
* Returns the high persistent ID.
* @return The high persistent ID.
*/
public long getHigh() {
return this.High;
}
/**
* Returns the low persistent ID.
* @return The low persistent ID.
*/
public long getLow() {
return this.Low;
}
/**
* Return a string representation (in hex) of the persistent IDs.
* @return String representation of the persistent IDs.
*/
public String toString() {
return this.hexString;
}
}

View File

@@ -1,62 +0,0 @@
package com.dt.iTunesController;
import com.jacob.com.Dispatch;
/**
* Represents the status of an asynchronous add or convert operation.
*
* When a track is added using TLibraryPlaylist.addFile(),
* ITLibraryPlaylist.AddFiles(), IITUserPlaylist.addFile(), or
* ITUserPlaylist.addFiles(), the add may not complete immediately if iTunes
* needs to make a copy of the file.
*
* Similarly, when converting or importing a file or track using
* <code>iTunes.convertFile()</code>, <code>iTunes.convertFiles()</code>,
* <code>iTunes.convertTrack()</code> or <code>iTunes.convertTracks()</code>,
* the conversion will never complete immediately.
*
* These methods return an <code>ITOperationStatus</code> object, which can be
* polled todetermine when the operation is done. This object will also return
* the collection of newly added or converted tracks.
*
* As of version 1.1 of the iTunes type library, you should use
* <code>iTunes.convertFile2()</code>, <code>iTunes.convertFiles2()</code>,
* <code>iTunes.convertTrack2()</code> or <code>iTunes.convertTracks2()</code>
* instead of the original convert methods. These new methods return an
* <code>ITConvertOperationStatus</code> object to allow clients to retrieve
* additional conversion progress information.
*
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public class ITOperationStatus {
protected Dispatch object;
public ITOperationStatus(Dispatch d) {
object = d;
}
/**
* Returns true if the operation is still in progress.
* You cannot retrieve the <code>ITOperationStatus.getTracks()</code>
* property until the operation completes.
* @return Returns true if the operation is still in progress.
*/
public boolean getInProgress() {
return Dispatch.get(object, "InProgress").getBoolean();
}
/**
* Returns a collection containing the tracks that were generated by the
* operation.
* You cannot retrieve this property until
* <code>ITOperationStatus.getInProgress()</code> returns false
* @return Returns a collection containing the tracks that were generated by
* the operation.
*/
public ITTrackCollection getTracks() {
Dispatch tracks = Dispatch.get(object, "Tracks").toDispatch();
return new ITTrackCollection(tracks);
}
}

View File

@@ -1,13 +0,0 @@
package com.dt.iTunesController;
/**
* Specifies the state of the player.
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public enum ITPlayerState {
ITPlayerStateStopped,
ITPlayerStatePlaying,
ITPlayerStateFastForward,
ITPlayerStateRewind;
}

View File

@@ -1,154 +0,0 @@
package com.dt.iTunesController;
import com.jacob.com.Dispatch;
/**
* Represents a playlist.
*
* A playlist is always associated with an ITSource.
*
* You can retrieve all the playlists defined for a source using
* <code>ITSource.getPlaylists()</code>.
*
* For convenience, you can retrieve the main library playlist using
* <code>iTunes.getLibraryPlaylist()</code>.
*
* You can create a new playlist using <code>iTunes.createPlaylist()</code>.
*
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public class ITPlaylist extends ITObject {
public ITPlaylist (Dispatch d) {
super(d);
}
/**
* Delete this object.
*/
public void delete() {
Dispatch.call(object, "Delete");
}
/**
* Start playing the first track in this object.
*/
public void playFirstTrack() {
Dispatch.call(object, "PlayFirstTrack");
}
/**
* Print this object.
* @param showPrintDialog If true, display the print dialog.
* @param printKind The printout kind.
* @param theme The name of the theme to use. This corresponds to the name
* of a Theme combo box item in the print dialog for the specified printKind
* (e.g. "Track length"). This string cannot be longer than 255 characters,
* but it may be empty.
*/
public void print(boolean showPrintDialog, ITPlaylistPrintKind printKind, String theme) {
Dispatch.call(object, "Print", showPrintDialog, printKind.ordinal(), theme);
}
/**
* Returns a collection containing the tracks with the specified text.
* @param searchText The text to search for. This string cannot be longer
* than 255 chracters.
* @param searchFields Specifies which fields of each track should be
* searched for searchText.
* @return Collection of IITTrack objects. This will be NULL if no tracks
* meet the search criteria.
*/
public ITTrackCollection search (String searchText, ITPlaylistSearchField searchFields) {
Dispatch collection = Dispatch.call(object, "Search", searchText, searchFields.ordinal()).getDispatch();
return new ITTrackCollection(collection);
}
/**
* Returns the kind of the object.
* @return Returns the kind of the object.
*/
public ITPlaylistKind getKind() {
return ITPlaylistKind.values()[Dispatch.get(object, "Kind").getInt()];
}
/**
* Returns an ITSource object corresponding to the source that contains the
* object.
* @return Returns an ITSource object corresponding to the source that
* contains the object.
*/
public ITSource getSource() {
Dispatch source = Dispatch.get(object, "Source").toDispatch();
return new ITSource(source);
}
/**
* Returns the total length of all songs in the object (in seconds).
* @return Returns the total length of all songs in the object (in
* seconds).
*/
public int getDuration() {
return Dispatch.get(object, "Duration").getInt();
}
/**
* Set whether songs in the object should be played in random order.
* @param shouldShuffle True if songs in the object should be played in
* random order.
*/
public void setShuffle(boolean shouldShuffle) {
Dispatch.put(object, "Shuffle", shouldShuffle);
}
/**
* Returns the total size of all songs in the object (in bytes).
* @return Returns the total size of all songs in the object (in bytes).
*/
public double getSize() {
return Dispatch.get(object, "Size").getDouble();
}
/**
* Sets the playback repeat mode.
* @param repeatMode The new playback repeat mode.
*/
public void setSongRepeat(ITPlaylistRepeatMode repeatMode) {
Dispatch.put(object, "SongRepeat", repeatMode.ordinal());
}
/**
* Returns the playback repeat mode.
* @return Returns the playback repeat mode.
*/
public ITPlaylistRepeatMode getSongRepeat() {
return ITPlaylistRepeatMode.values()[Dispatch.get(object, "SongRepeat").getInt()];
}
/**
* Returns the total length of all songs in the object (in MM:SS format).
* @return Returns the total length of all songs in the object (in
* MM:SS format).
*/
public String getTime() {
return Dispatch.get(object, "Time").getString();
}
/**
* Returns true if the object is visible in the sources list.
* @return True if the object is visible in the sources list.
*/
public boolean getVisible() {
return Dispatch.get(object, "Visible").getBoolean();
}
/**
* Returns a collection containing the tracks in this object.
* @return Collection of ITTrack objects.
*/
public ITTrackCollection getTracks() {
Dispatch tracks = Dispatch.get(object, "Tracks").toDispatch();
return new ITTrackCollection(tracks);
}
}

View File

@@ -1,67 +0,0 @@
package com.dt.iTunesController;
import com.jacob.com.Dispatch;
/**
* Represents a collection of playlist objects.
*
* Note that collection indices are always 1-based.
*
* You can retrieve all the playlists defined for a source using
* <code>ITSource.getPlaylists()</code>.
*
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public class ITPlaylistCollection {
protected Dispatch object;
public ITPlaylistCollection(Dispatch d) {
object = d;
}
/**
* Returns the number of playlists in the collection.
* @return Returns the number of playlists in the collection.
*/
public int getCount() {
return Dispatch.get(object, "Count").getInt();
}
/**
* Returns an ITPlaylist object corresponding to the given index (1-based).
* @param index Index of the playlist to retrieve, must be less than or
* equal to <code>ITPlaylistCollection.getCount()</code>.
* @return Returns an ITPlaylist object corresponding to the given index.
* Will be set to NULL if no playlist could be retrieved.
*/
public ITPlaylist getItem (int index) {
Dispatch item = Dispatch.call(object, "Item", index).toDispatch();
return new ITPlaylist(item);
}
/**
* Returns an ITPlaylist object withthe specified name.
* @param name The name of the playlist to retrieve.
* @return Returns an ITPlaylist object corresponding to the given index.
* Will be set to NULL if no playlist could be retrieved.
*/
public ITPlaylist ItemByName (String name) {
Dispatch item = Dispatch.call(object, "ItemByName", name).toDispatch();
return new ITPlaylist(item);
}
/**
* Returns an ITPlaylist object with the specified persistent ID. See the
* documentation on ITObject for more information on persistent IDs.
* @param highID The high 32 bits of the 64-bit persistent ID.
* @param lowID The low 32 bits of the 64-bit persistent ID.
* @return Returns an ITPlaylist object with the specified persistent ID.
* Will be set to NULL if no playlist could be retrieved.
*/
public ITPlaylist getItemByPersistentID (int highID, int lowID) {
Dispatch item = Dispatch.call(object, "ItemByPersistentID", highID, lowID).toDispatch();
return new ITPlaylist(item);
}
}

View File

@@ -1,15 +0,0 @@
package com.dt.iTunesController;
/**
* Specifies the playlist kind.
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public enum ITPlaylistKind {
ITPlaylistKindUnknown,
ITPlaylistKindLibrary,
ITPlaylistKindUser,
ITPlaylistKindCD,
ITPlaylistKindDevice,
ITPlaylistKindRadioTuner;
}

View File

@@ -1,14 +0,0 @@
package com.dt.iTunesController;
/**
* Specifies the kind of playlist printout.
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public enum ITPlaylistPrintKind {
ITPlaylistPrintKindPlaylist,
ITPlaylistPrintKindAlbumlist,
ITPlaylistPrintKindInsert;
}

View File

@@ -1,14 +0,0 @@
package com.dt.iTunesController;
/**
* Specifies the playlist playback repeat mode.
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public enum ITPlaylistRepeatMode {
ITPlaylistRepeatModeOff,
ITPlaylistRepeatModeOne,
ITPlaylistRepeatModeAll;
}

View File

@@ -1,16 +0,0 @@
package com.dt.iTunesController;
/**
* Specifies the fields in each track that will be searched by
* <code>ITPlaylist.search()</code>.
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public enum ITPlaylistSearchField {
ITPlaylistSearchFieldAll,
ITPlaylistSearchFieldVisible,
ITPlaylistSearchFieldArtists,
ITPlaylistSearchFieldAlbums,
ITPlaylistSearchFieldComposers,
ITPlaylistSearchFieldSongNames;
}

View File

@@ -1,11 +0,0 @@
package com.dt.iTunesController;
/**
* Specifies the rating kind.
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public enum ITRatingKind {
ITRatingKindUser,
ITRatingKindComputed;
}

View File

@@ -1,51 +0,0 @@
package com.dt.iTunesController;
import com.jacob.com.Dispatch;
/**
* Represents an entry in the Source list (music library, CD, device, etc.).
* You can retrieve all the sources using <code>iTunes.getSources()</code>.
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public class ITSource extends ITObject {
public ITSource(Dispatch d) {
super(d);
}
/**
* Returns the kind of the source.
* @return Returns the kind of the source.
*/
public ITSourceKind getKind() {
return ITSourceKind.values()[Dispatch.get(object, "Kind").getInt()];
}
/**
* Returns the total size of the source, if it has a fixed size.
* @return Returns the total size of the source, if it has a fixed size.
*/
public double getCapacity() {
return Dispatch.get(object, "Capacity").getDouble();
}
/**
* Returns the free space on the source, if it has a fixed size.
* @return Returns the free space on the source, if it has a fixed size.
*/
public double getFreespace() {
return Dispatch.get(object, "Freespace").getDouble();
}
/**
* Returns a collection containing the playlists in this source.
* The source's primary playlist is always the first playlist in the
* collection.
* @return Collection of IITPlaylist objects.
*/
public ITPlaylistCollection getPlaylists() {
Dispatch playlists = Dispatch.get(object, "Playlists").toDispatch();
return new ITPlaylistCollection(playlists);
}
}

View File

@@ -1,66 +0,0 @@
package com.dt.iTunesController;
import com.jacob.com.Dispatch;
/**
* Represents a collection of source objects.
*
* Note that collection indices are always 1-based.
*
* You can retrieve all the sources using <code>ITSource.getSources()</code>.
*
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public class ITSourceCollection {
protected Dispatch object;
public ITSourceCollection(Dispatch d) {
object = d;
}
/**
* Returns the number of sources in the collection.
* @return Returns the number of sources in the collection.
*/
public int getCount() {
return Dispatch.get(object, "Count").getInt();
}
/**
* Returns an ITSource object corresponding to the given index (1-based).
* @param index Index of the source to retrieve, must be less than or
* equal to <code>ITSourceCollection.getCount()</code>.
* @return Returns an ITSource object corresponding to the given index.
* Will be set to NULL if no source could be retrieved.
*/
public ITSource getItem (int index) {
Dispatch item = Dispatch.call(object, "Item", index).toDispatch();
return new ITSource(item);
}
/**
* Returns an ITSource object withthe specified name.
* @param name The name of the source to retrieve.
* @return Returns an ITSource object corresponding to the given index.
* Will be set to NULL if no source could be retrieved.
*/
public ITSource getItemByName (String name) {
Dispatch item = Dispatch.call(object, "ItemByName", name).toDispatch();
return new ITSource(item);
}
/**
* Returns an ITSource object with the specified persistent ID. See the
* documentation on ITObject for more information on persistent IDs.
* @param highID The high 32 bits of the 64-bit persistent ID.
* @param lowID The low 32 bits of the 64-bit persistent ID.
* @return Returns an ITSource object with the specified persistent ID.
* Will be set to NULL if no source could be retrieved.
*/
public ITSource getItemByPersistentID (int highID, int lowID) {
Dispatch item = Dispatch.call(object, "ItemByPersistentID", highID, lowID).toDispatch();
return new ITSource(item);
}
}

View File

@@ -1,17 +0,0 @@
package com.dt.iTunesController;
/**
* Specifies the source kind.
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public enum ITSourceKind {
ITSourceKindUnknown,
ITSourceKindLibrary,
ITSourceKindIPod,
ITSourceKindAudioCD,
ITSourceKindMP3CD,
ITSourceKindDevice,
ITSourceKindRadioTuner,
ITSourceKindSharedLibrary;
}

View File

@@ -1,492 +0,0 @@
package com.dt.iTunesController;
import com.jacob.com.*;
import java.util.Date;
/**
* Represents a track.
*
* A track represents a song in a single playlist. A song may be in more than
* one playlist, in which case it would be represented by multiple tracks.
*
* You can retrieve the currently targeted (playing) track using
* <code>iTunes.getCurrentTrack()</code>.
*
* Typically, an ITrack is accessed through an ITTrackCollection.
*
* You can retrieve all the tracks defined for a playlist using
* <code>ITPlaylist.getTracks()</code>.
*
* You can retrieve the currently selected track or tracks using
* <code>iTunes.getSelectedTracks()</code>.
*
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public class ITTrack extends ITObject {
public ITTrack (Dispatch d) {
super(d);
}
/**
* Delete this object.
*/
public void delete() {
Dispatch.call(object, "Delete");
}
/**
* Start playing this object.
*/
public void play() {
Dispatch.call(object, "Play");
}
/**
* Set the name of the album containing the object.;
* @param album The new name of the album containing the object.
*/
public void setAlbum(String album) {
Dispatch.put(object, "Album", album);
}
/**
* Returns the name of the album containing the object.
* @return Returns the name of the album containing the object.
*/
public String getAlbum() {
return Dispatch.get(object, "Album").getString();
}
/**
* Set the name of the artist/source of the object.
* @param artist The new artist/source of the object.
*/
public void setArtist(String artist) {
Dispatch.put(object, "Artist", artist);
}
/**
* Returns the name of the artist/source of the object.
* @return Returns the name of the artist/source of the object.
*/
public String getArtist() {
return Dispatch.get(object, "Artist").getString();
}
/**
* Returns the bit rate of the object (in kbps).
* @return Returns the bit rate of the object (in kbps).
*/
public int getBitRate() {
return Dispatch.get(object, "BitRate").getInt();
}
/**
* Set the tempo of the object (in beats per minute).
* @param beatsPerMinute The new tempo of the object (in beats per minute).
*/
public void setBPM(int beatsPerMinute) {
Dispatch.put(object, "BPM", beatsPerMinute);
}
/**
* Returns the tempo of the object (in beats per minute).
* @return Returns the tempo of the object (in beats per minute).
*/
public int getBPM() {
return Dispatch.get(object, "BPM").getInt();
}
/**
* Set freeform notes about the object.
* @param comment The new freeform notes about the object.
*/
public void setComment(String comment) {
Dispatch.put(object, "Comment", comment);
}
/**
* Returns freeform notes about the object.
* @return Returns freeform notes about the object.
*/
public String getComment() {
return Dispatch.get(object, "Comment").getString();
}
/**
* Set whether this object is from a compilation album.
* @param isCompilation True if this object should be from a compilation album.
*/
public void setCompilation(boolean isCompilation) {
Dispatch.put(object, "Compilation", isCompilation);
}
/**
* Returns true if this object is from a compilation album.
* @return Returns true if this object is from a compilation album.
*/
public boolean getCompilation() {
return Dispatch.get(object, "Compilation").getBoolean();
}
/**
* Set the composer of the object.
* @param composer The new composer of the object.
*/
public void setComposer (String composer) {
Dispatch.put(object, "Composer", composer);
}
/**
* Returns the composer of the object.
* @return Returns the composer of the object.
*/
public String getComposer() {
return Dispatch.get(object, "Composer").getString();
}
/**
* Returns the date the object was added to the playlist.
* @return Returns the date the object was added to the playlist.
*/
public Date getDateAdded() {
return Dispatch.get(object, "DateAdded").getJavaDate();
}
/**
* Set the total number of discs in the source album.
* @param discCount The new total number of discs in the source album.
*/
public void setDiscCount (int discCount) {
Dispatch.put(object, "DiscCount", discCount);
}
/**
* Returns the total number of discs in the source album.
* @return Returns the total number of discs in the source album.
*/
public int getDiscCount() {
return Dispatch.get(object, "DiscCount").getInt();
}
/**
* Set the index of the disc containing the object on the source album.
* @param discNumber The new index of the disc containing the object on the
* source album.
*/
public void setDiscNumber (int discNumber) {
Dispatch.put(object, "DiscNumber", discNumber);
}
/**
* Returns the index of the disc containing the object on the source album.
* @return Returns the index of the disc containing the object on the source
* album.
*/
public int getDiscNumber() {
return Dispatch.get(object, "DiscNumber").getInt();
}
/**
* Returns the length of the object (in seconds).
* @return Returns the length of the object (in seconds).
*/
public int getDuration() {
return Dispatch.get(object, "Duration").getInt();
}
/**
* Set whether this object is checked for playback.
* @param shouldBeEnabled True if the object should be checked for playback.
*/
public void setEnabled (boolean shouldBeEnabled) {
Dispatch.put(object, "Enabled", shouldBeEnabled);
}
/**
* Returns true if the object is checked for playback.
* @return Returns true if the object is checked for playback.
*/
public boolean getEnabled() {
return Dispatch.get(object, "Enabled").getBoolean();
}
/**
* Set the name of the EQ preset of the object.
* @param eq The new name of the EQ preset of the object.
*/
public void setEQ (String eq) {
Dispatch.put(object, "EQ", eq);
}
/**
* Returns the name of the EQ preset of the object.
* @return Returns the name of the EQ preset of the object.
*/
public String getEQ() {
return Dispatch.get(object, "EQ").getString();
}
/**
* Set the stop time of the object (in seconds).
* @param finish The new stop time of the object (in seconds).
*/
public void setFinish(int finish) {
Dispatch.put(object, "Finish", finish);
}
/**
* Returns the stop time of the object (in seconds).
* @return Returns the stop time of the object (in seconds).
*/
public int getFinish() {
return Dispatch.get(object, "Finish").getInt();
}
/**
* Returns the music/audio genre (category) of the object.
* @param genre Returns the music/audio genre (category) of the object.
*/
public void setGenre(String genre) {
Dispatch.put(object, "Genre", genre);
}
/**
* Set the music/audio genre (category) of the object.
* @return The new music/audio genre (category) of the object.
*/
public String getGenre() {
return Dispatch.get(object, "Genre").getString();
}
/**
* Set the grouping (piece) of the object.
* Generally used to denote movements within classical work.
* @param grouping The new grouping (piece) of the object.
*/
public void setGrouping (String grouping) {
Dispatch.put(object, "Grouping", grouping);
}
/**
* Returns the grouping (piece) of the object.
* Generally used to denote movements within classical work.
* @return Returns the grouping (piece) of the object.
*/
public String getGrouping() {
return Dispatch.get(object, "Grouping").getString();
}
public ITTrackKind getKind() {
return ITTrackKind.values()[Dispatch.get(object, "Kind").getInt()];
}
/**
* Returns the text description of the object (e.g. "AAC audio file").
* @return Returns the text description of the object (e.g. "AAC audio file").
*/
public String getKindAsString() {
return Dispatch.get(object, "KindAsString").getString();
}
/**
* Returns the modification date of the content of the object.
* @return Returns the modification date of the content of the object.
*/
public Date getModificationDate() {
return Dispatch.get(object, "ModificationDate").getJavaDate();
}
/**
* Set the number of times the object has been played. This property cannot
* be set if the object is not playable (e.g. a PDF file).
* @param playedCount The new number of times the object has been played.
*/
public void setPlayedCount (int playedCount) {
Dispatch.put(object, "PlayedCount", playedCount);
}
/**
* Returns the number of times the object has been played.
* @return Returns the number of times the object has been played.
*/
public int getPlayedCount() {
return Dispatch.get(object, "PlayedCount").getInt();
}
/**
* Set the date and time the object was last played. This property cannot be
* set if the object is not playable (e.g. a PDF file).
* A value of zero means no played date.
* @param playedDate The new date and time the object was last played.
*/
public void setPlayedDate (Date playedDate) {
Dispatch.put(object, "PlayedDate", playedDate);
}
/**
* Returns the date and time the object was last played.
* A value of zero means no played date.
* @return Returns the date and time the object was last played.
*/
public Date getPlayedDate() {
return Dispatch.get(object, "PlayedDate").getJavaDate();
}
/**
* Returns an ITPlaylist object corresponding to the playlist that contains
* the object. Use ITFileOrCDTrack::Playlists() or IITURLTrack::Playlists()
* to get the collection of all playlists that contain the song this object
* represents.
* @return Returns an ITPlaylist object corresponding to the playlist that
* contains the object.
*/
public ITPlaylist getPlaylist() {
Dispatch playlist = Dispatch.get(object, "Playlist").toDispatch();
return new ITPlaylist(playlist);
}
/**
* Returns the play order index of the object in the owner playlist
* (1-based).
* You can pass this index to IITTrackCollection::ItemByPlayOrder() for the
* collection returned by ITPlaylist::Tracks() to retrieve an ITTrack
* object corresponding to this object.
* @return Returns the play order index of the object in the owner playlist.
*/
public int getPlayOrderIndex() {
return Dispatch.get(object, "PlayOrderIndex").getInt();
}
/**
* Set the rating of the object (0 to 100). If the object rating is set to 0,
* it will be computed based on the album rating.
* @param rating The new rating of the object (0 to 100).
*/
public void setRating (int rating) {
Dispatch.put(object, "Rating", rating);
}
/**
* Returns the rating of the object (0 to 100). If the object rating has never
* been set, or has been set to 0, it will be computed based on the album
* rating.
* @return Returns the rating of the object (0 to 100).
*/
public int getRating() {
return Dispatch.get(object, "Rating").getInt();
}
/**
* Returns the sample rate of the object (in Hz).
* @return Returns the sample rate of the object (in Hz).
*/
public int getSampleRate() {
return Dispatch.get(object, "SampleRate").getInt();
}
/**
* Returns the size of the object (in bytes).
* @return Returns the size of the object (in bytes).
*/
public int getSize() {
return Dispatch.get(object, "Size").getInt();
}
/**
* Set the start time of the object (in seconds).
* @param start The new start time of the object (in seconds).
*/
public void setStart (int start) {
Dispatch.put(object, "Start", start);
}
/**
* Returns the start time of the object (in seconds).
* @return Returns the start time of the object (in seconds).
*/
public int getStart() {
return Dispatch.get(object, "Start").getInt();
}
/**
* Returns the length of the object (in MM:SS format).
* @return Returns the length of the object (in MM:SS format).
*/
public String getTime() {
return Dispatch.get(object, "Time").getString();
}
/**
* Set the total number of tracks on the source album.
* @param trackCount The new total number of tracks on the source album.
*/
public void setTrackCount (int trackCount) {
Dispatch.put(object, "TrackCount", trackCount);
}
/**
* Returns the total number of tracks on the source album.
* @return Returns the total number of tracks on the source album.
*/
public int getTrackCount() {
return Dispatch.get(object, "TrackCount").getInt();
}
/**
* Set the index of the object on the source album.
* @param trackNumber The new index of the object on the source album.
*/
public void setTrackNumber (int trackNumber) {
Dispatch.put(object, "TrackNumber", trackNumber);
}
/**
* Returns the index of the object on the source album.
* @return Returns the index of the object on the source album.
*/
public int getTrackNumber() {
return Dispatch.get(object, "TrackNumebr").getInt();
}
/**
* Set the relative volume adjustment of the object (-100% to 100%).
* @param volumeAdjustment Set the relative volume adjustment of the object
* (-100% to 100%).
*/
public void setVolumeAdjustment (int volumeAdjustment) {
Dispatch.put(object, "VolumeAdjustment", volumeAdjustment);
}
/**
* Returns the relative volume adjustment of the object (-100% to 100%).
* @return Returns the relative volume adjustment of the object (-100% to 100%).
*/
public int getVolumeAdjustment() {
return Dispatch.get(object, "VolumeAdjustment").getInt();
}
/**
* Set the year the object was recorded/released.
* @param year The new year the object was recorded/released.
*/
public void setYear (int year) {
Dispatch.put(object, "Year", year);
}
/**
* Returns the year the object was recorded/released.
* @return Returns the year the object was recorded/released.
*/
public int getYear() {
return Dispatch.get(object, "Year").getInt();
}
public ITArtworkCollection getArtwork() {
Dispatch art = Dispatch.get(object, "Artwork").toDispatch();
return new ITArtworkCollection(art);
}
}

View File

@@ -1,91 +0,0 @@
package com.dt.iTunesController;
import com.jacob.com.Dispatch;
/**
* Represents a collection of track objects.
*
* Note that collection indices are always 1-based.
*
* You can retrieve all the tracks defined for a playlist using
* <code>ITPlaylist.getTracks()</code>.
*
* You can retrieve the currently selected track or tracks using
* <code>iTunes.getSelectedTracks()</code>.
*
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public class ITTrackCollection {
protected Dispatch object;
public ITTrackCollection(Dispatch d) {
object = d;
}
/**
* Returns the number of tracks in the collection.
* @return Returns the number of tracks in the collection.
*/
public int getCount() {
return Dispatch.get(object, "Count").getInt();
}
/**
* Returns an ITTrack object corresponding to the given index (1-based).
* @param index Index of the track to retrieve, must be less than or
* equal to <code>ITTrackCollection.getCount()</code>.
* @return Returns an ITTrack object corresponding to the given index.
* Will be set to NULL if no track could be retrieved.
*/
public ITTrack getItem (int index) {
Dispatch item = Dispatch.call(object, "Item", index).toDispatch();
ITTrack track = new ITTrack(item);
if (track.getKind()==ITTrackKind.ITTrackKindFile) {
return new ITFileOrCDTrack(item);
} else if (track.getKind()==ITTrackKind.ITTrackKindCD) {
return new ITFileOrCDTrack(item);
} else if (track.getKind()==ITTrackKind.ITTrackKindURL ) {
return new ITURLTrack(item);
} else {
return track;
}
}
/**
* Returns an ITTrack object corresponding to the given index (1-based).
* @param index Index of the track to retrieve, must be less than or
* equal to <code>ITTrackCollection.getCount()</code>.
* @return Returns an ITTrack object corresponding to the given index.
* Will be set to NULL if no track could be retrieved.
*/
public ITTrack getItemByPlayOrder(int index) {
Dispatch item = Dispatch.call(object, "ItemByPlayOrder", index).toDispatch();
return new ITTrack(item);
}
/**
* Returns an ITTrack object withthe specified name.
* @param name The name of the track to retrieve.
* @return Returns an ITTrack object corresponding to the given index.
* Will be set to NULL if no track could be retrieved.
*/
public ITTrack ItemByName (String name) {
Dispatch item = Dispatch.call(object, "ItemByName", name).toDispatch();
return new ITTrack(item);
}
/**
* Returns an ITTrack object with the specified persistent ID. See the
* documentation on ITObject for more information on persistent IDs.
* @param highID The high 32 bits of the 64-bit persistent ID.
* @param lowID The low 32 bits of the 64-bit persistent ID.
* @return Returns an ITTrack object with the specified persistent ID.
* Will be set to NULL if no track could be retrieved.
*/
public ITTrack getItemByPersistentID (int highID, int lowID) {
Dispatch item = Dispatch.call(object, "ItemByPersistentID", highID, lowID).toDispatch();
return new ITTrack(item);
}
}

View File

@@ -1,15 +0,0 @@
package com.dt.iTunesController;
/**
* Specifies the track kind.
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public enum ITTrackKind {
ITTrackKindUnknown,
ITTrackKindFile,
ITTrackKindCD,
ITTrackKindURL,
ITTrackKindDevice,
ITTrackKindSharedLibrary;
}

View File

@@ -1,175 +0,0 @@
package com.dt.iTunesController;
import com.jacob.com.Dispatch;
/**
* Represents a URL track.
*
* A URL track references a network audio stream.
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public class ITURLTrack extends ITTrack {
public ITURLTrack (Dispatch d) {
super(d);
}
/**
* Returns the URL of the stream represented by this track.
* @return The URL of the stream represented by this track.
*/
public String getURL () {
return Dispatch.get(object, "URL").getString();
}
/**
* Set the URL of the stream represented by this track.
* @param url The URL of the stream represented by this track.
*/
public void setURL (String url) {
Dispatch.call(object, "URL", url);
}
/**
* Returns true if this track is a podcast track. If a podcast track is an
* <code>IITURLTrack</code>, the podcast episode has not been downloaded.
* @return Returns true if this track is a podcast track.
*/
public boolean isPodcast () {
return Dispatch.get(object, "Podcast").getBoolean();
}
/**
* Returns the category for the track.
* @return Returns the category for the track.
*/
public String getCategory () {
return Dispatch.get(object, "Category").getString();
}
/**
* Sets the category for the track.
* @param category Sets the category for the track.
*/
public void setCategory (String category) {
Dispatch.call(object, "Category", category);
}
/**
* Returns the description for the track.
* @return Returns the description for the track.
*/
public String getDescription () {
return Dispatch.get(object, "Description").getString();
}
/**
* Sets the description for the track.
* @param description The new description for the track.
*/
public void setDescription (String description) {
Dispatch.call(object, "Description", description);
}
/**
* Returns the long description for the track.
* @return Returns the description for the track.
*/
public String getLongDescription () {
return Dispatch.get(object, "LongDescription").getString();
}
/**
* Sets the long description for the track.
* @param longDescription The new long description for the track.
*/
public void setLongDescription (String longDescription) {
Dispatch.call(object, "LongDescription", longDescription);
}
/**
* Returns the user or computed rating of the album that this track belongs
* to (0 to 100). If the album rating has never been set, or has been set to
* 0, it will be computed based on the ratings of tracks in the album.
* @return Returns the album rating of the album that this track belongs to (0 to 100).
*/
public long getAlbumRating () {
return Dispatch.get(object, "AlbumRating").getLong();
}
/**
* Set the album rating of the album that this track belongs to (0 to 100).
* If the album rating is set to 0, it will be computed based on the ratings
* of tracks in the album.
* @param albumRating The new album rating of the album that this track
* belongs to (0 to 100). If rating is outside this range, it will be
* pinned.
*/
public void setAlbumRating (long albumRating) {
Dispatch.call(object, "AlbumRating", albumRating);
}
/**
* Returns the album rating kind. If the album rating has never been set, or
* has been set to 0, the kind is ITRatingKindComputed. Otherwise, the kind
* is ITRatingKindUser.
* @return Returns the album rating kind.
*/
public ITRatingKind getAlbumRatingKind () {
return ITRatingKind.values()[Dispatch.get(object, "AlbumRatingKind").getInt()];
}
/**
* Returns the track rating kind. If the track rating has never been set, or
* has been set to 0, the kind is ITRatingKindComputed. Otherwise, the kind
* is ITRatingKindUser.
* @return Returns the track rating kind.
*/
public ITRatingKind getRatingKind () {
return ITRatingKind.values()[Dispatch.get(object, "RatingKind").getInt()];
}
/**
* Returns a collection of playlists that contain the song that this track
* represents.
*
* This is the same collection of playlists that are shown in the "Show in
* Playlist" contextual menu for a track, plus the specific playlist that
* contains this track.
*
* A track represents a song in a single playlist, use
* <code>ITTrack.getPlaylist()</code> to get the specific playlist that
* contains this track.
* @return Collection of ITPlaylist objects.
*/
public ITPlaylistCollection getPlaylists () {
Dispatch playlists = Dispatch.get(object, "Playlists").toDispatch();
return new ITPlaylistCollection(playlists);
}
/**
* Update the podcast feed for this track. This is equivalent to the user
* choosing Update Podcast from the contextual menu for the podcast feed
* that contains this track.
*/
public void updatePodcastFeed () {
Dispatch.call(object, "UpdatePodcastFeed");
}
/**
* Start downloading the podcast episode that corresponds to this track.
* This is equivalent to the user clicking the Get button next to this
* track.
*/
public void downloadPodcastEpisode () {
Dispatch.call(object, "DownloadPodcastEpisode");
}
/**
* Reveals the track in the main browser window.
*/
public void reveal() {
Dispatch.call(object, "Reveal");
}
}

View File

@@ -1,60 +0,0 @@
package com.dt.iTunesController;
import com.jacob.com.Dispatch;
/**
* Represents a user-defined playlist.
*
* A user playlist includes both smart and manual user-defined playlists.
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public class ITUserPlaylist extends ITPlaylist {
public ITUserPlaylist(Dispatch d) {
super(d);
}
/**
* Add a file or files inside a folder to the playlist.
* You cannot use this method to add a file that requires conversion to be
* added (e.g. a CD track), use <code>iTunes.convertFile()</code> or
* <code>iTunes.convertFile2()</code> instead. If you add a folder that
* contains files that require conversion, they will be skipped.
* @param filePath The full path to the file or folder to add.
* @return Returns an ITOperationStatus object corresponding to the
* asynchronous operation. If an error occurs, or no files were added, this
* will be set to <code>NULL</code>.
*/
public ITOperationStatus addFile (String filePath) {
Dispatch status = Dispatch.call(object, "AddFile", filePath).toDispatch();
return new ITOperationStatus(status);
}
/**
* Add a streaming audio URL to the playlist.
* @param url The URL to add. The length of the URL can be 255 characters or
* less.
* @return Returns an ITURLTrack object corresponding to the new track.
*/
public ITURLTrack addURL (String url) {
Dispatch URLTrack = Dispatch.call(object, "AddURL", url).toDispatch();
return new ITURLTrack(URLTrack);
}
/**
* Add an existing track to the playlist.
* You cannot use this method to add a CD track (ITTrackKindCD) to another
* playlist, use <code>iTunes.convertTrack()</code> or
* <code>iTunes.convertTrack2()</code> instead.
* You cannot add a shared library track (ITTrackKindSharedLibrary) to
* another playlist.
* @param track The track to add.
* @return Returns an IITTrack object corresponding to the new track.
*/
public ITTrack addTrack (ITTrack track) {
Dispatch trackToAdd = track.fetchDispatch();
Dispatch addedTrack = Dispatch.call(object, "AddTrack", trackToAdd).toDispatch();
return new ITTrack(addedTrack);
}
}

View File

@@ -1,13 +0,0 @@
package com.dt.iTunesController;
/**
* Specifies the Video kind.
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public enum ITVideoKind {
ITVideoKindNone,
ITVideoKindMovie,
ITVideoKindMusicVideo,
ITVideoKindTVShow;
}

View File

@@ -1,32 +0,0 @@
package com.dt.iTunesController;
import com.jacob.com.Dispatch;
/**
* Represents an iTunes window.
*/
public class ITWindow {
protected Dispatch object;
public ITWindow(Dispatch d) {
object = d;
}
/**
* Returns the JACOB Dispatch object for this object.
* @return Returns the JACOB Dispatch object for this object.
*/
public Dispatch fetchDispatch() {
return object;
}
/**
* Returns the name of the object.
* @return Returns the name of the object.
*/
public String getName() {
return Dispatch.get(object, "Name").getString();
}
}

View File

@@ -1,55 +0,0 @@
package com.dt.iTunesController;
import com.jacob.com.Dispatch;
/**
* Represents a collection of window objects.
*
* Note that collection indices are always 1-based.
*
* You can retrieve all the windows using
* <code>iTunes.getWindows()</code>.
*
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public class ITWindowCollection {
protected Dispatch object;
public ITWindowCollection(Dispatch d) {
object = d;
}
// TODO: iTunes.getWindows()
/**
* Returns the number of playlists in the collection.
* @return Returns the number of playlists in the collection.
*/
public int getCount() {
return Dispatch.get(object, "Count").getInt();
}
/**
* Returns an ITWindow object corresponding to the given index (1-based).
* @param index Index of the playlist to retrieve, must be less than or
* equal to <code>ITWindowCollection.getCount()</code>.
* @return Returns an ITWindow object corresponding to the given index.
* Will be set to NULL if no playlist could be retrieved.
*/
public ITWindow getItem (int index) {
Dispatch item = Dispatch.call(object, "Item", index).toDispatch();
return new ITWindow(item);
}
/**
* Returns an ITWindow object with the specified name.
* @param name The name of the window to retrieve.
* @return Returns an ITWindow object corresponding to the given index.
* Will be set to NULL if no ITWindow could be retrieved.
*/
public ITWindow ItemByName (String name) {
Dispatch item = Dispatch.call(object, "ItemByName", name).toDispatch();
return new ITWindow(item);
}
}

View File

@@ -1,488 +0,0 @@
package com.dt.iTunesController;
import com.jacob.activeX.*;
import com.jacob.com.Dispatch;
import com.jacob.com.DispatchEvents;
import com.jacob.com.Variant;
/**
* Defines the top-level iTunes application object.
*
* This interface defines the top-level iTunes application object. All other
* iTunes interfaces are accessed through this object.
*
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public class iTunes {
ActiveXComponent iTunes;
iTunesEvents iTunesEvents;
DispatchEvents dispatchEvents;
/**
* Initiate iTunes Controller.
*/
public iTunes() {
iTunes = new ActiveXComponent("iTunes.Application");
}
/**
* Add an event handler to the iTunes controller.
* @param itef The class that will handle the iTunes events.
*/
public void addEventHandler(iTunesEventsInterface itef) {
iTunesEvents = new iTunesEvents(itef);
dispatchEvents = new DispatchEvents(iTunes, iTunesEvents);
System.out.println("New event handler added.");
}
/**
* Reposition to the beginning of the current track or go to the previous
* track if already at start of current track.
*/
public void backTrack() {
iTunes.invoke("BackTrack");
}
/**
* Skip forward in a playing track.
*/
public void fastForward() {
iTunes.invoke("FastForward");
}
/**
* Advance to the next track in the current playlist.
*/
public void nextTrack() {
iTunes.invoke("NextTrack");
}
/**
* Pause playback.
*/
public void pause() {
iTunes.invoke("Pause");
}
/**
* Play the currently targeted track.
*/
public void play() {
Variant s = iTunes.invoke("ASDSDPlay");
}
/**
* Play the specified file path, adding it to the library if not already
* present.
*/
public void playFile(String filePath) {
iTunes.invoke("PlayFile", filePath);
}
/**
* Toggle the playing/paused state of the current track.
*/
public void playPause() {
iTunes.invoke("PlayPause");
}
/**
* Return to the previous track in the current playlist.
*/
public void previousTrack() {
iTunes.invoke("PreviousTrack");
}
/**
* Disable fast forward/rewind and resume playback, if playing.
*/
public void resume() {
iTunes.invoke("Resume");
}
/**
* Skip backwards in a playing track.
*/
public void rewind() {
iTunes.invoke("Rewind");
}
/**
* Stop playback.
*/
public void stop() {
iTunes.invoke("Stop");
}
/**
* Retrieves the current state of the player buttons in the window
* containing the currently targeted track. If there is no currently
* targeted track, returns the current state of the player buttons
* in the main browser window.
*/
public void getPlayerButtonsState(boolean previousEnabled,
String playPause, boolean nextEnabled) {
}
/**
* Returns true if this version of the iTunes type library is compatible
* with the specified version.
* @param majorVersion Major version of iTunes interface.
* @param minorVersion Minor version of iTunes interface.
* @return Returns true if this version is compatible with the indicated
* interface version.
*/
public boolean getCheckVersion (int majorVersion, int minorVersion) {
return iTunes.invoke("CheckVersion", majorVersion, minorVersion).getBoolean();
}
/**
* Returns an IITObject corresponding to the specified IDs.
* The object may be a source, playlist, or track.
* @param sourceID The ID that identifies the source. Valid for a source,
* playlist, or track.
* @param playlistID The ID that identifies the playlist. Valid for a
* playlist or track. Must be zero for a source.
* @param trackID The ID that identifies the track within the playlist.
* Valid for a track. Must be zero for a source or playlist.
* @param databaseID The ID that identifies the track, independent of its
* playlist. Valid for a track. Must be zero for a source or playlist.
* @return Returns an IITObject object corresponding to the specified IDs.
* Will be set to NULL if no object could be retrieved.
*/
public ITObject getITObjectByID(int sourceID, int playlistID, int trackID, int databaseID) {
Dispatch object = Dispatch.call(iTunes, "GetITObjectByID", sourceID, playlistID, trackID, databaseID).toDispatch();
return new ITObject(object);
}
/**
* Creates a new playlist in the main library.
* @param playlistName The name of the new playlist (may be empty).
* @return Returns an ITPlaylist object corresponding to the new playlist.
*/
public ITPlaylist createPlaylist(String playlistName) {
Dispatch cplaylist = Dispatch.call(iTunes, "CreatePlaylist", playlistName).toDispatch();
ITPlaylist playlist = new ITPlaylist(cplaylist);
ITPlaylistKind playlistKind = playlist.getKind();
if (playlistKind == ITPlaylistKind.ITPlaylistKindCD)
return new ITAudioCDPlaylist(cplaylist);
else if (playlist.getKind() == ITPlaylistKind.ITPlaylistKindLibrary)
return new ITLibraryPlaylist(cplaylist);
else if (playlist.getKind() == ITPlaylistKind.ITPlaylistKindUser)
return new ITUserPlaylist(cplaylist);
else
return playlist;
}
/**
* Open the specified iTunes Store or streaming audio URL.
* @param url The URL to open. The length of the URL cannot exceed 512
* characters. iTunes Store URLs start with itms:// or itmss://. Streaming
* audio URLs start with http://.
*/
public void openURL (String url) {
iTunes.invoke("OpenURL", url);
}
/**
* Go to the iTunes Store home page.
*/
public void gotoMusicStoreHomePage() {
iTunes.invoke("GoToMusicStoreHomePage");
}
/**
* Update the contents of the iPod.
*/
public void updateIPod() {
iTunes.invoke("UpdateIPod");
}
/**
* Exits the iTunes application.
*/
public void quit() {
iTunes.invoke("Quit");
}
/**
* Creates a new EQ preset.
* The EQ preset will be created "flat", i.e. the preamp and all band levels
* will be set to 0.
* EQ preset names cannot start with leading spaces. If you specify a name
* that starts with leading spaces they will be stripped out.
* If <code>eqPresetName</code> is empty, the EQ preset will be created with
* a default name.
* @param eqPresetName The name of the new EQ Preset (may be empty)
* @return Returns an ITEQPreset object corresponding to the new EQ Preset.
*/
public ITEQPreset createEQPreset(String eqPresetName) {
Dispatch eqPreset = Dispatch.call(iTunes, "CreateEQPreset", eqPresetName).toDispatch();
return new ITEQPreset(eqPreset);
}
/**
* Creates a new playlist in an existing source.
* You may not be able to create a playlist in every source. For example,
* you cannot create a playlist in an audio CD source, or in an iPod source
* if it is in auto update mode.
* If <code>playlistName</code> is empty, the playlist will be created with
* a default name.
* @param playlistName The name of the new playlist (may be empty).
* @param source The source that will contain the new playlist.
* @return Returns an ITPlaylist object corresponding to the new playlist.
*/
public ITPlaylist createPlaylistInSource(String playlistName, ITSource source) {
Dispatch cplaylist = Dispatch.call(iTunes, "CreatePlaylistInSource", playlistName, source.fetchDispatch()).toDispatch();
ITPlaylist playlist = new ITPlaylist(cplaylist);
ITPlaylistKind playlistKind = playlist.getKind();
if (playlistKind == ITPlaylistKind.ITPlaylistKindCD)
return new ITAudioCDPlaylist(cplaylist);
else if (playlist.getKind() == ITPlaylistKind.ITPlaylistKindLibrary)
return new ITLibraryPlaylist(cplaylist);
else if (playlist.getKind() == ITPlaylistKind.ITPlaylistKindUser)
return new ITUserPlaylist(cplaylist);
else
return playlist;
}
/**
* Subscribes to the specified podcast feed URL. Any "unsafe" characters in
* the URL should already be converted into their corresponding escape
* sequences, iTunes will not do this.
* @param url The URL to subscribe to.
*/
public void subscribeToPodcast(String url) {
iTunes.invoke("SubscribeToPodcast", url);
}
/**
* Updates all podcast feeds. This is equivalent to the user pressing the
* Update button when Podcasts is selected in the Source list.
*/
public void updatePodcastFeeds() {
iTunes.invoke("UpdatePodcastFeeds");
}
/**
* Creates a new folder in the main library.
* If <code>folderName</code> is empty, the folder will be created with a
* default name.
* @param folderName The name of the new folder (may be empty).
* @return Returns an ITPlaylist object corresponding to the new folder.
*/
public ITUserPlaylist createFolder(String folderName) {
Dispatch folder = Dispatch.call(iTunes, "CreateFolder", folderName).toDispatch();
return new ITUserPlaylist(folder);
}
/**
* Creates a new folder in an existing source.
* You may not be able to create a folder in every source. For example, you
* cannot create a folder in an audio CD source, or in an iPod source if it
* is in auto update mode.
* If <code>folderName</code> is empty, the folder will be created with a
* default name.
* @param folderName The name of the new folder (may be empty)
* @param iSource The source that will contain the new folder.
* @return Returns an ITPlaylist object corresponding to the new folder.
*/
public ITUserPlaylist createFolderInSource(String folderName, ITSource iSource) {
Dispatch folder = Dispatch.call(iTunes, "CreateFolderInSource", folderName, iSource.fetchDispatch()).toDispatch();
return new ITUserPlaylist(folder);
}
/**
* Returns a collection of music sources (music library, CD, device, etc.).
* @return Collection of ITSource objects.
*/
public ITSourceCollection getSources() {
Dispatch sources = Dispatch.call(iTunes, "Sources").toDispatch();
return new ITSourceCollection(sources);
}
/**
* Sets the sound output volume (0=minimum, 100=maximum).
* @param volume New sound output volume
*/
public void setSoundVolume(int volume) {
iTunes.setProperty("SoundVolume", volume);
}
/**
* Returns the sound output volume (0=minimum, 100=maximum).
* @return Current sound output volume
*/
public int getSoundVolume() {
return iTunes.getPropertyAsInt("SoundVolume");
}
/**
* Sets sound output mute state.
* @param shouldMute If true, sound output will be muted.
*/
public void setMute(boolean shouldMute) {
iTunes.setProperty("Mute", shouldMute);
}
/**
* Returns true if the sound output is muted.
* @return True if sound output is muted.
*/
public boolean getMute() {
return iTunes.getPropertyAsBoolean("Mute");
}
/**
* Returns the current player state.
* @return Returns the current player state.
*/
public ITPlayerState getPlayerState() {
return ITPlayerState.values()[Dispatch.get(iTunes, "PlayerState").getInt()];
}
/**
* Sets the player's position within the currently playing track in
* seconds.
* If playerPos specifies a position before the beginning of the track,
* the position will be set to the beginning. If playerPos specifies a
* position after the end of the track, the position will be set to the
* end.
* @param playerPos The player's position within the currently playing
* track in seconds.
*/
public void setPlayerPosition(int playerPos) {
iTunes.setProperty("playerPosition", playerPos);
}
/**
* Returns the player's position within the currently playing track in
* seconds.
* @return The player's position within the currently playing track in
* seconds.
*/
public int getPlayerPosition() {
return iTunes.getPropertyAsInt("playerPosition");
}
/**
* Returns the source that represents the main library.
* You can also find the main library source by iterating over
* <code>iTunes.getSources()</code> and looking for an <code>ITSource</code>
* of kind <code>ITSourceKindLibrary</code>.
* @return Returns the source that represents the main library.
*/
public ITSource getLibrarySource() {
Dispatch lsource = iTunes.getProperty("LibrarySource").toDispatch();
return new ITSource(lsource);
}
/**
* Returns the main library playlist in the main library source.
* @return An IITLibraryPlaylist object corresponding to the main library
* playlist.
*/
public ITLibraryPlaylist getLibraryPlaylist() {
Dispatch lplaylist = iTunes.getProperty("LibraryPlaylist").toDispatch();
return new ITLibraryPlaylist(lplaylist);
}
/**
* Returns the currently targetd track.
* @return An ITTrack object corresponding to the currently targeted track.
* Will be set to NULL if there is no currently targeted track.
*/
public ITTrack getCurrentTrack() {
Dispatch item = iTunes.getProperty("CurrentTrack").toDispatch();
ITTrack track = new ITTrack(item);
if (track.getKind()==ITTrackKind.ITTrackKindFile) {
return new ITFileOrCDTrack(item);
} else if (track.getKind()==ITTrackKind.ITTrackKindCD) {
return new ITFileOrCDTrack(item);
} else if (track.getKind()==ITTrackKind.ITTrackKindURL ) {
return new ITURLTrack(item);
} else {
return track;
}
}
/**
* Returns the playlist containing the currently targeted track.
* @return An ITPlaylist object corresponding to the playlist containing the
* currently targeted track.
* Will be set to NULL if there is no currently targeted playlist.
*/
public ITPlaylist getCurrentPlaylist() {
Dispatch cplaylist = iTunes.getProperty("CurrentPlaylist").toDispatch();
ITPlaylist playlist = new ITPlaylist(cplaylist);
ITPlaylistKind playlistKind = playlist.getKind();
if (playlistKind == ITPlaylistKind.ITPlaylistKindCD)
return new ITAudioCDPlaylist(cplaylist);
else if (playlist.getKind() == ITPlaylistKind.ITPlaylistKindLibrary)
return new ITLibraryPlaylist(cplaylist);
else if (playlist.getKind() == ITPlaylistKind.ITPlaylistKindUser)
return new ITUserPlaylist(cplaylist);
else
return playlist;
}
/**
* Returns a collection containing the currently selected track or tracks.
* The frontmost visible window in iTunes must be a browser or playlist
* window. If there is no frontmost visible window (e.g. iTunes is minimized
* to the system tray), the main browser window is used.
* @return Collection of ITrack objects.
* Will be set to NULL if there is no current selection.
*/
public ITTrackCollection getSelectedTracks() {
Dispatch stracks = iTunes.getProperty("SelectedTracks").toDispatch();
return new ITTrackCollection(stracks);
}
/**
* Returns the version of the iTunes application.
* @return
*/
public String getVersion() {
return iTunes.getPropertyAsString("Version");
}
/**
* Returns the high 32 bits of the persistent ID of the specified IITObject.
* See the documentation on IITObject for more information on persistent
* IDs.
*
* The object may be a source, playlist, or track.
* @param iObject The object to fetch the High Persistent ID.
* @return The high 32 bits of the 64-bit persistent ID.
*/
public long getITObjectPersistentIDHigh (ITObject iObject) {
Dispatch object = iObject.fetchDispatch();
return Dispatch.call(object, "GetObjectPersistentIDHigh", object).getLong();
}
/**
* Returns the low 32 bits of the persistent ID of the specified IITObject.
* See the documentation on IITObject for more information on persistent
* IDs.
*
* The object may be a source, playlist, or track.
* @param iObject The object to fetch the Low Persistent ID.
* @return The low 32 bits of the 64-bit persistent ID.
*/
public long getITObjectPersistentIDLow (ITObject iObject) {
Dispatch object = iObject.fetchDispatch();
return Dispatch.call(object, "GetObjectPersistentIDLow", object).getLong();
}
public ITObjectPersistentID getObjectPersistentIDs(ITObject iObject){
return new ITObjectPersistentID(getITObjectPersistentIDHigh(iObject),getITObjectPersistentIDLow(iObject));
}
public ITBrowserWindow getBrowserWindow(){
Dispatch window = iTunes.getProperty("BrowserWindow").toDispatch();
return new ITBrowserWindow(window);
}
}

View File

@@ -1,62 +0,0 @@
package com.dt.iTunesController;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
/**
* This class is used to forward all iTunes COM Events to a class that
* implements <code>iTunesEventsInterface</code>. To receive events, create
* a class that implements the interface, and then use
* <code>iTunes.addEventHandler()</code>.
*
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public class iTunesEvents {
private iTunesEventsInterface eventHandler;
public iTunesEvents (iTunesEventsInterface itef) {
eventHandler = itef;
}
public void OnDatabaseChangedEvent(Variant[] args) {
// Not currently implemented
}
public void OnPlayerPlayEvent(Variant[] args) {
ITTrack itt = new ITTrack((Dispatch)args[0].getDispatch());
eventHandler.onPlayerPlayEvent(itt);
}
public void OnPlayerStopEvent(Variant[] args) {
ITTrack itt = new ITTrack((Dispatch)args[0].getDispatch());
eventHandler.onPlayerStopEvent(itt);
}
public void OnPlayerPlayingTrackChangedEvent(Variant[] args) {
ITTrack itt = new ITTrack((Dispatch)args[0].getDispatch());
eventHandler.onPlayerPlayingTrackChangedEvent(itt);
}
public void OnCOMCallsDisabledEvent(Variant[] args) {
ITCOMDisabledReason reason = ITCOMDisabledReason.values()[args[0].getInt()];
eventHandler.onCOMCallsDisabledEvent(reason);
}
public void OnCOMCallsEnabledEvent(Variant[] args) {
eventHandler.onCOMCallsEnabledEvent();
}
public void OnQuittingEvent(Variant[] args) {
eventHandler.onQuittingEvent();
}
public void OnAboutToPromptUserToQuitEvent(Variant[] args) {
eventHandler.onAboutToPromptUserToQuitEvent();
}
public void OnSoundVolumeChangedEvent(Variant[] args) {
eventHandler.onSoundVolumeChangedEvent(args[0].getInt());
}
}

View File

@@ -1,115 +0,0 @@
package com.dt.iTunesController;
/**
* Interface for receiving iTunes events.
* @author <a href="mailto:steve@dot-totally.co.uk">Steve Eyre</a>
* @version 0.2
*/
public interface iTunesEventsInterface {
/**
* <strong>Not currently implemented</strong>.
*
* The ITEventDatabaseChanged event is fired when the iTunes database is
* changed.
*
* Each parameter is a two-dimensional array of integers. The first
* dimension is the number of objects. The second dimension is always 4 and
* specifies each of the 4 ITObject IDs, where index 0 is the source ID,
* index 1 is the playlist ID, index 2 is the track ID, and index 3 is the
* track database ID. For more information on object IDs, see
* <code>ITObject</code>.
*
* Note that you can use <code>iTunes.getITObjectByID()</code> to retrieve
* changed ITObject, but not for deleted objects (since they no longer
* exist).
*
* @param deletedObjectIDs
* @param changedObjectIDs
*/
public void onDatabaseChangedEvent(int[][] deletedObjectIDs, int[][] changedObjectIDs);
/**
* The ITEventPlayerPlay event is fired when a track begins playing.
* @param iTrack An ITTrack object corresponding to the track that has
* started playing.
*/
public void onPlayerPlayEvent (ITTrack iTrack);
/**
* The ITEventPlayerStop event is fired when a track stops playing.
* @param iTrack An ITTrack object corresponding to the track that has
* stopped playing.
*/
public void onPlayerStopEvent (ITTrack iTrack);
/**
* The ITEventPlayerPlayingTrackChanged event is fired when information
* about the currently playing track has changed.
* This event is fired when the user changes information about the currently
* playing track (e.g. the name of the track).
* This event is also fired when iTunes plays the next joined CD track in a
* CD playlist, since joined CD tracks are treated as a single track.
* @param iTrack An ITTrack object corresponding to the track that is now
* playing.
*/
public void onPlayerPlayingTrackChangedEvent(ITTrack iTrack);
/**
* The ITEventCOMCallsDisabled event is fired when calls to the iTunes COM
* interface will be deferred.
* Typically, iTunes will defer COM calls when any modal dialog is being
* displayed. When the user dismisses the last modal dialog, COM calls will
* be enabled again, and any deferred COM calls will be executed. You can
* use this event to avoid making a COM call which will be deferred.
* @param reason The reason the COM interface is being disabled. This is
* typically <code>ITCOMDisabledReasonDialog</code>.
*/
public void onCOMCallsDisabledEvent(ITCOMDisabledReason reason);
/**
* The ITEventCOMCallsEnabled event is fired when calls to the iTunes COM
* interface will no longer be deferred.
* Typically, iTunes will defer COM calls when any modal dialog is being
* displayed. When the user dismisses the last modal dialog, COM calls will
* be enabled again, and any deferred COM calls will be executed.
*/
public void onCOMCallsEnabledEvent();
/**
* The ITEventQuitting event is fired when iTunes is about to quit.
* If the user attempts to quit iTunes while a client still has outstanding
* iTunes COM objects instantiated, iTunes will display a warning dialog.
* The user can still choose to quit iTunes anyway, in which case this event
* will be fired. After this event is fired, any existing iTunes COM objects
* will no longer be valid.
* This event is only used to notify clients that iTunes is quitting,
* clients cannot prevent this from happening.
*/
public void onQuittingEvent();
/**
* The ITEventAboutToPromptUserToQuit event is fired when iTunes is about
* prompt the user to quit.
* This event gives clients the opportunity to prevent the warning dialog
* prompt from occurring.
* If the user attempts to quit iTunes while a client still has outstanding
* iTunes COM objects instantiated, iTunes will display a warning dialog.
* This event is fired just before the warning dialog is shown. iTunes will
* then wait up to 5 seconds for clients to release any outstanding iTunes
* COM objects. If all objects are released during this time, the warning
* dialog will not be shown and iTunes will quit immediately.
* Otherwise, the warning dialog will be shown. If the user chooses to quit
* iTunes anyway, the ITEventQuitting event is fired. See
* <code>iTunesEventsInterface.onQuittingEvent()</code> for more details.
*/
public void onAboutToPromptUserToQuitEvent();
/**
* The ITEventSoundVolumeChanged event is fired when the sound output volume
* has changed.
* @param newVolume The new sound output volume (0 = minimum, 100 = maximum).
*/
public void onSoundVolumeChangedEvent(int newVolume);
}

View File

@@ -1,523 +0,0 @@
/*
* %W% %E%
*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*/
#ifndef CLASSFILE_CONSTANTS_H
#define CLASSFILE_CONSTANTS_H
#ifdef __cplusplus
extern "C" {
#endif
/* Flags */
enum {
JVM_ACC_PUBLIC = 0x0001,
JVM_ACC_PRIVATE = 0x0002,
JVM_ACC_PROTECTED = 0x0004,
JVM_ACC_STATIC = 0x0008,
JVM_ACC_FINAL = 0x0010,
JVM_ACC_SYNCHRONIZED = 0x0020,
JVM_ACC_SUPER = 0x0020,
JVM_ACC_VOLATILE = 0x0040,
JVM_ACC_BRIDGE = 0x0040,
JVM_ACC_TRANSIENT = 0x0080,
JVM_ACC_VARARGS = 0x0080,
JVM_ACC_NATIVE = 0x0100,
JVM_ACC_INTERFACE = 0x0200,
JVM_ACC_ABSTRACT = 0x0400,
JVM_ACC_STRICT = 0x0800,
JVM_ACC_SYNTHETIC = 0x1000,
JVM_ACC_ANNOTATION = 0x2000,
JVM_ACC_ENUM = 0x4000
};
/* Used in newarray instruction. */
enum {
JVM_T_BOOLEAN = 4,
JVM_T_CHAR = 5,
JVM_T_FLOAT = 6,
JVM_T_DOUBLE = 7,
JVM_T_BYTE = 8,
JVM_T_SHORT = 9,
JVM_T_INT = 10,
JVM_T_LONG = 11
};
/* Constant Pool Entries */
enum {
JVM_CONSTANT_Utf8 = 1,
JVM_CONSTANT_Unicode = 2, /* unused */
JVM_CONSTANT_Integer = 3,
JVM_CONSTANT_Float = 4,
JVM_CONSTANT_Long = 5,
JVM_CONSTANT_Double = 6,
JVM_CONSTANT_Class = 7,
JVM_CONSTANT_String = 8,
JVM_CONSTANT_Fieldref = 9,
JVM_CONSTANT_Methodref = 10,
JVM_CONSTANT_InterfaceMethodref = 11,
JVM_CONSTANT_NameAndType = 12
};
/* StackMapTable type item numbers */
enum {
JVM_ITEM_Top = 0,
JVM_ITEM_Integer = 1,
JVM_ITEM_Float = 2,
JVM_ITEM_Double = 3,
JVM_ITEM_Long = 4,
JVM_ITEM_Null = 5,
JVM_ITEM_UninitializedThis = 6,
JVM_ITEM_Object = 7,
JVM_ITEM_Uninitialized = 8
};
/* Type signatures */
enum {
JVM_SIGNATURE_ARRAY = '[',
JVM_SIGNATURE_BYTE = 'B',
JVM_SIGNATURE_CHAR = 'C',
JVM_SIGNATURE_CLASS = 'L',
JVM_SIGNATURE_ENDCLASS = ';',
JVM_SIGNATURE_ENUM = 'E',
JVM_SIGNATURE_FLOAT = 'F',
JVM_SIGNATURE_DOUBLE = 'D',
JVM_SIGNATURE_FUNC = '(',
JVM_SIGNATURE_ENDFUNC = ')',
JVM_SIGNATURE_INT = 'I',
JVM_SIGNATURE_LONG = 'J',
JVM_SIGNATURE_SHORT = 'S',
JVM_SIGNATURE_VOID = 'V',
JVM_SIGNATURE_BOOLEAN = 'Z'
};
/* Opcodes */
enum {
JVM_OPC_nop = 0,
JVM_OPC_aconst_null = 1,
JVM_OPC_iconst_m1 = 2,
JVM_OPC_iconst_0 = 3,
JVM_OPC_iconst_1 = 4,
JVM_OPC_iconst_2 = 5,
JVM_OPC_iconst_3 = 6,
JVM_OPC_iconst_4 = 7,
JVM_OPC_iconst_5 = 8,
JVM_OPC_lconst_0 = 9,
JVM_OPC_lconst_1 = 10,
JVM_OPC_fconst_0 = 11,
JVM_OPC_fconst_1 = 12,
JVM_OPC_fconst_2 = 13,
JVM_OPC_dconst_0 = 14,
JVM_OPC_dconst_1 = 15,
JVM_OPC_bipush = 16,
JVM_OPC_sipush = 17,
JVM_OPC_ldc = 18,
JVM_OPC_ldc_w = 19,
JVM_OPC_ldc2_w = 20,
JVM_OPC_iload = 21,
JVM_OPC_lload = 22,
JVM_OPC_fload = 23,
JVM_OPC_dload = 24,
JVM_OPC_aload = 25,
JVM_OPC_iload_0 = 26,
JVM_OPC_iload_1 = 27,
JVM_OPC_iload_2 = 28,
JVM_OPC_iload_3 = 29,
JVM_OPC_lload_0 = 30,
JVM_OPC_lload_1 = 31,
JVM_OPC_lload_2 = 32,
JVM_OPC_lload_3 = 33,
JVM_OPC_fload_0 = 34,
JVM_OPC_fload_1 = 35,
JVM_OPC_fload_2 = 36,
JVM_OPC_fload_3 = 37,
JVM_OPC_dload_0 = 38,
JVM_OPC_dload_1 = 39,
JVM_OPC_dload_2 = 40,
JVM_OPC_dload_3 = 41,
JVM_OPC_aload_0 = 42,
JVM_OPC_aload_1 = 43,
JVM_OPC_aload_2 = 44,
JVM_OPC_aload_3 = 45,
JVM_OPC_iaload = 46,
JVM_OPC_laload = 47,
JVM_OPC_faload = 48,
JVM_OPC_daload = 49,
JVM_OPC_aaload = 50,
JVM_OPC_baload = 51,
JVM_OPC_caload = 52,
JVM_OPC_saload = 53,
JVM_OPC_istore = 54,
JVM_OPC_lstore = 55,
JVM_OPC_fstore = 56,
JVM_OPC_dstore = 57,
JVM_OPC_astore = 58,
JVM_OPC_istore_0 = 59,
JVM_OPC_istore_1 = 60,
JVM_OPC_istore_2 = 61,
JVM_OPC_istore_3 = 62,
JVM_OPC_lstore_0 = 63,
JVM_OPC_lstore_1 = 64,
JVM_OPC_lstore_2 = 65,
JVM_OPC_lstore_3 = 66,
JVM_OPC_fstore_0 = 67,
JVM_OPC_fstore_1 = 68,
JVM_OPC_fstore_2 = 69,
JVM_OPC_fstore_3 = 70,
JVM_OPC_dstore_0 = 71,
JVM_OPC_dstore_1 = 72,
JVM_OPC_dstore_2 = 73,
JVM_OPC_dstore_3 = 74,
JVM_OPC_astore_0 = 75,
JVM_OPC_astore_1 = 76,
JVM_OPC_astore_2 = 77,
JVM_OPC_astore_3 = 78,
JVM_OPC_iastore = 79,
JVM_OPC_lastore = 80,
JVM_OPC_fastore = 81,
JVM_OPC_dastore = 82,
JVM_OPC_aastore = 83,
JVM_OPC_bastore = 84,
JVM_OPC_castore = 85,
JVM_OPC_sastore = 86,
JVM_OPC_pop = 87,
JVM_OPC_pop2 = 88,
JVM_OPC_dup = 89,
JVM_OPC_dup_x1 = 90,
JVM_OPC_dup_x2 = 91,
JVM_OPC_dup2 = 92,
JVM_OPC_dup2_x1 = 93,
JVM_OPC_dup2_x2 = 94,
JVM_OPC_swap = 95,
JVM_OPC_iadd = 96,
JVM_OPC_ladd = 97,
JVM_OPC_fadd = 98,
JVM_OPC_dadd = 99,
JVM_OPC_isub = 100,
JVM_OPC_lsub = 101,
JVM_OPC_fsub = 102,
JVM_OPC_dsub = 103,
JVM_OPC_imul = 104,
JVM_OPC_lmul = 105,
JVM_OPC_fmul = 106,
JVM_OPC_dmul = 107,
JVM_OPC_idiv = 108,
JVM_OPC_ldiv = 109,
JVM_OPC_fdiv = 110,
JVM_OPC_ddiv = 111,
JVM_OPC_irem = 112,
JVM_OPC_lrem = 113,
JVM_OPC_frem = 114,
JVM_OPC_drem = 115,
JVM_OPC_ineg = 116,
JVM_OPC_lneg = 117,
JVM_OPC_fneg = 118,
JVM_OPC_dneg = 119,
JVM_OPC_ishl = 120,
JVM_OPC_lshl = 121,
JVM_OPC_ishr = 122,
JVM_OPC_lshr = 123,
JVM_OPC_iushr = 124,
JVM_OPC_lushr = 125,
JVM_OPC_iand = 126,
JVM_OPC_land = 127,
JVM_OPC_ior = 128,
JVM_OPC_lor = 129,
JVM_OPC_ixor = 130,
JVM_OPC_lxor = 131,
JVM_OPC_iinc = 132,
JVM_OPC_i2l = 133,
JVM_OPC_i2f = 134,
JVM_OPC_i2d = 135,
JVM_OPC_l2i = 136,
JVM_OPC_l2f = 137,
JVM_OPC_l2d = 138,
JVM_OPC_f2i = 139,
JVM_OPC_f2l = 140,
JVM_OPC_f2d = 141,
JVM_OPC_d2i = 142,
JVM_OPC_d2l = 143,
JVM_OPC_d2f = 144,
JVM_OPC_i2b = 145,
JVM_OPC_i2c = 146,
JVM_OPC_i2s = 147,
JVM_OPC_lcmp = 148,
JVM_OPC_fcmpl = 149,
JVM_OPC_fcmpg = 150,
JVM_OPC_dcmpl = 151,
JVM_OPC_dcmpg = 152,
JVM_OPC_ifeq = 153,
JVM_OPC_ifne = 154,
JVM_OPC_iflt = 155,
JVM_OPC_ifge = 156,
JVM_OPC_ifgt = 157,
JVM_OPC_ifle = 158,
JVM_OPC_if_icmpeq = 159,
JVM_OPC_if_icmpne = 160,
JVM_OPC_if_icmplt = 161,
JVM_OPC_if_icmpge = 162,
JVM_OPC_if_icmpgt = 163,
JVM_OPC_if_icmple = 164,
JVM_OPC_if_acmpeq = 165,
JVM_OPC_if_acmpne = 166,
JVM_OPC_goto = 167,
JVM_OPC_jsr = 168,
JVM_OPC_ret = 169,
JVM_OPC_tableswitch = 170,
JVM_OPC_lookupswitch = 171,
JVM_OPC_ireturn = 172,
JVM_OPC_lreturn = 173,
JVM_OPC_freturn = 174,
JVM_OPC_dreturn = 175,
JVM_OPC_areturn = 176,
JVM_OPC_return = 177,
JVM_OPC_getstatic = 178,
JVM_OPC_putstatic = 179,
JVM_OPC_getfield = 180,
JVM_OPC_putfield = 181,
JVM_OPC_invokevirtual = 182,
JVM_OPC_invokespecial = 183,
JVM_OPC_invokestatic = 184,
JVM_OPC_invokeinterface = 185,
JVM_OPC_xxxunusedxxx = 186,
JVM_OPC_new = 187,
JVM_OPC_newarray = 188,
JVM_OPC_anewarray = 189,
JVM_OPC_arraylength = 190,
JVM_OPC_athrow = 191,
JVM_OPC_checkcast = 192,
JVM_OPC_instanceof = 193,
JVM_OPC_monitorenter = 194,
JVM_OPC_monitorexit = 195,
JVM_OPC_wide = 196,
JVM_OPC_multianewarray = 197,
JVM_OPC_ifnull = 198,
JVM_OPC_ifnonnull = 199,
JVM_OPC_goto_w = 200,
JVM_OPC_jsr_w = 201,
JVM_OPC_MAX = 201
};
/* Opcode length initializer, use with something like:
* unsigned char opcode_length[JVM_OPC_MAX+1] = JVM_OPCODE_LENGTH_INITIALIZER;
*/
#define JVM_OPCODE_LENGTH_INITIALIZER { \
1, /* nop */ \
1, /* aconst_null */ \
1, /* iconst_m1 */ \
1, /* iconst_0 */ \
1, /* iconst_1 */ \
1, /* iconst_2 */ \
1, /* iconst_3 */ \
1, /* iconst_4 */ \
1, /* iconst_5 */ \
1, /* lconst_0 */ \
1, /* lconst_1 */ \
1, /* fconst_0 */ \
1, /* fconst_1 */ \
1, /* fconst_2 */ \
1, /* dconst_0 */ \
1, /* dconst_1 */ \
2, /* bipush */ \
3, /* sipush */ \
2, /* ldc */ \
3, /* ldc_w */ \
3, /* ldc2_w */ \
2, /* iload */ \
2, /* lload */ \
2, /* fload */ \
2, /* dload */ \
2, /* aload */ \
1, /* iload_0 */ \
1, /* iload_1 */ \
1, /* iload_2 */ \
1, /* iload_3 */ \
1, /* lload_0 */ \
1, /* lload_1 */ \
1, /* lload_2 */ \
1, /* lload_3 */ \
1, /* fload_0 */ \
1, /* fload_1 */ \
1, /* fload_2 */ \
1, /* fload_3 */ \
1, /* dload_0 */ \
1, /* dload_1 */ \
1, /* dload_2 */ \
1, /* dload_3 */ \
1, /* aload_0 */ \
1, /* aload_1 */ \
1, /* aload_2 */ \
1, /* aload_3 */ \
1, /* iaload */ \
1, /* laload */ \
1, /* faload */ \
1, /* daload */ \
1, /* aaload */ \
1, /* baload */ \
1, /* caload */ \
1, /* saload */ \
2, /* istore */ \
2, /* lstore */ \
2, /* fstore */ \
2, /* dstore */ \
2, /* astore */ \
1, /* istore_0 */ \
1, /* istore_1 */ \
1, /* istore_2 */ \
1, /* istore_3 */ \
1, /* lstore_0 */ \
1, /* lstore_1 */ \
1, /* lstore_2 */ \
1, /* lstore_3 */ \
1, /* fstore_0 */ \
1, /* fstore_1 */ \
1, /* fstore_2 */ \
1, /* fstore_3 */ \
1, /* dstore_0 */ \
1, /* dstore_1 */ \
1, /* dstore_2 */ \
1, /* dstore_3 */ \
1, /* astore_0 */ \
1, /* astore_1 */ \
1, /* astore_2 */ \
1, /* astore_3 */ \
1, /* iastore */ \
1, /* lastore */ \
1, /* fastore */ \
1, /* dastore */ \
1, /* aastore */ \
1, /* bastore */ \
1, /* castore */ \
1, /* sastore */ \
1, /* pop */ \
1, /* pop2 */ \
1, /* dup */ \
1, /* dup_x1 */ \
1, /* dup_x2 */ \
1, /* dup2 */ \
1, /* dup2_x1 */ \
1, /* dup2_x2 */ \
1, /* swap */ \
1, /* iadd */ \
1, /* ladd */ \
1, /* fadd */ \
1, /* dadd */ \
1, /* isub */ \
1, /* lsub */ \
1, /* fsub */ \
1, /* dsub */ \
1, /* imul */ \
1, /* lmul */ \
1, /* fmul */ \
1, /* dmul */ \
1, /* idiv */ \
1, /* ldiv */ \
1, /* fdiv */ \
1, /* ddiv */ \
1, /* irem */ \
1, /* lrem */ \
1, /* frem */ \
1, /* drem */ \
1, /* ineg */ \
1, /* lneg */ \
1, /* fneg */ \
1, /* dneg */ \
1, /* ishl */ \
1, /* lshl */ \
1, /* ishr */ \
1, /* lshr */ \
1, /* iushr */ \
1, /* lushr */ \
1, /* iand */ \
1, /* land */ \
1, /* ior */ \
1, /* lor */ \
1, /* ixor */ \
1, /* lxor */ \
3, /* iinc */ \
1, /* i2l */ \
1, /* i2f */ \
1, /* i2d */ \
1, /* l2i */ \
1, /* l2f */ \
1, /* l2d */ \
1, /* f2i */ \
1, /* f2l */ \
1, /* f2d */ \
1, /* d2i */ \
1, /* d2l */ \
1, /* d2f */ \
1, /* i2b */ \
1, /* i2c */ \
1, /* i2s */ \
1, /* lcmp */ \
1, /* fcmpl */ \
1, /* fcmpg */ \
1, /* dcmpl */ \
1, /* dcmpg */ \
3, /* ifeq */ \
3, /* ifne */ \
3, /* iflt */ \
3, /* ifge */ \
3, /* ifgt */ \
3, /* ifle */ \
3, /* if_icmpeq */ \
3, /* if_icmpne */ \
3, /* if_icmplt */ \
3, /* if_icmpge */ \
3, /* if_icmpgt */ \
3, /* if_icmple */ \
3, /* if_acmpeq */ \
3, /* if_acmpne */ \
3, /* goto */ \
3, /* jsr */ \
2, /* ret */ \
99, /* tableswitch */ \
99, /* lookupswitch */ \
1, /* ireturn */ \
1, /* lreturn */ \
1, /* freturn */ \
1, /* dreturn */ \
1, /* areturn */ \
1, /* return */ \
3, /* getstatic */ \
3, /* putstatic */ \
3, /* getfield */ \
3, /* putfield */ \
3, /* invokevirtual */ \
3, /* invokespecial */ \
3, /* invokestatic */ \
5, /* invokeinterface */ \
0, /* xxxunusedxxx */ \
3, /* new */ \
2, /* newarray */ \
3, /* anewarray */ \
1, /* arraylength */ \
1, /* athrow */ \
3, /* checkcast */ \
3, /* instanceof */ \
1, /* monitorenter */ \
1, /* monitorexit */ \
0, /* wide */ \
4, /* multianewarray */ \
3, /* ifnull */ \
3, /* ifnonnull */ \
5, /* goto_w */ \
5 /* jsr_w */ \
}
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif /* CLASSFILE_CONSTANTS */

View File

@@ -1,278 +0,0 @@
/*
* %W% %E%
*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
#ifndef _JAVASOFT_JAWT_H_
#define _JAVASOFT_JAWT_H_
#include "jni.h"
#ifdef __cplusplus
extern "C" {
#endif
/*
* AWT native interface (new in JDK 1.3)
*
* The AWT native interface allows a native C or C++ application a means
* by which to access native structures in AWT. This is to facilitate moving
* legacy C and C++ applications to Java and to target the needs of the
* community who, at present, wish to do their own native rendering to canvases
* for performance reasons. Standard extensions such as Java3D also require a
* means to access the underlying native data structures of AWT.
*
* There may be future extensions to this API depending on demand.
*
* A VM does not have to implement this API in order to pass the JCK.
* It is recommended, however, that this API is implemented on VMs that support
* standard extensions, such as Java3D.
*
* Since this is a native API, any program which uses it cannot be considered
* 100% pure java.
*/
/*
* AWT Native Drawing Surface (JAWT_DrawingSurface).
*
* For each platform, there is a native drawing surface structure. This
* platform-specific structure can be found in jawt_md.h. It is recommended
* that additional platforms follow the same model. It is also recommended
* that VMs on Win32 and Solaris support the existing structures in jawt_md.h.
*
*******************
* EXAMPLE OF USAGE:
*******************
*
* In Win32, a programmer wishes to access the HWND of a canvas to perform
* native rendering into it. The programmer has declared the paint() method
* for their canvas subclass to be native:
*
*
* MyCanvas.java:
*
* import java.awt.*;
*
* public class MyCanvas extends Canvas {
*
* static {
* System.loadLibrary("mylib");
* }
*
* public native void paint(Graphics g);
* }
*
*
* myfile.c:
*
* #include "jawt_md.h"
* #include <assert.h>
*
* JNIEXPORT void JNICALL
* Java_MyCanvas_paint(JNIEnv* env, jobject canvas, jobject graphics)
* {
* JAWT awt;
* JAWT_DrawingSurface* ds;
* JAWT_DrawingSurfaceInfo* dsi;
* JAWT_Win32DrawingSurfaceInfo* dsi_win;
* jboolean result;
* jint lock;
*
* // Get the AWT
* awt.version = JAWT_VERSION_1_3;
* result = JAWT_GetAWT(env, &awt);
* assert(result != JNI_FALSE);
*
* // Get the drawing surface
* ds = awt.GetDrawingSurface(env, canvas);
* assert(ds != NULL);
*
* // Lock the drawing surface
* lock = ds->Lock(ds);
* assert((lock & JAWT_LOCK_ERROR) == 0);
*
* // Get the drawing surface info
* dsi = ds->GetDrawingSurfaceInfo(ds);
*
* // Get the platform-specific drawing info
* dsi_win = (JAWT_Win32DrawingSurfaceInfo*)dsi->platformInfo;
*
* //////////////////////////////
* // !!! DO PAINTING HERE !!! //
* //////////////////////////////
*
* // Free the drawing surface info
* ds->FreeDrawingSurfaceInfo(dsi);
*
* // Unlock the drawing surface
* ds->Unlock(ds);
*
* // Free the drawing surface
* awt.FreeDrawingSurface(ds);
* }
*
*/
/*
* JAWT_Rectangle
* Structure for a native rectangle.
*/
typedef struct jawt_Rectangle {
jint x;
jint y;
jint width;
jint height;
} JAWT_Rectangle;
struct jawt_DrawingSurface;
/*
* JAWT_DrawingSurfaceInfo
* Structure for containing the underlying drawing information of a component.
*/
typedef struct jawt_DrawingSurfaceInfo {
/*
* Pointer to the platform-specific information. This can be safely
* cast to a JAWT_Win32DrawingSurfaceInfo on Windows or a
* JAWT_X11DrawingSurfaceInfo on Solaris. See jawt_md.h for details.
*/
void* platformInfo;
/* Cached pointer to the underlying drawing surface */
struct jawt_DrawingSurface* ds;
/* Bounding rectangle of the drawing surface */
JAWT_Rectangle bounds;
/* Number of rectangles in the clip */
jint clipSize;
/* Clip rectangle array */
JAWT_Rectangle* clip;
} JAWT_DrawingSurfaceInfo;
#define JAWT_LOCK_ERROR 0x00000001
#define JAWT_LOCK_CLIP_CHANGED 0x00000002
#define JAWT_LOCK_BOUNDS_CHANGED 0x00000004
#define JAWT_LOCK_SURFACE_CHANGED 0x00000008
/*
* JAWT_DrawingSurface
* Structure for containing the underlying drawing information of a component.
* All operations on a JAWT_DrawingSurface MUST be performed from the same
* thread as the call to GetDrawingSurface.
*/
typedef struct jawt_DrawingSurface {
/*
* Cached reference to the Java environment of the calling thread.
* If Lock(), Unlock(), GetDrawingSurfaceInfo() or
* FreeDrawingSurfaceInfo() are called from a different thread,
* this data member should be set before calling those functions.
*/
JNIEnv* env;
/* Cached reference to the target object */
jobject target;
/*
* Lock the surface of the target component for native rendering.
* When finished drawing, the surface must be unlocked with
* Unlock(). This function returns a bitmask with one or more of the
* following values:
*
* JAWT_LOCK_ERROR - When an error has occurred and the surface could not
* be locked.
*
* JAWT_LOCK_CLIP_CHANGED - When the clip region has changed.
*
* JAWT_LOCK_BOUNDS_CHANGED - When the bounds of the surface have changed.
*
* JAWT_LOCK_SURFACE_CHANGED - When the surface itself has changed
*/
jint (JNICALL *Lock)
(struct jawt_DrawingSurface* ds);
/*
* Get the drawing surface info.
* The value returned may be cached, but the values may change if
* additional calls to Lock() or Unlock() are made.
* Lock() must be called before this can return a valid value.
* Returns NULL if an error has occurred.
* When finished with the returned value, FreeDrawingSurfaceInfo must be
* called.
*/
JAWT_DrawingSurfaceInfo* (JNICALL *GetDrawingSurfaceInfo)
(struct jawt_DrawingSurface* ds);
/*
* Free the drawing surface info.
*/
void (JNICALL *FreeDrawingSurfaceInfo)
(JAWT_DrawingSurfaceInfo* dsi);
/*
* Unlock the drawing surface of the target component for native rendering.
*/
void (JNICALL *Unlock)
(struct jawt_DrawingSurface* ds);
} JAWT_DrawingSurface;
/*
* JAWT
* Structure for containing native AWT functions.
*/
typedef struct jawt {
/*
* Version of this structure. This must always be set before
* calling JAWT_GetAWT()
*/
jint version;
/*
* Return a drawing surface from a target jobject. This value
* may be cached.
* Returns NULL if an error has occurred.
* Target must be a java.awt.Component (should be a Canvas
* or Window for native rendering).
* FreeDrawingSurface() must be called when finished with the
* returned JAWT_DrawingSurface.
*/
JAWT_DrawingSurface* (JNICALL *GetDrawingSurface)
(JNIEnv* env, jobject target);
/*
* Free the drawing surface allocated in GetDrawingSurface.
*/
void (JNICALL *FreeDrawingSurface)
(JAWT_DrawingSurface* ds);
/*
* Since 1.4
* Locks the entire AWT for synchronization purposes
*/
void (JNICALL *Lock)(JNIEnv* env);
/*
* Since 1.4
* Unlocks the entire AWT for synchronization purposes
*/
void (JNICALL *Unlock)(JNIEnv* env);
/*
* Since 1.4
* Returns a reference to a java.awt.Component from a native
* platform handle. On Windows, this corresponds to an HWND;
* on Solaris and Linux, this is a Drawable. For other platforms,
* see the appropriate machine-dependent header file for a description.
* The reference returned by this function is a local
* reference that is only valid in this environment.
* This function returns a NULL reference if no component could be
* found with matching platform information.
*/
jobject (JNICALL *GetComponent)(JNIEnv* env, void* platformInfo);
} JAWT;
/*
* Get the AWT native structure. This function returns JNI_FALSE if
* an error occurs.
*/
_JNI_IMPORT_OR_EXPORT_
jboolean JNICALL JAWT_GetAWT(JNIEnv* env, JAWT* awt);
#define JAWT_VERSION_1_3 0x00010003
#define JAWT_VERSION_1_4 0x00010004
#ifdef __cplusplus
} /* extern "C" */
#endif
#endif /* !_JAVASOFT_JAWT_H_ */

View File

@@ -1,237 +0,0 @@
/*
* %W% %E%
*
* Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*/
/*
* Java Debug Wire Protocol Transport Service Provider Interface.
*/
#ifndef JDWPTRANSPORT_H
#define JDWPTRANSPORT_H
#include "jni.h"
enum {
JDWPTRANSPORT_VERSION_1_0 = 0x00010000
};
#ifdef __cplusplus
extern "C" {
#endif
struct jdwpTransportNativeInterface_;
struct _jdwpTransportEnv;
#ifdef __cplusplus
typedef _jdwpTransportEnv jdwpTransportEnv;
#else
typedef const struct jdwpTransportNativeInterface_ *jdwpTransportEnv;
#endif /* __cplusplus */
/*
* Errors. Universal errors with JVMTI/JVMDI equivalents keep the
* values the same.
*/
typedef enum {
JDWPTRANSPORT_ERROR_NONE = 0,
JDWPTRANSPORT_ERROR_ILLEGAL_ARGUMENT = 103,
JDWPTRANSPORT_ERROR_OUT_OF_MEMORY = 110,
JDWPTRANSPORT_ERROR_INTERNAL = 113,
JDWPTRANSPORT_ERROR_ILLEGAL_STATE = 201,
JDWPTRANSPORT_ERROR_IO_ERROR = 202,
JDWPTRANSPORT_ERROR_TIMEOUT = 203,
JDWPTRANSPORT_ERROR_MSG_NOT_AVAILABLE = 204
} jdwpTransportError;
/*
* Structure to define capabilities
*/
typedef struct {
unsigned int can_timeout_attach :1;
unsigned int can_timeout_accept :1;
unsigned int can_timeout_handshake :1;
unsigned int reserved3 :1;
unsigned int reserved4 :1;
unsigned int reserved5 :1;
unsigned int reserved6 :1;
unsigned int reserved7 :1;
unsigned int reserved8 :1;
unsigned int reserved9 :1;
unsigned int reserved10 :1;
unsigned int reserved11 :1;
unsigned int reserved12 :1;
unsigned int reserved13 :1;
unsigned int reserved14 :1;
unsigned int reserved15 :1;
} JDWPTransportCapabilities;
/*
* Structures to define packet layout.
*
* See: http://java.sun.com/j2se/1.5/docs/guide/jpda/jdwp-spec.html
*/
enum {
JDWPTRANSPORT_FLAGS_NONE = 0x0,
JDWPTRANSPORT_FLAGS_REPLY = 0x80
};
typedef struct {
jint len;
jint id;
jbyte flags;
jbyte cmdSet;
jbyte cmd;
jbyte *data;
} jdwpCmdPacket;
typedef struct {
jint len;
jint id;
jbyte flags;
jshort errorCode;
jbyte *data;
} jdwpReplyPacket;
typedef struct {
union {
jdwpCmdPacket cmd;
jdwpReplyPacket reply;
} type;
} jdwpPacket;
/*
* JDWP functions called by the transport.
*/
typedef struct jdwpTransportCallback {
void *(*alloc)(jint numBytes); /* Call this for all allocations */
void (*free)(void *buffer); /* Call this for all deallocations */
} jdwpTransportCallback;
typedef jint (JNICALL *jdwpTransport_OnLoad_t)(JavaVM *jvm,
jdwpTransportCallback *callback,
jint version,
jdwpTransportEnv** env);
/* Function Interface */
struct jdwpTransportNativeInterface_ {
/* 1 : RESERVED */
void *reserved1;
/* 2 : Get Capabilities */
jdwpTransportError (JNICALL *GetCapabilities)(jdwpTransportEnv* env,
JDWPTransportCapabilities *capabilities_ptr);
/* 3 : Attach */
jdwpTransportError (JNICALL *Attach)(jdwpTransportEnv* env,
const char* address,
jlong attach_timeout,
jlong handshake_timeout);
/* 4: StartListening */
jdwpTransportError (JNICALL *StartListening)(jdwpTransportEnv* env,
const char* address,
char** actual_address);
/* 5: StopListening */
jdwpTransportError (JNICALL *StopListening)(jdwpTransportEnv* env);
/* 6: Accept */
jdwpTransportError (JNICALL *Accept)(jdwpTransportEnv* env,
jlong accept_timeout,
jlong handshake_timeout);
/* 7: IsOpen */
jboolean (JNICALL *IsOpen)(jdwpTransportEnv* env);
/* 8: Close */
jdwpTransportError (JNICALL *Close)(jdwpTransportEnv* env);
/* 9: ReadPacket */
jdwpTransportError (JNICALL *ReadPacket)(jdwpTransportEnv* env,
jdwpPacket *pkt);
/* 10: Write Packet */
jdwpTransportError (JNICALL *WritePacket)(jdwpTransportEnv* env,
const jdwpPacket* pkt);
/* 11: GetLastError */
jdwpTransportError (JNICALL *GetLastError)(jdwpTransportEnv* env,
char** error);
};
/*
* Use inlined functions so that C++ code can use syntax such as
* env->Attach("mymachine:5000", 10*1000, 0);
*
* rather than using C's :-
*
* (*env)->Attach(env, "mymachine:5000", 10*1000, 0);
*/
struct _jdwpTransportEnv {
const struct jdwpTransportNativeInterface_ *functions;
#ifdef __cplusplus
jdwpTransportError GetCapabilities(JDWPTransportCapabilities *capabilities_ptr) {
return functions->GetCapabilities(this, capabilities_ptr);
}
jdwpTransportError Attach(const char* address, jlong attach_timeout,
jlong handshake_timeout) {
return functions->Attach(this, address, attach_timeout, handshake_timeout);
}
jdwpTransportError StartListening(const char* address,
char** actual_address) {
return functions->StartListening(this, address, actual_address);
}
jdwpTransportError StopListening(void) {
return functions->StopListening(this);
}
jdwpTransportError Accept(jlong accept_timeout, jlong handshake_timeout) {
return functions->Accept(this, accept_timeout, handshake_timeout);
}
jboolean IsOpen(void) {
return functions->IsOpen(this);
}
jdwpTransportError Close(void) {
return functions->Close(this);
}
jdwpTransportError ReadPacket(jdwpPacket *pkt) {
return functions->ReadPacket(this, pkt);
}
jdwpTransportError WritePacket(const jdwpPacket* pkt) {
return functions->WritePacket(this, pkt);
}
jdwpTransportError GetLastError(char** error) {
return functions->GetLastError(this, error);
}
#endif /* __cplusplus */
};
#ifdef __cplusplus
} /* extern "C" */
#endif /* __cplusplus */
#endif /* JDWPTRANSPORT_H */

Some files were not shown because too many files have changed in this diff Show More