Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
mch
committed
Apr 5, 2012
1 parent
3567a5f
commit bee8a99
Showing
7 changed files
with
47 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
package ubi.core | ||
|
||
trait IPlugin { | ||
def register(service : LocationService); | ||
def register(); | ||
def initialize(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,18 @@ | ||
package ubi.core | ||
|
||
import scala.actors.Actor; | ||
import scala.actors.Actor._; | ||
import scala.collection.mutable.HashMap; | ||
import ubi.log.Log; | ||
import ubi.log.LogLevel._; | ||
|
||
class LocationService { | ||
val plugins = new HashMap[String,Actor](); | ||
val plugins = new HashMap[String,PluginBase](); | ||
|
||
def register(name : String, plugin : Actor) { | ||
Log.log(INFO, "Registering plugin '" + name + "'"); | ||
def register(name : String, plugin : PluginBase) { | ||
Log.log(INFO, "Registering plugin: " + name); | ||
plugins.put(name, plugin); | ||
} | ||
|
||
def findActor(name : String) : Option[PluginBase] = { | ||
plugins.get(name); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,15 @@ | ||
package ubi.core | ||
|
||
import scala.actors.Actor; | ||
import scala.actors.Actor._; | ||
import ubi.core.subscribers.SubscriberHandler; | ||
|
||
class PluginBase(name : String) | ||
extends SubscriberHandler with Actor with IPlugin { | ||
def register(service : LocationService) { | ||
service.register(name, this); | ||
def register() { | ||
Globals.locationService.register(name, this); | ||
} | ||
|
||
def initialize() {} | ||
|
||
def act() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,24 @@ | ||
package ubi.core | ||
|
||
import scala.actors.Actor; | ||
import scala.actors.Actor._; | ||
import micclient.messages.DataPacket | ||
import ubi.log.{LogLevel, Log} | ||
import ubi.log.LogLevel._; | ||
; | ||
|
||
class VoiceCommandModule extends PluginBase("VoiceCommandModule") { | ||
override def initialize() { | ||
val actor = Globals.locationService.findActor("MicClient"); | ||
if (actor.isDefined) { | ||
actor.get.subscribers.add(this); | ||
} | ||
} | ||
|
||
override def act() { | ||
|
||
while (true) { | ||
receive { | ||
case msg : DataPacket => | ||
Log.log(INFO, "Received data: " + msg.words); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,24 @@ | ||
package ubi.core | ||
|
||
import scala.actors.Actor; | ||
import scala.actors.Actor._; | ||
import scala.collection.immutable.List; | ||
import ubi.core.subscribers.SubscriberHandler; | ||
import ubi.core.micclient.messages.DataPacket; | ||
import java.awt.event.ActionListener; | ||
import java.awt.event.ActionEvent; | ||
|
||
class MicClient extends PluginBase("MicClient") { | ||
def notifySubscribers() { | ||
def notifySubscribers(list : List[String]) { | ||
if (subscribers.isEmpty) return; | ||
var packet = new DataPacket(); | ||
packet.source = this; | ||
packet.words = List("McHalls", "was", "here"); | ||
packet.words = list; | ||
for (subscriber <- subscribers) { | ||
packet.target = subscriber; | ||
subscriber ! packet; | ||
} | ||
} | ||
|
||
override def act() { | ||
while (true) { | ||
Thread.sleep(1000); | ||
notifySubscribers(List("McHalls", "was", "here")); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters