bunti/src/main/java/de/ctdo/bunti/control/BuntiControllerImpl.java

74 lines
1.8 KiB
Java

package de.ctdo.bunti.control;
import java.util.Map;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.stereotype.Component;
import net.sf.json.JSONObject;
import de.ctdo.bunti.DeviceChangedEvent;
import de.ctdo.bunti.dao.BuntiDevicesDAO;
import de.ctdo.bunti.model.*;
@Component
public class BuntiControllerImpl implements BuntiController, ApplicationEventPublisherAware {
private Logger logger = LoggerFactory.getLogger(getClass());
private ApplicationEventPublisher applicationEventPublisher = null;
private BuntiDevicesDAO devicesDAO;
@Autowired
public void setDevicesDAO(BuntiDevicesDAO devicesDAO) {
this.devicesDAO = devicesDAO;
}
public void performJSONString(String json) {
JSONObject jsonobj = JSONObject.fromObject(json);
if (jsonobj.containsKey("command")) {
String command = jsonobj.get("command").toString();
if (command.equals("setdmxchannels")) {
} else if (command.equals("switchdevice")) {
}
}
}
@Override
public boolean setDevice(int deviceId, Map<String, Object> options) {
BuntiDevice device = devicesDAO.getDeviceById(deviceId);
if (device != null) {
this.applicationEventPublisher.publishEvent(new DeviceChangedEvent(this, device, options));
logger.debug("publishEvent in BuntiController");
return true;
}
return false;
}
@Override
public void setApplicationEventPublisher(ApplicationEventPublisher publisher) {
this.applicationEventPublisher = publisher;
}
// public void sendBroadcastMessage(String message) {
// for (BroadcastListener l : listeners) {
// l.Broadcast(message);
// }
// }
}