Index: Makefile ================================================================== --- Makefile +++ Makefile @@ -151,17 +151,22 @@ $(INSTALL) mt-pg.sql $(PREFIX)/share/db/mt-pg.sql # Special dependencies for the includes $(MOFILE) $(MOIMPFILES) : megatest-fossil-hash.scm +#====================================================================== +# Other deps +#====================================================================== + # common.o : mofiles/commonmod.o megatest-fossil-hash.scm # commonmod.o dashboard.o megatest.o tcmt.o apimod.o : megatest-fossil-hash.scm tests.o db.o launch.o runs.o dashboard-tests.o \ dashboard-context-menu.o dashboard-guimonitor.o dashboard-main.o \ monitor.o dashboard.o archive.o megatest.o : db_records.scm megatest-fossil-hash.scm +mofiles/ulex.o : ulex/ulex.scm tests.o runs.o dashboard.o dashboard-tests.o dashboard-context-menu.o dashboard-main.o : run_records.scm db.o ezsteps.o keys.o launch.o megatest.o monitor.o runs-for-ref.o runs.o tests.o : key_records.scm Index: rmt.scm ================================================================== --- rmt.scm +++ rmt.scm @@ -24,10 +24,13 @@ (declare (uses api)) (declare (uses http-transport)) (declare (uses rmtmod)) (import (prefix rmtmod rmtmod:)) +(declare (uses ulex)) +(import (prefix ulex ulex:)) + (include "common_records.scm") (include "db_records.scm") ;; ;; THESE ARE ALL CALLED ON THE CLIENT SIDE!!! @@ -74,13 +77,15 @@ (set! *rmt-query-last-rest-time* now) (set! *rmt-query-last-call-time* now)) (else ;; sufficient rests have occurred, just record the last query time (set! *rmt-query-last-call-time* now))))) +(define *alldat* (rmtmod:create-alldat *toppath*)) + (define (rmt:send-receive cmd rid params #!key (attemptnum 1)(area-dat #f)) (if (equal? (configf:lookup *configdat* "setup" "newapi") "yes") - (rmtmod:send-receive cmd rid params attemptnum: 1 area-dat: #f) + (rmtmod:send-receive *alldat* cmd rid params) (rmt:send-receive-orig cmd rid params attemptnum: 1 area-dat: #f))) ;; RA => e.g. usage (rmt:send-receive 'get-var #f (list varname)) ;; (define (rmt:send-receive-orig cmd rid params #!key (attemptnum 1)(area-dat #f)) ;; start attemptnum at 1 so the modulo below works as expected Index: rmtmod.scm ================================================================== --- rmtmod.scm +++ rmtmod.scm @@ -26,21 +26,36 @@ (module rmtmod * (import scheme chicken data-structures extras) (import (prefix sqlite3 sqlite3:) posix typed-records srfi-18) - +(use tcp6) (import (prefix ulex ulex:)) (defstruct alldat (areapath #f) - (ulexdat #f) + (ulexdat (ulex:make-udat)) ) -(define (send-receive cmd rid params #!key (attemptnum 1)(area-dat #f)) - (print "Got here.") - (exit)) +;; create-alldat also sets up our tcp server +;; +(define (create-alldat areapath) + (let* ((adat (make-alldat)) + (udat (alldat-ulexdat adat))) + (alldat-areapath-set! adat areapath) + (if (not (ulex:start-server-find-port udat (+ 4242 (random 5000)))) + (print "Server NOT started properly")) + (thread-start! (make-thread + (lambda () + (ulex:ulex-handler-loop udat)) + "Ulex handler loop thread")) + ;; exit handler needed here + adat)) + +(define (send-receive adat cmd rid params) + (let* ((dbpath (conc (alldat-areapath adat) "/dbs/" (modulo (or rid 0) 1000) ".db"))) + (ulex:remote-call (alldat-ulexdat adat) dbpath 'megatest cmd params))) ;; return the handle struct for sending queries to a specific database ;; - initializes the connection object if this is the first access ;; - finds the "captain" and asks who to talk to for the given dbfname ;; - establishes the connection to the current dbowner Index: ulex/ulex.scm ================================================================== --- ulex/ulex.scm +++ ulex/ulex.scm @@ -105,16 +105,18 @@ ;; udata - all the connection info, captain, server, ulex db etc. MUST BE PASSED IN ;; dbpath - full path and filename of the db to talk to or a symbol naming the db? ;; callname - the remote call to execute ;; params - parameters to pass to the remote call ;; -(define (remote-call udata dbpath dbtype callname . params) +(define (remote-call udata dbpath dbtype callname params) (start-server-find-port udata) ;; ensure we have a local server (find-or-setup-captain udata) ;; look at connect, process-request, send, send-receive (let-values (((cookie-key host-port)(get-db-owner udata dbpath dbtype))) - (send-receive udata host-port callname cookie-key params))) + (if (and cookie-key host-port) + (send-receive udata host-port callname cookie-key params) + #f))) ;;====================================================================== ;; KEY FUNCTIONS - THESE ARE TOO BE EXPOSED AND USED ;;====================================================================== @@ -213,13 +215,14 @@ (let* ((cookie (make-cookie udata)) (msg #f) ;; (conc dbname " " dbtype)) (params `(,dbname ,dbtype)) (res (send udata host-port 'db-owner cookie msg params: params retval: #t))) - (match (string-split res) + (match (and res (string-split res)) ((retcookie owner-host-port) - (values (equal? retcookie cookie) owner-host-port)))) + (values (equal? retcookie cookie) owner-host-port)) + (else (values #f #f)))) (values #f -1)))) ;; called in ulex-handler to dispatch work, called on the workers side ;; calls (proc params data) ;; returns result with cookie @@ -540,10 +543,12 @@ newcnum))) ;; create a tcp listener and return a populated udat struct with ;; my port, address, hostname, pid etc. ;; return #f if fail to find a port to allocate. +;; +;; does not actually start a server thread ;; ;; if udata-in is #f create the record ;; if there is already a serv-listener return the udata ;; (define (start-server-find-port udata-in #!optional (port 4242)(tries 0))