(*     This file was automatically generated by the	*)
(* 							*)
(*		 VisualObliq Dialog Editor 	 	*)
(*	       	     VERSION 3.0 	        	*)
(*       Krishna Bharat/Marc H Brown/Luca Cardelli  	*)

(* You may edit the $name$.New procedure to configure   *)
(* the start up process                                 *)


(* Copyright (C) 1993, Digital Equipment Corporation 	*)
(* All rights reserved. 							*)
(* See the file COPYRIGHT for a full description. 	    *)
(* 											     *)
(* You should not have to edit this file manually           *)

module $name$;

var allForms = [];
var migrateTo = 0;
(* to allow you to migrate to a remote receiver *)

var installAt = 0;
(* to allow you to  create remote clients *)

$Definition$ (* if not bundled this goes to 'load "$name$DEFN.obl";' 
			  else the definitions are inlined *)
		  
let SERVERNAME = sys_address; 
(* So that everyone knows the server name *)

let CreateEachFormOnce = proc(LOCAL)
	$initForms$
end;



let $name$ = 
   { New => proc(LOCAL)	

	  let HOSTNAME =  LOCAL.HOSTNAME;
	  let SERVERSITE = text_equal(SERVERNAME, HOSTNAME);
	           
	  (* This procedure is the Global Session Constructor, and will                *)
  	  (* be executed by all sites including the server site, at                             *)
	  (* start up							                                                     *)

	  (* You may edit this section to configure the start-up process               *)
	  (* You can use HOSTNAME, SERVERSITE and SERVERNAME to           *)
	  (* create  forms conditionally.					   	    	  	        *)

	  (* SERVERSITE is a flag that is set only at the server site      		      *)
	  (* HOSTNAME is the name of the host that will be executing this  	      *)
 	  (* procedure							   						   *)
	  (* SERVERNAME is the HOSTNAME of the server                     		   *)
	  (* 								   						            *)
	  (* Creation of forms :                                           					       *)
	  (* To create 1 instance of the form named 'foo' use              			 *)
	  (*  	fooNew(LOCAL);						   	  	 			     *)
	  (* To create 1 instance of each form use CreateEachFormOnce(LOCAL) *)
	  (* e.g. to create one instance of $egform$ you will use          			*)
	  (* $egform$New(LOCAL); 				           					*)
    	  	
	  (* -----------------------START------------------------- *)


	    $SessionConstCode$







	  (* ------------------------END-------------------------   *)
	   end	
   };


(* LOCAL is a handle to the local context, which includes the support   *)
(* procedures used to implement operations on widgets. This mechanism   *)
(* ensures that operations that may be done locally are done so         *)
(* You will not need to use this handle except while creating forms as  *)
(* described earlier							*)

net_export("$name$", "", $name$);

installAt := proc(site)
             try
		let vos = net_import("vos", site);
	        vos.Install($name$.New, "$name$");
		true
	     except else
	     	false
             end
            end;

(* Now you can say installAt("somemachine.pa.dec.com") *)

($name$.New)(volibLocal);
(* This executes the constructor at the server site *)

(* Any code that is to be executed at the server site only
   may be placed after this                                *)

$ServerSideCode$

module migrate;

let packFormList = proc(flist)
    try
	if flist isnot 0 then
		foreach frm in flist do
			if (frm isnot ok) and (frm isnot 0) then
			(* is a valid form hopefully *)
				frm.VOPackUp();
			end;
		end;
	end;
    except
    else
    end;
end;

let unpackFormList = proc(flist)
    try
	if flist isnot 0 then
		foreach frm in flist do
			if (frm isnot ok) and (frm isnot 0) then
			(* is a valid form hopefully *)
				frm.VOUnpack();
			end;
		end;
	end;
    except
    else
    end;
end;



let agent = proc(contin, local)       
        contin(local);
end;

var continuation = 0;

migrateTo := proc(dest)
	try
		let atsite = net_importEngine("VOReceiver", dest);
		foreach formlist in allForms do
			packFormList(formlist());
		end;
        	atsite(proc(arg) agent(copy(continuation), arg) end);
		true
	except else
		false
	end 
end;


continuation := proc (local)
	foreach formlist in allForms do
		unpackFormList(formlist());
	end;			
end;

