def isStateChange = eventDataMap["isStateChange"]
def unit = eventDataMap["unit"]
def data = eventDataMap["data"]
-
- for (int i = 0;i < eventList.size();i++) {
- if (eventList[i] == name) {
+ def minSize
+ def smallest
+
+ //make search efficient
+ if (app1.eventList.size() == app2.eventList.size()) {
+ minSize = app1.eventList.size()
+ smallest = "equal"
+ } else if (app1.eventList.size() < app2.eventList.size()) {
+ minSize = app1.eventList.size()
+ smallest = "app1"
+ } else {
+ minSize = app2.eventList.size()
+ smallest = "app2"
+ }
+
+ for (int i = 0;i < minSize;i++) {
+ if (app1.eventList[i] == name) {
evt.add(new Event())
evt[-1].value = value
evt[-1].name = name
evt[-1].isStateChange = isStateChange
evt[-1].unit = unit
evt[-1].data = data
- functionList[i](evt[-1])
+ app1.functionList[i](evt[-1])
+ }
+ if (app2.eventList[i] == name) {
+ evt.add(new Event())
+ evt[-1].value = value
+ evt[-1].name = name
+ evt[-1].deviceId = deviceId
+ evt[-1].descriptionText = descriptionText
+ evt[-1].displayed = displayed
+ evt[-1].linkText = linkText
+ evt[-1].displayName = linkText
+ evt[-1].isStateChange = isStateChange
+ evt[-1].unit = unit
+ evt[-1].data = data
+ app2.functionList[i](evt[-1])
}
}
+
+ if (smallest == "app1") {
+ for (int i = minSize;i < app2.eventList.size();i++) {
+ if (app2.eventList[i] == name) {
+ evt.add(new Event())
+ evt[-1].value = value
+ evt[-1].name = name
+ evt[-1].deviceId = deviceId
+ evt[-1].descriptionText = descriptionText
+ evt[-1].displayed = displayed
+ evt[-1].linkText = linkText
+ evt[-1].displayName = linkText
+ evt[-1].isStateChange = isStateChange
+ evt[-1].unit = unit
+ evt[-1].data = data
+ app2.functionList[i](evt[-1])
+ }
+ }
+ } else if (smallest == "app2") {
+ for (int i = minSize;i < app1.eventList.size();i++) {
+ if (app1.eventList[i] == name) {
+ evt.add(new Event())
+ evt[-1].value = value
+ evt[-1].name = name
+ evt[-1].deviceId = deviceId
+ evt[-1].descriptionText = descriptionText
+ evt[-1].displayed = displayed
+ evt[-1].linkText = linkText
+ evt[-1].displayName = linkText
+ evt[-1].isStateChange = isStateChange
+ evt[-1].unit = unit
+ evt[-1].data = data
+ app1.functionList[i](evt[-1])
+ }
+ }
+ }
}
import appTouch.Touched
import Event.Event
+//Global eventHandler
+/////////////////////////////////////////////////////////////////////
+def eventHandler(LinkedHashMap eventDataMap) {
+ def value = eventDataMap["value"]
+ def name = eventDataMap["name"]
+ def deviceId = eventDataMap["deviceId"]
+ def descriptionText = eventDataMap["descriptionText"]
+ def displayed = eventDataMap["displayed"]
+ def linkText = eventDataMap["linkText"]
+ def isStateChange = eventDataMap["isStateChange"]
+ def unit = eventDataMap["unit"]
+ def data = eventDataMap["data"]
+ def minSize
+ def smallest
+
+ //make search efficient
+ if (app1.eventList.size() == app2.eventList.size()) {
+ minSize = app1.eventList.size()
+ smallest = "equal"
+ } else if (app1.eventList.size() < app2.eventList.size()) {
+ minSize = app1.eventList.size()
+ smallest = "app1"
+ } else {
+ minSize = app2.eventList.size()
+ smallest = "app2"
+ }
+
+ for (int i = 0;i < minSize;i++) {
+ if (app1.eventList[i] == name) {
+ evt.add(new Event())
+ evt[-1].value = value
+ evt[-1].name = name
+ evt[-1].deviceId = deviceId
+ evt[-1].descriptionText = descriptionText
+ evt[-1].displayed = displayed
+ evt[-1].linkText = linkText
+ evt[-1].displayName = linkText
+ evt[-1].isStateChange = isStateChange
+ evt[-1].unit = unit
+ evt[-1].data = data
+ app1.functionList[i](evt[-1])
+ }
+ if (app2.eventList[i] == name) {
+ evt.add(new Event())
+ evt[-1].value = value
+ evt[-1].name = name
+ evt[-1].deviceId = deviceId
+ evt[-1].descriptionText = descriptionText
+ evt[-1].displayed = displayed
+ evt[-1].linkText = linkText
+ evt[-1].displayName = linkText
+ evt[-1].isStateChange = isStateChange
+ evt[-1].unit = unit
+ evt[-1].data = data
+ app2.functionList[i](evt[-1])
+ }
+ }
+
+ if (smallest == "app1") {
+ for (int i = minSize;i < app2.eventList.size();i++) {
+ if (app2.eventList[i] == name) {
+ evt.add(new Event())
+ evt[-1].value = value
+ evt[-1].name = name
+ evt[-1].deviceId = deviceId
+ evt[-1].descriptionText = descriptionText
+ evt[-1].displayed = displayed
+ evt[-1].linkText = linkText
+ evt[-1].displayName = linkText
+ evt[-1].isStateChange = isStateChange
+ evt[-1].unit = unit
+ evt[-1].data = data
+ app2.functionList[i](evt[-1])
+ }
+ }
+ } else if (smallest == "app2") {
+ for (int i = minSize;i < app1.eventList.size();i++) {
+ if (app1.eventList[i] == name) {
+ evt.add(new Event())
+ evt[-1].value = value
+ evt[-1].name = name
+ evt[-1].deviceId = deviceId
+ evt[-1].descriptionText = descriptionText
+ evt[-1].displayed = displayed
+ evt[-1].linkText = linkText
+ evt[-1].displayName = linkText
+ evt[-1].isStateChange = isStateChange
+ evt[-1].unit = unit
+ evt[-1].data = data
+ app1.functionList[i](evt[-1])
+ }
+ }
+ }
+}
+
//GlobalVariables for both Apps
//Create a global variable for send event
@Field def sendEvent = {eventDataMap ->
- app1.eventHandler(eventDataMap)
- app2.eventHandler(eventDataMap)
+ eventHandler(eventDataMap)
}
//Object for location
@Field def locationObject = new LocationVar()
//Object for touch
@Field def appObject = new Touched(sendEvent, 0)
+//Create a global list for events
+@Field def evt = []
//Extracted global objects for both Apps
//Global Object for class lock!
//Global Object for class contactSensor!
@Field def contactObject = new Contacting(sendEvent, 1)
//Global Object for class Switch!
-@Field def switchObject = new Switching(sendEvent, 2)
+@Field def switchObject = new Switching(sendEvent, 1)
//Application #1
class App1 {
//Global variable for number!
def minutesLater = 1
//Global variable for number!
- def secondsLater = 2
+ def secondsLater = 1
//Global variable for recipients!
def recipients = ['AJ']
//Global variable for phone number!
def timersFuncList = []
//Create a global list for timer schedulers
def timersList = []
- //Create a global list for events
- def evt = []
//Methods
/////////////////////////////////////////////////////////////////////
def sendSms(long phoneNumber, String text) {
println("Sending \""+text+"\" to "+phoneNumber.toString())
}
- /////////////////////////////////////////////////////////////////////
- def eventHandler(LinkedHashMap eventDataMap) {
- def value = eventDataMap["value"]
- def name = eventDataMap["name"]
- def deviceId = eventDataMap["deviceId"]
- def descriptionText = eventDataMap["descriptionText"]
- def displayed = eventDataMap["displayed"]
- def linkText = eventDataMap["linkText"]
- def isStateChange = eventDataMap["isStateChange"]
- def unit = eventDataMap["unit"]
- def data = eventDataMap["data"]
-
- for (int i = 0;i < eventList.size();i++) {
- if (eventList[i] == name) {
- evt.add(new Event())
- evt[-1].value = value
- evt[-1].name = name
- evt[-1].deviceId = deviceId
- evt[-1].descriptionText = descriptionText
- evt[-1].displayed = displayed
- evt[-1].linkText = linkText
- evt[-1].displayName = linkText
- evt[-1].isStateChange = isStateChange
- evt[-1].unit = unit
- evt[-1].data = data
- functionList[i](evt[-1])
- }
- }
- }
def installed(){
initialize()
//Global variable for mode!
def newMode = "away"
//Global variable for number!
- def waitfor = 10
+ def waitfor = 1
//Global Object for functions in subscribe method!
def installed = this.&installed
//Global Object for functions in subscribe method!
def timersFuncList = []
//Create a global list for timer schedulers
def timersList = []
- //Create a global list for events
- def evt = []
//Methods
/////////////////////////////////////////////////////////////////////
def sendSms(long phoneNumber, String text) {
println("Sending \""+text+"\" to "+phoneNumber.toString())
}
- /////////////////////////////////////////////////////////////////////
- def eventHandler(LinkedHashMap eventDataMap) {
- def value = eventDataMap["value"]
- def name = eventDataMap["name"]
- def deviceId = eventDataMap["deviceId"]
- def descriptionText = eventDataMap["descriptionText"]
- def displayed = eventDataMap["displayed"]
- def linkText = eventDataMap["linkText"]
- def isStateChange = eventDataMap["isStateChange"]
- def unit = eventDataMap["unit"]
- def data = eventDataMap["data"]
-
- for (int i = 0;i < eventList.size();i++) {
- if (eventList[i] == name) {
- evt.add(new Event())
- evt[-1].value = value
- evt[-1].name = name
- evt[-1].deviceId = deviceId
- evt[-1].descriptionText = descriptionText
- evt[-1].displayed = displayed
- evt[-1].linkText = linkText
- evt[-1].displayName = linkText
- evt[-1].isStateChange = isStateChange
- evt[-1].unit = unit
- evt[-1].data = data
- functionList[i](evt[-1])
- }
- }
- }
def installed()
{
@Field def app2 = new App2(this)
app1.installed()
app2.installed()
+appObject.setValue([name: "Touched", value: "Touched", deviceId: 0, descriptionText: "",
+ displayed: true, linkText: "", isStateChange: false, unit: "", data: []])
+