diff options
author | Christian Pointner <equinox@spreadspace.org> | 2010-11-17 19:33:45 +0000 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2010-11-17 19:33:45 +0000 |
commit | 5d457adf1964bdf227b434441a9b1ed3c159915b (patch) | |
tree | 02ee98ebf2b27b1ab13204d0b98820dc24a4fc6e | |
parent | fixed loaderpath at module_list (diff) |
added stdout module
git-svn-id: https://svn.spreadspace.org/gcsd/trunk@35 ac14a137-c7f1-4531-abe0-07747231d213
-rw-r--r-- | src/defines.lua | 4 | ||||
-rw-r--r-- | src/gcsd.c | 1 | ||||
-rw-r--r-- | src/main_loop.lua | 6 | ||||
-rw-r--r-- | src/modules/stdout.lua | 102 |
4 files changed, 108 insertions, 5 deletions
diff --git a/src/defines.lua b/src/defines.lua index 0bc3cce..1639934 100644 --- a/src/defines.lua +++ b/src/defines.lua @@ -38,8 +38,8 @@ defines.KILL_MODULE = 2 defines.KILL_MODULE_CLASS = 3 defines.KILL_DAEMON = 4 -defines.INPUT_MODULE = 1 -defines.OUTPUT_MODULE = 2 +defines.IN_MODULE = 1 +defines.OUT_MODULE = 2 defines.INOUT_MODULE = 3 defines.MISC_MODULE = 4 @@ -60,6 +60,7 @@ static const luaL_Reg gcsd_lualibs[] = { {LUA_TABLIBNAME, luaopen_table}, {LUA_STRLIBNAME, luaopen_string}, {LUA_MATHLIBNAME, luaopen_math}, + {LUA_IOLIBNAME, luaopen_io}, {LUA_LOGLIBNAME, luaopen_log}, {LUA_SIGNALLIBNAME, luaopen_signal}, {NULL, NULL} diff --git a/src/main_loop.lua b/src/main_loop.lua index 3007e6a..ec68b70 100644 --- a/src/main_loop.lua +++ b/src/main_loop.lua @@ -113,9 +113,9 @@ function main_loop(opt) end end if(command_queue:command_pending()) then - log.printf(log.DEBUG, "sending pending command: %s", command_queue:get_next_command()) - command_queue:command_sent() - command_queue:command_completed() + local command = command_queue:get_next_command() + log.printf(log.DEBUG, "sending pending command: %s", command) + module_list.output:start_command(command) end end end diff --git a/src/modules/stdout.lua b/src/modules/stdout.lua new file mode 100644 index 0000000..c88812d --- /dev/null +++ b/src/modules/stdout.lua @@ -0,0 +1,102 @@ +-- +-- gcsd +-- +-- gcsd the generic command sequencer daemon can be used to serialize +-- commands sent over various paralell communication channels to a +-- single command output. It can be seen as a multiplexer for any +-- kind of communication between a single resource and various clients +-- which want to submit commands to it or query information from it. +-- gcsd is written in C and Lua. The goal is to provide an easy to +-- understand high level API based on Lua which can be used to +-- implement the business logic of the so formed multiplexer daemon. +-- +-- +-- Copyright (C) 2009-2010 Markus Grueneis <gimpf@spreadspace.org> +-- Christian Pointner <equinox@spreadspace.org> +-- +-- This file is part of gcsd. +-- +-- gcsd is free software: you can redistribute it and/or modify +-- it under the terms of the GNU General Public License as published by +-- the Free Software Foundation, either version 3 of the License, or +-- any later version. +-- +-- gcsd is distributed in the hope that it will be useful, +-- but WITHOUT ANY WARRANTY; without even the implied warranty of +-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +-- GNU General Public License for more details. +-- +-- You should have received a copy of the GNU General Public License +-- along with gcsd. If not, see <http://www.gnu.org/licenses/>. +-- + +local defines = require("defines") + +-- stdout module class +local stdout = {} +stdout.properties = { type=defines.OUT_MODULE, name="stdout", max_instances=-1 } +stdout.next_id = 0 + +-- create new instance of stdout module class +function stdout:new(config) + local inst = {} + inst.class = self.properties.name + inst.config = config + if(config.name == nil or config.name == "") then + inst.name = self.properties.name .. self.next_id + self.next_id = self.next_id + 1 + else + inst.name = config.name + end + + local handle = {} + handle.fd = 1 + handle.client_instance = nil + handle.out_buffer = nil + function handle:getfd() return self.fd end + function handle:dirty() return 0 end + function handle:read() end + function handle:write() + io.stdout:write(self.out_buffer) + io.stdout:flush() + self.out_buffer = nil + command_queue:command_sent() + command_queue:command_completed() + end + + local client = {} + client.module_instance = inst + client.name = inst.name .. "#0" + function client:process_response() end + function client:process_timeout() end + function client:get_read_handles() return {} end + function client:get_write_handles() + if(handle.out_buffer ~= nil) then + return { handle } + else + return {} + end + end + function client:cleanup() end + handle.client_instance = client + + function inst:cleanup() + client_list:unregister_by_module(self) + end + function inst:get_read_handles() + return {} + end + function inst:get_write_handles() + return {} + end + function inst:start_command(command) + handle.out_buffer = command + end + setmetatable(inst, {}) + getmetatable(inst).__gc = function() inst:cleanup() end + + client_list:register(client) + return inst +end + +return stdout |