Difference between revisions of "NodeSpace.h"
m |
(no THEN needed) |
||
Line 160: | Line 160: | ||
// Moves "this" to current loop item if exists then rotates loop and executes or reduces the item | // Moves "this" to current loop item if exists then rotates loop and executes or reduces the item | ||
− | |||
− | |||
void nodeReduce() { | void nodeReduce() { | ||
if (this = nodeGetValue(loop = nodeTraverse(this,nodeLOOP),0)) { // this = current loop item | if (this = nodeGetValue(loop = nodeTraverse(this,nodeLOOP),0)) { // this = current loop item |
Revision as of 01:21, 4 November 2006
// [[[[1]]]] - nodal p2p wiki daemon // This article and all its includes are licenced under LGPL // GPL: [[[[2]]]] // SRC: [[[[3]]]] // included in [[[[4]]]][[[[5]]]]
typedef int node; // node: a type for referring to nodes typedef void (code)(); // code: a type for executing functions from pointer
// nodal constants defined in [[peerd.c]]
// Runtime nodes node this; // this: the current node, like cwd
// stateless node nodeINTERFACE; node nodeSTREAMS; node nodeFIRSTCHILD;
// function ref node nodeEVENTS; node nodeIO; node nodeSERVER; node nodeDESKTOP;
// pointer to struct node nodeSTREAM; node nodeWINDOW; node nodeEVENT;
// Prototypes node nodeTraverse(node subject,node key); node nodeGetValue(node subject,node key); node nodeSetValue(node subject,node key,node value); node nodeInsertKey(node subject,node key); node nodeRemoveKey(node subject,node key); node nodeLoopInsert(node subject,node insert); node nodeLoopRemove(node subject); void **nodeGetState(node subject,node key); int nodeInit(); void nodeExit(); void nodeReduce();
// ----------------------------------------------------------------------------------------- //
// nodeSpace.c
// - use array-of-node path? node nodeTraverse(node subject,node key) { return listTraverse((item)subject,(item)key); }
// set nodal value of node/path // - allows null key node nodeGetValue(node subject,node key) { return listGetValue(key?listTraverse((item)subject,(item)key):(item)subject); }
node nodeSetValue(node subject,node key,node value) { // todo: onChange return listSetValue(key?listTraverse((item)subject,(item)key):(item)subject, (item)value); }
// Returns a newly created node node nodeInsert() { return (node)listInsert(); }
// Returns newly created node // - this is just traverse() but with an event raised node nodeInsertKey(node subject,node key) { // todo: onInstall node i = nodeTraverse(subject,key); return i; }
// Returns the node that was removed node nodeRemoveKey(node subject,node key) { // todo: onRemove node i = nodeTraverse(subject,key); // todo: delete return i; }
// Returns the inserted node as the new loop pointer // - this allows it to act as a stack if nodeLOOP (current-loop-node) is updated with returned node // - either can be 0 on entry (for new loop and/or new node) node nodeLoopInsert(node subject,node insert) { if (insert == 0) insert = nodeInsert(); if (subject == 0) subject = insert; node next = nodeGetValue(subject,nodeNEXT); nodeSetValue(insert,nodeNEXT,next); nodeSetValue(subject,nodeNEXT,insert); nodeSetValue(insert,nodePREV,subject); return nodeSetValue(next,nodePREV,insert); }
// Returns the new loop pointer so nodeLOOP can be removed and updated node nodeLoopRemove(node subject) { node prev = nodeGetValue(subject,nodePREV); node next = nodeGetValue(subject,nodeNEXT); nodeSetValue(next,nodePREV,prev); return nodeSetValue(prev,nodeNEXT,next); }
void **nodeState(node subject,node key) { subject = key ? (node)listTraverse((item)subject,(item)key) : subject; int index = nodeGetValue(subject,nodeDATA); if (index == 0) nodeSetValue(subject,nodeDATA,index = insertPointer(NULL)); return pointer(index); }
// Clean up all the mess and exit // - add exit functions here for any includes requiring cleanup before exit void nodeExit() { logAdd("Gracefully exiting."); ifExit(); ioExit(); listExit(); exit(EXIT_SUCCESS); }
// Set up initial nodal structure
// - todo: this structure should be read from [[nodeSpace.txt]]
// - use [[io.c]] for reading content from wiki if url/file
char *serialise(node);
void deserialise(char*);
int nodeInit() {
if (file) {
// todo: load from file and deserialise
} else { // no file specified in command-line args, use default inline text deserialise("\ *root\ *io;interface;\ *io\ *server;streams;\ *stream\ *interface\ *events;desktop;\ *window\ "); } nodeIO = trieGetValue("io"); logAdd("nodeIO = %d",nodeIO); nodeINTERFACE = trieGetValue("interface"); logAdd("nodeINTERFACE = %d",nodeINTERFACE); nodeSERVER = trieGetValue("server"); logAdd("nodeSERVER = %d",nodeSERVER); nodeSTREAMS = trieGetValue("streams"); logAdd("nodeSTREAMS = %d",nodeSTREAMS); nodeSTREAM = trieGetValue("stream"); logAdd("nodeSTREAM = %d",nodeSTREAM); nodeEVENTS = trieGetValue("events"); logAdd("nodeEVENTS = %d",nodeEVENTS); nodeDESKTOP = trieGetValue("desktop"); logAdd("nodeDESKTOP = %d",nodeDESKTOP); nodeWINDOW = trieGetValue("window"); logAdd("nodeWINDOW = %d",nodeWINDOW);
return EXIT_SUCCESS; }
// Moves "this" to current loop item if exists then rotates loop and executes or reduces the item void nodeReduce() { if (this = nodeGetValue(loop = nodeTraverse(this,nodeLOOP),0)) { // this = current loop item nodeSetValue(loop,0,nodeGetValue(this,nodeNEXT)); // Rotate loop nodeGetValue(this,nodeCODE)?((code*)*nodeState(this,0))():nodeReduce(); // Exec or reduce item } }