153 def reply_error(arg: Any) { reply(Server.Reply.ERROR, arg) } |
153 def reply_error(arg: Any) { reply(Server.Reply.ERROR, arg) } |
154 def reply_error_message(message: String, more: (String, JSON.T)*): Unit = |
154 def reply_error_message(message: String, more: (String, JSON.T)*): Unit = |
155 reply_error(Map("message" -> message) ++ more) |
155 reply_error(Map("message" -> message) ++ more) |
156 |
156 |
157 def notify(arg: Any) { reply(Server.Reply.NOTE, arg) } |
157 def notify(arg: Any) { reply(Server.Reply.NOTE, arg) } |
158 def notify_message(kind: String, msg: String, more: (String, JSON.T)*): Unit = |
158 } |
|
159 |
|
160 |
|
161 /* context with output channels */ |
|
162 |
|
163 class Context private[Server](server: Server, connection: Connection) |
|
164 { |
|
165 context => |
|
166 |
|
167 def shutdown() { server.close() } |
|
168 |
|
169 def notify(arg: Any) { connection.notify(arg) } |
|
170 def message(kind: String, msg: String, more: (String, JSON.T)*): Unit = |
159 notify(Map(Markup.KIND -> kind, "message" -> msg) ++ more) |
171 notify(Map(Markup.KIND -> kind, "message" -> msg) ++ more) |
160 } |
|
161 |
|
162 |
|
163 /* context with output channels */ |
|
164 |
|
165 class Context private[Server](server: Server, connection: Connection) |
|
166 { |
|
167 context => |
|
168 |
|
169 def shutdown() { server.close() } |
|
170 |
|
171 def message(kind: String, msg: String, more: (String, JSON.T)*): Unit = |
|
172 connection.notify_message(kind, msg, more:_*) |
|
173 def writeln(msg: String, more: (String, JSON.T)*): Unit = message(Markup.WRITELN, msg, more:_*) |
172 def writeln(msg: String, more: (String, JSON.T)*): Unit = message(Markup.WRITELN, msg, more:_*) |
174 def warning(msg: String, more: (String, JSON.T)*): Unit = message(Markup.WARNING, msg, more:_*) |
173 def warning(msg: String, more: (String, JSON.T)*): Unit = message(Markup.WARNING, msg, more:_*) |
175 def error_message(msg: String, more: (String, JSON.T)*): Unit = |
174 def error_message(msg: String, more: (String, JSON.T)*): Unit = |
176 message(Markup.ERROR_MESSAGE, msg, more:_*) |
175 message(Markup.ERROR_MESSAGE, msg, more:_*) |
177 |
176 |
396 connection.reply_ok(()) |
395 connection.reply_ok(()) |
397 var finished = false |
396 var finished = false |
398 while (!finished) { |
397 while (!finished) { |
399 connection.read_message() match { |
398 connection.read_message() match { |
400 case None => finished = true |
399 case None => finished = true |
401 case Some("") => context.writeln("Command 'help' provides list of commands") |
400 case Some("") => context.notify("Command 'help' provides list of commands") |
402 case Some(msg) => |
401 case Some(msg) => |
403 val (name, argument) = Server.Argument.split(msg) |
402 val (name, argument) = Server.Argument.split(msg) |
404 name match { |
403 name match { |
405 case Server.Command(cmd) => |
404 case Server.Command(cmd) => |
406 argument match { |
405 argument match { |