mirror of
https://github.com/samba-team/samba.git
synced 2024-12-24 21:34:56 +03:00
r20364: SWAT updates, part 1
These next few check-ins will add a working Statistics module to SWAT, and add an API Documentation module as well. Next step will be to modify the LDB browser to work with this new module and fsm structure. Derrell
This commit is contained in:
parent
1adb0fb291
commit
29db71587f
@ -19,4 +19,10 @@ function _nbt_packet_stats(params, error) {
|
||||
}
|
||||
jsonrpc.method.NBTPacketStats = _nbt_packet_stats;
|
||||
|
||||
|
||||
/*
|
||||
* Local Variables:
|
||||
* mode: c
|
||||
* End:
|
||||
*/
|
||||
%>
|
||||
|
184
services/samba/management.esp
Normal file
184
services/samba/management.esp
Normal file
@ -0,0 +1,184 @@
|
||||
<%
|
||||
/*
|
||||
* Copyright:
|
||||
* (C) 2006 by Derrell Lipman
|
||||
* All rights reserved
|
||||
*
|
||||
* License:
|
||||
* LGPL 2.1: http://creativecommons.org/licenses/LGPL/2.1/
|
||||
*/
|
||||
|
||||
/*
|
||||
* JSON-RPC mappings to management functions
|
||||
*/
|
||||
|
||||
libinclude("base.js");
|
||||
libinclude("management.js");
|
||||
|
||||
/**
|
||||
* Get statistics from each of the servers
|
||||
*
|
||||
* @param params[0]
|
||||
* Optional enum_smb_sessions flag, default false
|
||||
*
|
||||
* @param params[1]
|
||||
* Optional enum_smb_tcons flag, default false
|
||||
*
|
||||
* @param error
|
||||
* An object of class JsonRpcError.
|
||||
*
|
||||
* @return
|
||||
* Success: Object containing all of the statistics
|
||||
* Failure: error event
|
||||
*/
|
||||
function _get_statistics(params, error)
|
||||
{
|
||||
var enum_smb_sessions = false;
|
||||
var enum_smb_tcons = false;
|
||||
|
||||
if (params.length >= 1)
|
||||
{
|
||||
enum_smb_sessions = params[0];
|
||||
}
|
||||
if (params.length >= 2)
|
||||
{
|
||||
enum_smb_tcons = params[1];
|
||||
}
|
||||
|
||||
var info = new Object();
|
||||
|
||||
info["nbt"] = new Object();
|
||||
info["wins"] = new Object();
|
||||
info["cldap"] = new Object();
|
||||
info["kdc"] = new Object();
|
||||
info["smb"] = new Object();
|
||||
info["ldap"] = new Object();
|
||||
info["rpc"] = new Object();
|
||||
|
||||
for (var service in info)
|
||||
{
|
||||
var irpc = irpc_init();
|
||||
var status;
|
||||
var obj = info[service];
|
||||
obj.status = null;
|
||||
|
||||
if (!service_enabled(service))
|
||||
{
|
||||
obj.status = "DISABLED";
|
||||
}
|
||||
else
|
||||
{
|
||||
status = irpc.connect(service + "_server");
|
||||
if (status.is_ok != true)
|
||||
{
|
||||
obj.status = "INACTIVE";
|
||||
}
|
||||
else
|
||||
{
|
||||
var io = irpcObj();
|
||||
status = irpc.irpc_uptime(io);
|
||||
if (status.is_ok != true)
|
||||
{
|
||||
obj.status = "NOT RESPONDING";
|
||||
}
|
||||
else
|
||||
{
|
||||
obj.status = "RUNNING";
|
||||
|
||||
if (service == "smb" ||
|
||||
service == "ldap" ||
|
||||
service == "rpc")
|
||||
{
|
||||
obj.connections = io.results.length;
|
||||
}
|
||||
|
||||
if (service == "smb")
|
||||
{
|
||||
if (enum_smb_sessions)
|
||||
{
|
||||
var io = irpcObj();
|
||||
io.input.level = irpc.SMBSRV_INFO_SESSIONS;
|
||||
status = irpc.smbsrv_information(io);
|
||||
obj.sessions = new Array(0);
|
||||
if (status.is_ok == true)
|
||||
{
|
||||
/* gather the results into a single array */
|
||||
var count = 0;
|
||||
for (var i = 0; i < io.results.length; i++)
|
||||
{
|
||||
var sessions =
|
||||
io.results[i].info.sessions.sessions;
|
||||
for (var j = 0; j < sessions.length; j++)
|
||||
{
|
||||
obj.sessions[count] = sessions[j];
|
||||
|
||||
// convert NT times to unix epoch
|
||||
obj.sessions[count].auth_time =
|
||||
nttime2unix(obj.sessions[count].auth_time);
|
||||
obj.sessions[count].last_use_time =
|
||||
nttime2unix(obj.sessions[count].last_use_time);
|
||||
obj.sessions[count].connect_time =
|
||||
nttime2unix(obj.sessions[count].connect_time);
|
||||
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (enum_smb_tcons)
|
||||
{
|
||||
var io = irpcObj();
|
||||
io.input.level = irpc.SMBSRV_INFO_TCONS;
|
||||
status = irpc.smbsrv_information(io);
|
||||
obj.tcons = new Array(0);
|
||||
|
||||
if (status.is_ok == true)
|
||||
{
|
||||
/* gather the results into a single array */
|
||||
var count=0;
|
||||
for (var i = 0; i < io.results.length; i++)
|
||||
{
|
||||
var tcons = io.results[i].info.tcons.tcons;
|
||||
for (var j = 0; j < tcons.length; j++)
|
||||
{
|
||||
obj.tcons[count] = tcons[j];
|
||||
|
||||
|
||||
// convert NT times to unix epoch
|
||||
obj.tcons[count].last_use_time =
|
||||
nttime2unix(obj.tcons[count].last_use_time);
|
||||
obj.tcons[count].connect_time =
|
||||
nttime2unix(obj.tcons[count].connect_time);
|
||||
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (service == "nbt")
|
||||
{
|
||||
var io = irpcObj();
|
||||
io.input.level = irpc.NBTD_INFO_STATISTICS;
|
||||
status = irpc.nbtd_information(io);
|
||||
if (status.is_ok == true)
|
||||
{
|
||||
obj.statistics = io.results[0].info.stats;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return info;
|
||||
}
|
||||
jsonrpc.method.get_statistics = _get_statistics;
|
||||
|
||||
/*
|
||||
* Local Variables:
|
||||
* mode: c
|
||||
* End:
|
||||
*/
|
||||
%>
|
@ -165,6 +165,23 @@ static int ejs_sys_gmtime(MprVarHandle eid, int argc, struct MprVar **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
return the given NT time as a time_t value
|
||||
*/
|
||||
static int ejs_sys_nttime2unix(MprVarHandle eid, int argc, struct MprVar **argv)
|
||||
{
|
||||
time_t t;
|
||||
struct MprVar v;
|
||||
if (argc != 1 || !mprVarIsNumber(argv[0]->type)) {
|
||||
ejsSetErrorMsg(eid, "sys_ntgmtime invalid arguments");
|
||||
return -1;
|
||||
}
|
||||
t = nt_time_to_unix(mprVarToNumber(argv[0]));
|
||||
v = mprCreateNumberVar(t);
|
||||
mpr_Return(eid, v);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
return the given NT time as a gmtime structure
|
||||
*/
|
||||
@ -417,6 +434,7 @@ static int ejs_sys_init(MprVarHandle eid, int argc, struct MprVar **argv)
|
||||
mprSetCFunction(obj, "unix2nttime", ejs_sys_unix2nttime);
|
||||
mprSetCFunction(obj, "gmmktime", ejs_sys_gmmktime);
|
||||
mprSetCFunction(obj, "gmtime", ejs_sys_gmtime);
|
||||
mprSetCFunction(obj, "nttime2unix", ejs_sys_nttime2unix);
|
||||
mprSetCFunction(obj, "ntgmtime", ejs_sys_ntgmtime);
|
||||
mprSetCFunction(obj, "ldaptime", ejs_sys_ldaptime);
|
||||
mprSetCFunction(obj, "httptime", ejs_sys_httptime);
|
||||
|
File diff suppressed because one or more lines are too long
@ -4,12 +4,13 @@
|
||||
|
||||
QOOXDOO = ../qooxdoo-0.6.3-sdk
|
||||
SCRIPTNAME = swat.js
|
||||
APPCLASS = swat.Application
|
||||
INCLUDEALL = true
|
||||
APPCLASS = swat.main.Main
|
||||
INCLUDEALL = false
|
||||
OPTIMIZESTRINGS = false
|
||||
OPTIMIZEVARIABLES = false
|
||||
SOURCELOADER=
|
||||
NICE=10
|
||||
LOCALINSTALLDIR = /usr/local/samba/share/swat/apps/swat
|
||||
|
||||
|
||||
###################################################################################
|
||||
@ -60,8 +61,15 @@ all: build
|
||||
# COMMON TARGETS
|
||||
###################################################################################
|
||||
|
||||
source: info-source generate-script-source
|
||||
build: info-build generate-script-build copy-build-files fix-build-rights
|
||||
source: info-source \
|
||||
generate-script-source \
|
||||
generate-api-data
|
||||
|
||||
build: info-build \
|
||||
generate-script-build \
|
||||
generate-api-data \
|
||||
copy-build-files \
|
||||
fix-build-rights
|
||||
|
||||
api: generate-api-build generate-api-data
|
||||
@echo
|
||||
@ -111,6 +119,8 @@ generate-script-source:
|
||||
@chmod u+x $(GENERATOR) && nice -n $(NICE) $(GENERATOR) \
|
||||
--script-input $(FRAMEWORK)/source/class \
|
||||
--source-script-path ../$(FRAMEWORK)/source/class \
|
||||
--script-input $(API)/source/class \
|
||||
--source-script-path ../$(API)/source/class \
|
||||
--script-input source/class \
|
||||
--source-script-path class \
|
||||
--generate-source-script $(SOURCELDR) \
|
||||
@ -120,18 +130,29 @@ generate-script-source:
|
||||
--cache-directory $(CACHE) \
|
||||
--add-new-lines
|
||||
|
||||
#
|
||||
# djl: --script-input begins a set for which --resource-input and
|
||||
# --resource-output apply. Since there is a --resource-input and a
|
||||
# --resource-output defined for one set, it must be defined for each set
|
||||
#
|
||||
generate-script-build:
|
||||
@chmod u+x $(GENERATOR) && nice -n $(NICE) $(GENERATOR) \
|
||||
--script-input $(FRAMEWORK)/source/class \
|
||||
--resource-input $(FRAMEWORK)/source/resource \
|
||||
--resource-output build/resource \
|
||||
--script-input $(API)/source/class \
|
||||
--resource-input $(API)/source/resource \
|
||||
--resource-output build/resource \
|
||||
--script-input source/class \
|
||||
--resource-input source/resource \
|
||||
--resource-output build/resource \
|
||||
--generate-compiled-script \
|
||||
$(INCLUDE) $(OPTIMIZESTR) $(OPTIMIZEVAR) \
|
||||
--compiled-script-file build/script/$(SCRIPTNAME) \
|
||||
--copy-resources \
|
||||
--resource-input $(FRAMEWORK)/source/resource \
|
||||
--resource-output build/resource \
|
||||
--define-runtime-setting qx.manager.object.AliasManager.resourceUri:./resource \
|
||||
--cache-directory $(CACHE)
|
||||
--cache-directory $(CACHE) \
|
||||
--add-new-lines
|
||||
|
||||
generate-api-build:
|
||||
@chmod u+x $(GENERATOR) && nice -n $(NICE) $(GENERATOR) \
|
||||
@ -146,16 +167,17 @@ generate-api-build:
|
||||
--generate-compiled-script \
|
||||
--compiled-script-file api/script/api.js \
|
||||
--define-runtime-setting qx.manager.object.AliasManager.resourceUri:resource/qooxdoo \
|
||||
--define-runtime-setting api.Viewer.title:Sample \
|
||||
--define-runtime-setting api.Viewer.title:Swat \
|
||||
--copy-resources \
|
||||
--cache-directory $(CACHE)
|
||||
|
||||
generate-api-data:
|
||||
@chmod u+x $(GENERATOR) && nice -n $(NICE) $(GENERATOR) \
|
||||
--script-input $(FRAMEWORK)/source/class \
|
||||
--script-input $(API)/source/class \
|
||||
--script-input source/class \
|
||||
--generate-api-documentation \
|
||||
--api-documentation-json-file api/script/data.js \
|
||||
--api-documentation-json-file build/script/data.js \
|
||||
--cache-directory $(CACHE)
|
||||
|
||||
generate-pretty:
|
||||
@ -205,10 +227,21 @@ fix-build-rights:
|
||||
|
||||
info-build:
|
||||
@echo "****************************************************************************"
|
||||
@echo " GENERATING SAMPLE 1 BUILD"
|
||||
@echo " GENERATING SWAT BUILD"
|
||||
@echo "****************************************************************************"
|
||||
|
||||
info-source:
|
||||
@echo "****************************************************************************"
|
||||
@echo " GENERATING SAMPLE 1 SOURCE"
|
||||
@echo " GENERATING SWAT SOURCE"
|
||||
@echo "****************************************************************************"
|
||||
|
||||
###################################################################################
|
||||
# INSTALL TARGETS
|
||||
###################################################################################
|
||||
|
||||
install:
|
||||
@echo "****************************************************************************"
|
||||
@echo " INSTALLING SWAT"
|
||||
@echo "****************************************************************************"
|
||||
@echo " * Installing swat files..."
|
||||
@rsync -av --exclude=crystalsvg --delete build/ $(LOCALINSTALLDIR)
|
||||
|
@ -1,3 +1,12 @@
|
||||
/*
|
||||
* Copyright:
|
||||
* (C) 2006 by Derrell Lipman
|
||||
* All rights reserved
|
||||
*
|
||||
* License:
|
||||
* LGPL 2.1: http://creativecommons.org/licenses/LGPL/2.1/
|
||||
*/
|
||||
|
||||
/**
|
||||
* The graphical user interface for the main menu
|
||||
*/
|
||||
@ -18,7 +27,7 @@ qx.Class.buildGui = function(modules)
|
||||
top: 0,
|
||||
left: 0,
|
||||
right: 0,
|
||||
height: 40,
|
||||
height: 40
|
||||
});
|
||||
o.setBackgroundColor(topColor);
|
||||
o.addToDocument();
|
||||
@ -128,6 +137,8 @@ qx.Class.buildGui = function(modules)
|
||||
// When a Module menu item is selected:
|
||||
o.addEventListener("changeChecked", function(e)
|
||||
{
|
||||
var canvas = modules.list[this.moduleName].canvas;
|
||||
|
||||
// If there's a current canvas, ...
|
||||
if (modules.currentCanvas)
|
||||
{
|
||||
@ -149,6 +160,10 @@ qx.Class.buildGui = function(modules)
|
||||
// Track the current canvas (now ours)
|
||||
modules.currentCanvas = canvas;
|
||||
|
||||
// Dispatch an event on the canvas to notify new
|
||||
// module it's coming into use.
|
||||
canvas.createDispatchEvent("appear");
|
||||
|
||||
// Set the application title
|
||||
title.setHtml("<span>" +
|
||||
"Samba Web Administration Tool" +
|
||||
@ -156,9 +171,10 @@ qx.Class.buildGui = function(modules)
|
||||
this.moduleName +
|
||||
"</span>");
|
||||
|
||||
// Dispatch an event on the canvas to notify new
|
||||
// module it's coming into use.
|
||||
canvas.createDispatchEvent("appear");
|
||||
// Set the browser title as well
|
||||
document.title =
|
||||
"Swat: " + this.moduleName;
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -1,7 +1,17 @@
|
||||
/*
|
||||
#module(swat_main)
|
||||
* Copyright:
|
||||
* (C) 2006 by Derrell Lipman
|
||||
* All rights reserved
|
||||
*
|
||||
* License:
|
||||
* LGPL 2.1: http://creativecommons.org/licenses/LGPL/2.1/
|
||||
*/
|
||||
|
||||
/*
|
||||
#require(swat.module.AbstractModule)
|
||||
#require(swat.module.stats.Statistics)
|
||||
#require(swat.module.statistics.Statistics)
|
||||
#require(swat.module.documentation.Documentation)
|
||||
#require(api.Viewer)
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -13,31 +23,27 @@ function()
|
||||
qx.component.AbstractApplication.call(this);
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* The list of supported modules
|
||||
*/
|
||||
var moduleSystemStatus =
|
||||
{
|
||||
"canvas" : null,
|
||||
"fsm" : null,
|
||||
"class" : swat.module.stats.Statistics
|
||||
};
|
||||
|
||||
/*
|
||||
var moduleLdbView =
|
||||
{
|
||||
"canvas" : null,
|
||||
"fsm" : null,
|
||||
"class" : swat.module.ldbview.LdbView
|
||||
};
|
||||
*/
|
||||
|
||||
qx.Class.modules =
|
||||
{
|
||||
list :
|
||||
{
|
||||
"System Status" : moduleSystemStatus
|
||||
"System Status" :
|
||||
{
|
||||
"canvas" : null,
|
||||
"fsm" : null,
|
||||
"gui" : null,
|
||||
"class" : swat.module.statistics.Statistics
|
||||
},
|
||||
"Documentation" :
|
||||
{
|
||||
"canvas" : null,
|
||||
"fsm" : null,
|
||||
"gui" : null,
|
||||
"class" : swat.module.documentation.Documentation
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -51,7 +57,12 @@ qx.Class.modules =
|
||||
qx.Proto.initialize = function()
|
||||
{
|
||||
var modules = swat.main.Main.modules;
|
||||
var o = new qx.ui.basic.Label("hello world");
|
||||
|
||||
// Set the resource URI
|
||||
qx.Settings.setCustom("resourceUri", "./resource");
|
||||
|
||||
// Turn on JSON debugging for the time being
|
||||
qx.Settings.setCustomOfClass("qx.io.Json", "enableDebug", true);
|
||||
|
||||
// For each module...
|
||||
for (moduleName in modules.list)
|
||||
@ -93,4 +104,5 @@ qx.Proto.finalize = function()
|
||||
var module = modules.list[moduleName]["class"].getInstance();
|
||||
module.finalize(modules.list[moduleName]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1,3 +1,12 @@
|
||||
/*
|
||||
* Copyright:
|
||||
* (C) 2006 by Derrell Lipman
|
||||
* All rights reserved
|
||||
*
|
||||
* License:
|
||||
* LGPL 2.1: http://creativecommons.org/licenses/LGPL/2.1/
|
||||
*/
|
||||
|
||||
/**
|
||||
* Abstract Module class. All modules should extend this class.
|
||||
*/
|
||||
@ -105,7 +114,8 @@ qx.Proto.buildInitialFsm = function(module)
|
||||
|
||||
// Save the finite state machine for this module
|
||||
module.fsm = fsm;
|
||||
fsm.addObject("swat.module.fsm", fsm);
|
||||
|
||||
// Start the finite state machine
|
||||
fsm.start();
|
||||
};
|
||||
|
||||
|
@ -1,6 +1,11 @@
|
||||
/*
|
||||
#module(swat_module)
|
||||
*/
|
||||
* Copyright:
|
||||
* (C) 2006 by Derrell Lipman
|
||||
* All rights reserved
|
||||
*
|
||||
* License:
|
||||
* LGPL 2.1: http://creativecommons.org/licenses/LGPL/2.1/
|
||||
*/
|
||||
|
||||
/**
|
||||
* Common facilities for modules' finite state machines. Each module's FSM
|
||||
@ -99,6 +104,17 @@ qx.Proto.addAwaitRpcResultState = function(module)
|
||||
]
|
||||
},
|
||||
|
||||
"onentry" :
|
||||
function(fsm, state)
|
||||
{
|
||||
// If we're coming from some other start...
|
||||
if (fsm.getPreviousState() != "State_AwaitRpcResult")
|
||||
{
|
||||
// ... then push the previous state onto the state stack
|
||||
fsm.pushState(false);
|
||||
}
|
||||
},
|
||||
|
||||
"events" :
|
||||
{
|
||||
"execute" :
|
||||
@ -108,10 +124,10 @@ qx.Proto.addAwaitRpcResultState = function(module)
|
||||
},
|
||||
|
||||
"completed" :
|
||||
"Transition_AwaitRpcResult_to_Idle_via_complete",
|
||||
"Transition_AwaitRpcResult_to_PopStack_via_complete",
|
||||
|
||||
"failed" :
|
||||
"Transition_AwaitRpcResult_to_Idle_via_failed"
|
||||
"Transition_AwaitRpcResult_to_PopStack_via_failed"
|
||||
}
|
||||
});
|
||||
fsm.addState(state);
|
||||
@ -140,15 +156,15 @@ qx.Proto.addAwaitRpcResultState = function(module)
|
||||
state.addTransition(trans);
|
||||
|
||||
/*
|
||||
* Transition: AwaitRpcResult to Idle
|
||||
* Transition: AwaitRpcResult to PopStack
|
||||
*
|
||||
* Cause: "complete" (on RPC)
|
||||
*/
|
||||
var trans = new qx.util.fsm.Transition(
|
||||
"Transition_AwaitRpcResult_to_Idle_via_complete",
|
||||
"Transition_AwaitRpcResult_to_PopStack_via_complete",
|
||||
{
|
||||
"nextState" :
|
||||
"State_Idle",
|
||||
qx.util.fsm.FiniteStateMachine.StateChange.POP_STATE_STACK,
|
||||
|
||||
"ontransition" :
|
||||
function(fsm, event)
|
||||
@ -167,15 +183,15 @@ qx.Proto.addAwaitRpcResultState = function(module)
|
||||
state.addTransition(trans);
|
||||
|
||||
/*
|
||||
* Transition: AwaitRpcResult to Idle
|
||||
* Transition: AwaitRpcResult to PopStack
|
||||
*
|
||||
* Cause: "failed" (on RPC)
|
||||
*/
|
||||
var trans = new qx.util.fsm.Transition(
|
||||
"Transition_AwaitRpcResult_to_Idle_via_failed",
|
||||
"Transition_AwaitRpcResult_to_PopStack_via_failed",
|
||||
{
|
||||
"nextState" :
|
||||
"State_Idle",
|
||||
qx.util.fsm.FiniteStateMachine.StateChange.POP_STATE_STACK,
|
||||
|
||||
"ontransition" :
|
||||
function(fsm, event)
|
||||
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Copyright:
|
||||
* (C) 2006 by Derrell Lipman
|
||||
* All rights reserved
|
||||
*
|
||||
* License:
|
||||
* LGPL 2.1: http://creativecommons.org/licenses/LGPL/2.1/
|
||||
*/
|
||||
|
||||
/**
|
||||
* Swat statistics class
|
||||
*/
|
||||
qx.OO.defineClass("swat.module.documentation.Documentation",
|
||||
swat.module.AbstractModule,
|
||||
function()
|
||||
{
|
||||
swat.module.AbstractModule.call(this);
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Load the documentation data
|
||||
*
|
||||
* This function is called the first time a module is actually selected to
|
||||
* appear. Creation of the module's GUI has been deferred until it was
|
||||
* actually needed (now), so we need to create it.
|
||||
*
|
||||
* @param module {Object} @see AbstractModule
|
||||
*/
|
||||
qx.Proto.initialAppear = function(module)
|
||||
{
|
||||
qx.manager.object.AliasManager.getInstance().add("api", "./resource/image");
|
||||
|
||||
// Include CSS file.
|
||||
// (This is the hard way; I can't get qx.dom.StyleSheet.includeFile to load)
|
||||
var el = document.createElement("link");
|
||||
el.type = "text/css";
|
||||
el.rel = "stylesheet";
|
||||
el.href = "./resource/css/apiviewer.css";
|
||||
var head = document.getElementsByTagName("head")[0];
|
||||
head.appendChild(el);
|
||||
|
||||
// avoid redundant naming by api viewer
|
||||
qx.Settings.setCustomOfClass("apiviewer.Viewer", "title", "");
|
||||
|
||||
var viewer = new api.Viewer();
|
||||
module.canvas.add(viewer);
|
||||
viewer.load("script/data.js");
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Singleton Instance Getter
|
||||
*/
|
||||
qx.Class.getInstance = qx.util.Return.returnInstance;
|
@ -1,138 +0,0 @@
|
||||
/**
|
||||
* Swat statistics class finite state machine
|
||||
*/
|
||||
qx.OO.defineClass("swat.module.stats.Fsm", swat.module.AbstractModuleFsm,
|
||||
function()
|
||||
{
|
||||
swat.module.AbstractModuleFsm.call(this);
|
||||
});
|
||||
|
||||
|
||||
qx.Proto.buildFsm = function(module)
|
||||
{
|
||||
var fsm = module.fsm;
|
||||
|
||||
/*
|
||||
* State: Idle
|
||||
*
|
||||
* Actions upon entry
|
||||
* - if returning from RPC, display the result
|
||||
* - start an interval timer to request statistics again in a while
|
||||
*
|
||||
* Transition on:
|
||||
* "interval" on interval_timer
|
||||
*/
|
||||
var state = new qx.util.fsm.State(
|
||||
"State_Idle",
|
||||
{
|
||||
"onentry" :
|
||||
function(fsm, state)
|
||||
{
|
||||
// Did we just return from an RPC request?
|
||||
if (fsm.getPreviousState() == "State_AwaitRpcResult")
|
||||
{
|
||||
// Yup. Display the result. We need to get the request object
|
||||
var request = fsm.getObject("swat.module.fsmUtils.request");
|
||||
|
||||
// Get the message object
|
||||
var message = fsm.getObject("message");
|
||||
|
||||
// Did the request succeed or fail?
|
||||
switch(request.result.type)
|
||||
{
|
||||
case "complete":
|
||||
// It succeeded
|
||||
message.setValue("Result: " + request.result.data);
|
||||
break;
|
||||
|
||||
case "failed":
|
||||
// It failed
|
||||
message.setValue("Failed: " + request.result.data);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// Create a timer instance to expire in 5 seconds
|
||||
var timer = new qx.client.Timer(5000);
|
||||
timer.addEventListener("interval", fsm.eventListener, fsm);
|
||||
fsm.addObject("timer", timer);
|
||||
timer.start();
|
||||
},
|
||||
|
||||
"onexit" :
|
||||
function(fsm, state)
|
||||
{
|
||||
// Get the timer object
|
||||
var timer = fsm.getObject("timer");
|
||||
|
||||
// If it still exists...
|
||||
if (timer)
|
||||
{
|
||||
// ... then dispose of it.
|
||||
timer.dispose();
|
||||
fsm.removeObject("timer");
|
||||
}
|
||||
},
|
||||
|
||||
"events" :
|
||||
{
|
||||
// If the timer expires, send a new statistics request
|
||||
"interval" :
|
||||
{
|
||||
"timer" :
|
||||
"Transition_Idle_to_AwaitRpcResult_via_request_statistics"
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// Replace the initial Idle state with this one
|
||||
fsm.replaceState(state, true);
|
||||
|
||||
/*
|
||||
* Transition: Idle to AwaitRpcResult
|
||||
*
|
||||
* Cause: "interval" on timer
|
||||
*
|
||||
* Action:
|
||||
* Issue a Get Statistics request
|
||||
*/
|
||||
var trans = new qx.util.fsm.Transition(
|
||||
"Transition_Idle_to_AwaitRpcResult_via_request_statistics",
|
||||
{
|
||||
"nextState" :
|
||||
"State_AwaitRpcResult",
|
||||
|
||||
"ontransition" :
|
||||
function(fsm, event)
|
||||
{
|
||||
var rpc = fsm.getObject("swat.module.rpc");
|
||||
|
||||
rpc.setUrl("/services/");
|
||||
rpc.setServiceName("samba.admin");
|
||||
|
||||
var request =
|
||||
rpc.callAsyncListeners(true, // coalesce failure events
|
||||
"get_statistics");
|
||||
fsm.addObject("swat.module.fsmUtils.request", request);
|
||||
}
|
||||
});
|
||||
state.addTransition(trans);
|
||||
|
||||
// Add the AwaitRpcResult state and all of its transitions
|
||||
this.addAwaitRpcResultState(module);
|
||||
|
||||
// Allocate an RPC object
|
||||
o = new qx.io.remote.Rpc();
|
||||
o.setTimeout(10000);
|
||||
o.addEventListener("completed", fsm.eventListener, fsm);
|
||||
o.addEventListener("failed", fsm.eventListener, fsm);
|
||||
o.addEventListener("timeout", fsm.eventListener, fsm);
|
||||
o.addEventListener("aborted", fsm.eventListener, fsm);
|
||||
fsm.addObject("swat.module.rpc", o);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Singleton Instance Getter
|
||||
*/
|
||||
qx.Class.getInstance = qx.util.Return.returnInstance;
|
@ -1,28 +0,0 @@
|
||||
/**
|
||||
* Swat statistics class graphical user interface
|
||||
*/
|
||||
qx.OO.defineClass("swat.module.stats.Gui", qx.core.Object,
|
||||
function()
|
||||
{
|
||||
qx.core.Object.call(this);
|
||||
});
|
||||
|
||||
|
||||
qx.Proto.buildGui = function(module)
|
||||
{
|
||||
var o;
|
||||
var fsm = module.fsm;
|
||||
var canvas = module.canvas;
|
||||
|
||||
// Add a message field
|
||||
o = new qx.ui.form.TextField("hello world");
|
||||
o.setWidth(600);
|
||||
canvas.add(o);
|
||||
fsm.addObject("message", o);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Singleton Instance Getter
|
||||
*/
|
||||
qx.Class.getInstance = qx.util.Return.returnInstance;
|
@ -1,33 +0,0 @@
|
||||
/**
|
||||
* Swat statistics class
|
||||
*/
|
||||
qx.OO.defineClass("swat.module.stats.Statistics", swat.module.AbstractModule,
|
||||
function()
|
||||
{
|
||||
swat.module.AbstractModule.call(this);
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* Create the module's finite state machine and graphical user interface.
|
||||
*
|
||||
* This function is called the first time a module is actually selected to
|
||||
* appear. Creation of the module's actual FSM and GUI have been deferred
|
||||
* until they were actually needed (now) so we need to create them.
|
||||
*
|
||||
* @param module {Object} @see AbstractModule
|
||||
*/
|
||||
qx.Proto.initialAppear = function(module)
|
||||
{
|
||||
// Replace the existing (temporary) finite state machine with the real one
|
||||
swat.module.stats.Fsm.getInstance().buildFsm(module);
|
||||
|
||||
// Create the real gui
|
||||
swat.module.stats.Gui.getInstance().buildGui(module);
|
||||
};
|
||||
|
||||
|
||||
/**
|
||||
* Singleton Instance Getter
|
||||
*/
|
||||
qx.Class.getInstance = qx.util.Return.returnInstance;
|
Loading…
Reference in New Issue
Block a user