1 /**
2  * Created on Mar 12, 2009
3  *
4  * Copyright (C) Azureus Software, Inc, All Rights Reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA
19  */
20 
21 package com.aelitis.azureus.core.messenger.config;
22 
23 import java.util.*;
24 
25 import org.gudy.azureus2.core3.config.COConfigurationManager;
26 import org.gudy.azureus2.core3.util.*;
27 import org.gudy.azureus2.plugins.PluginInterface;
28 import org.gudy.azureus2.plugins.PluginManager;
29 
30 import com.aelitis.azureus.core.AzureusCoreFactory;
31 import com.aelitis.azureus.core.devices.*;
32 import com.aelitis.azureus.core.messenger.PlatformMessage;
33 import com.aelitis.azureus.core.messenger.PlatformMessenger;
34 
35 /**
36  * @author TuxPaper
37  * @created Mar 12, 2009
38  *
39  */
40 public class PlatformDevicesMessenger
41 {
42 	public static final String CFG_SEND_QOS = "devices.sendQOS";
43 
44 	public static final String LISTENER_ID = "devices";
45 
46 	private static final String OP_QOS_TURN_ON = "qos-turn-on";
47 
48 	private static final String OP_QOS_FOUND_DEVICE = "qos-found-device";
49 
50 	private static final String OP_REPORT_DEVICES = "report-devices";
51 
qosTurnOn(boolean withITunes, boolean bugFix)52 	public static void qosTurnOn(boolean withITunes, boolean bugFix) {
53 		if (!COConfigurationManager.getBooleanParameter(CFG_SEND_QOS, false)) {
54 			return;
55 		}
56 
57 		PlatformMessage message = new PlatformMessage("AZMSG", LISTENER_ID,
58 				OP_QOS_TURN_ON, new Object[] {
59 					"itunes",
60 					Boolean.valueOf(withITunes),
61 					"os-name",
62 					Constants.OSName + (bugFix ? ":BF" : "")
63 				}, 5000);
64 		message.setSendAZID(false);
65 		PlatformMessenger.queueMessage(message, null);
66 	}
67 
qosFoundDevice(final Device device)68 	public static void qosFoundDevice(final Device device) {
69 		if (device == null
70 				|| !COConfigurationManager.getBooleanParameter(CFG_SEND_QOS, false)) {
71 			return;
72 		}
73 
74 		if ("ms_wmp.generic".equals(device.getClassification())) {
75 			return;
76 		}
77 
78 		SimpleTimer.addEvent("qosFoundDevice", SystemTime.getOffsetTime(1000), new TimerEventPerformer() {
79 			public void perform(TimerEvent event) {
80 				_qosFoundDevice(device);
81 			}
82 		});
83 	}
84 
_qosFoundDevice(Device device)85 	private static void _qosFoundDevice(Device device) {
86 		if (device == null
87 				|| !COConfigurationManager.getBooleanParameter(CFG_SEND_QOS, false)) {
88 			return;
89 		}
90 
91 		HashMap<String, Object> map = new HashMap<String, Object>();
92 
93 		addPluginVersionsToMap(map);
94 
95 		map.put("device-name", getDeviceName(device));
96 		map.put("device-type", new Integer(device.getType()));
97 		if (device instanceof DeviceMediaRenderer) {
98 			DeviceMediaRenderer renderer = (DeviceMediaRenderer) device;
99 			map.put("renderer-species",
100 					Integer.valueOf(renderer.getRendererSpecies()));
101 		}
102 
103 		PlatformMessage message = new PlatformMessage("AZMSG", LISTENER_ID,
104 				OP_QOS_FOUND_DEVICE, map, 5000);
105 		message.setSendAZID(false);
106 		PlatformMessenger.queueMessage(message, null);
107 	}
108 
addPluginVersionsToMap(Map map)109 	private static void addPluginVersionsToMap(Map map) {
110 		if (AzureusCoreFactory.isCoreRunning()) {
111   		PluginManager pm = AzureusCoreFactory.getSingleton().getPluginManager();
112   		PluginInterface pi;
113   		pi = pm.getPluginInterfaceByID("vuzexcode");
114   		if (pi != null) {
115   			map.put("xcode-plugin-version", pi.getPluginVersion());
116   		}
117   		pi = pm.getPluginInterfaceByID("azitunes");
118   		if (pi != null) {
119   			map.put("itunes-plugin-version", pi.getPluginVersion());
120   		}
121 		}
122 		map.put("os-name", Constants.OSName);
123 	}
124 
getDeviceName(Device device)125 	private static String getDeviceName(Device device) {
126 		return device.getClassification();
127 		/*
128 		String name = device.getName();
129 		String classification = device.getClassification();
130 		StringBuffer deviceName = new StringBuffer();
131 		if (device.isGenericUSB()) {
132 			deviceName.append("{g}");
133 		}
134 		if (device.isHidden()) {
135 			deviceName.append("{h}");
136 		}
137 		deviceName.append(name);
138 		if (!name.equals(classification)) {
139 			deviceName.append('/');
140 			deviceName.append(classification);
141 		}
142 		return deviceName.toString();
143 		*/
144 	}
145 }
146