diff options
author | Christian Pointner <equinox@spreadspace.org> | 2010-11-06 19:39:49 +0000 |
---|---|---|
committer | Christian Pointner <equinox@spreadspace.org> | 2010-11-06 19:39:49 +0000 |
commit | 8403a859e3a65c16928f099bc1adebeb4cf9024d (patch) | |
tree | 1c000f2d9ae3bc9c23906328155b4b2e0ae2c483 | |
parent | fixed options print bug (diff) |
updated main_loop
added dummy module
added cleanlua target to Makefile
git-svn-id: https://svn.spreadspace.org/gcsd/trunk@9 ac14a137-c7f1-4531-abe0-07747231d213
-rw-r--r-- | src/Makefile | 16 | ||||
-rw-r--r-- | src/main_loop.lua | 31 | ||||
-rw-r--r-- | src/modules/dummy.lua | 64 |
3 files changed, 104 insertions, 7 deletions
diff --git a/src/Makefile b/src/Makefile index 2fb2b55..007bae8 100644 --- a/src/Makefile +++ b/src/Makefile @@ -48,13 +48,17 @@ C_OBJS := log.o \ C_SRCS := $(C_OBJS:%.o=%.c) +#MODULES := dummy +#MODULE_SRC := $(MODULES:%=modules/%.lua) + LUA_SRCS := main_loop.lua \ debug_shell.lua + LUA_BYTECODE := $(EXECUTABLE).lc LUA_BYTECODE_OBJ := $(EXECUTABLE)_lua_bytecode.o -.PHONY: clean cleanall distclean manpage install install-bin install-etc install-man uninstall remove purge +.PHONY: cleanlua clean cleanall distclean manpage install install-bin install-etc install-man uninstall remove purge all: $(EXECUTABLE) @@ -93,13 +97,15 @@ distclean: cleanall rm -f include.mk rm -f version.h -clean: - rm -f *.o - rm -f *.d - rm -f *.d.* +cleanlua: rm -f $(LUA_BYTECODE) rm -f $(LUA_BYTECODE_OBJ) rm -f $(LUA_BYTECODE_OBJ:%.o=%.c) + +clean: cleanlua + rm -f *.o + rm -f *.d + rm -f *.d.* rm -f $(EXECUTABLE) rm -f $(EXECUTABLE).exe diff --git a/src/main_loop.lua b/src/main_loop.lua index 2ff1eae..da48515 100644 --- a/src/main_loop.lua +++ b/src/main_loop.lua @@ -41,6 +41,16 @@ function main_loop(opt) log.printf(log.DEBUG, "gcsd input[%d] = %s", idx, input) end + local modules = {} + -- parse module config + local old_path = package.path + package.path = "./modules/?.lua" + dummy = require ("dummy") + package.path = old_path + + table.insert(modules, dummy.new("module config")) + + if(opt.debug) then local ret = debug_shell.init("localhost", 9000) if(ret == nil) then return -1 end @@ -48,7 +58,21 @@ function main_loop(opt) local return_value = 0 while return_value == 0 do - local readable, _, err = socket.select({ sig , unpack(debug_shell.socks) } , nil) + + local readables = { sig } + for _, module in ipairs(modules) do + for _, fd in ipairs(module.get_read_handles()) do + table.insert(readables, fd) + end + end + local writeables = { } + for _, module in ipairs(modules) do + for _, fd in ipairs(module.get_write_handles()) do + table.insert(writeables, fd) + end + end + + local readable, writeable, err = socket.select(readables , writeables) if(err) then log.printf(log.ERROR, "select returned with error: %s", err) return_value = -1 @@ -61,9 +85,12 @@ function main_loop(opt) return_value = debug_shell.handle(input) if(return_value == 2) then break end else - log.printf(log.ERROR, "select returned unknown file descriptor!?") + input.read() end end + for _, output in ipairs(writeable) do + output.write() + end end end diff --git a/src/modules/dummy.lua b/src/modules/dummy.lua new file mode 100644 index 0000000..0f05cbe --- /dev/null +++ b/src/modules/dummy.lua @@ -0,0 +1,64 @@ +-- +-- 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 dummy = { + properties = { input=true, output=true, max_instances=-1 }, + new = function(config) + local handle = {} + handle.fd = 0 + function handle:getfd() return self.fd end + function handle:dirty() return 0 end + function handle:read() end + function handle:write(data) end + + local client = {} + function client:process_response() end + function client:process_timeout() end + function client:read_command() end + function client:get_read_handles() return handle end + function client:get_write_handles() return {} end + + local inst = { + cleanup = function() end, + get_read_handles = function() + return {} + end, + get_write_handles = function() + return {} + end + } + metatable(inst).__gc = inst.cleanup() + return inst + end +} + +return dummy
\ No newline at end of file |