package b4a.example;

import anywheresoftware.b4a.BA;
import anywheresoftware.b4a.pc.*;

public class starter_subs_0 {


public static RemoteObject  _application_error(RemoteObject _error,RemoteObject _stacktrace) throws Exception{
try {
		Debug.PushSubsStack("Application_Error (starter) ","starter",1,starter.processBA,starter.mostCurrent,104);
if (RapidSub.canDelegate("application_error")) { return b4a.example.starter.remoteMe.runUserSub(false, "starter","application_error", _error, _stacktrace);}
Debug.locals.put("Error", _error);
Debug.locals.put("StackTrace", _stacktrace);
 BA.debugLineNum = 104;BA.debugLine="Sub Application_Error (Error As Exception, StackTr";
Debug.ShouldStop(128);
 BA.debugLineNum = 105;BA.debugLine="Return True";
Debug.ShouldStop(256);
if (true) return starter.mostCurrent.__c.getField(true,"True");
 BA.debugLineNum = 106;BA.debugLine="End Sub";
Debug.ShouldStop(512);
return RemoteObject.createImmutable(false);
}
catch (Exception e) {
			throw Debug.ErrorCaught(e);
		} 
finally {
			Debug.PopSubsStack();
		}}
public static RemoteObject  _astream_error() throws Exception{
try {
		Debug.PushSubsStack("AStream_Error (starter) ","starter",1,starter.processBA,starter.mostCurrent,79);
if (RapidSub.canDelegate("astream_error")) { return b4a.example.starter.remoteMe.runUserSub(false, "starter","astream_error");}
 BA.debugLineNum = 79;BA.debugLine="Sub AStream_Error";
Debug.ShouldStop(16384);
 BA.debugLineNum = 80;BA.debugLine="UpdateState(False)";
Debug.ShouldStop(32768);
_updatestate(starter.mostCurrent.__c.getField(true,"False"));
 BA.debugLineNum = 81;BA.debugLine="End Sub";
Debug.ShouldStop(65536);
return RemoteObject.createImmutable("");
}
catch (Exception e) {
			throw Debug.ErrorCaught(e);
		} 
finally {
			Debug.PopSubsStack();
		}}
public static RemoteObject  _astream_newdata(RemoteObject _buffer) throws Exception{
try {
		Debug.PushSubsStack("AStream_NewData (starter) ","starter",1,starter.processBA,starter.mostCurrent,87);
if (RapidSub.canDelegate("astream_newdata")) { return b4a.example.starter.remoteMe.runUserSub(false, "starter","astream_newdata", _buffer);}
Debug.locals.put("Buffer", _buffer);
 BA.debugLineNum = 87;BA.debugLine="Sub AStream_NewData (Buffer() As Byte)";
Debug.ShouldStop(4194304);
 BA.debugLineNum = 89;BA.debugLine="return_data_TPlink=True";
Debug.ShouldStop(16777216);
starter._return_data_tplink = starter.mostCurrent.__c.getField(true,"True");
 BA.debugLineNum = 90;BA.debugLine="If IsPaused(Get_data)=False Then";
Debug.ShouldStop(33554432);
if (RemoteObject.solveBoolean("=",starter.mostCurrent.__c.runMethod(true,"IsPaused",starter.processBA,(Object)((starter.mostCurrent._get_data.getObject()))),starter.mostCurrent.__c.getField(true,"False"))) { 
 BA.debugLineNum = 91;BA.debugLine="CallSub2(Get_data, \"NewData\", Buffer)";
Debug.ShouldStop(67108864);
starter.mostCurrent.__c.runMethodAndSync(false,"CallSubNew2",starter.processBA,(Object)((starter.mostCurrent._get_data.getObject())),(Object)(BA.ObjectToString("NewData")),(Object)((_buffer)));
 };
 BA.debugLineNum = 93;BA.debugLine="StopService(Get_data)";
Debug.ShouldStop(268435456);
starter.mostCurrent.__c.runVoidMethod ("StopService",starter.processBA,(Object)((starter.mostCurrent._get_data.getObject())));
 BA.debugLineNum = 95;BA.debugLine="End Sub";
Debug.ShouldStop(1073741824);
return RemoteObject.createImmutable("");
}
catch (Exception e) {
			throw Debug.ErrorCaught(e);
		} 
finally {
			Debug.PopSubsStack();
		}}
public static RemoteObject  _astream_terminated() throws Exception{
try {
		Debug.PushSubsStack("AStream_Terminated (starter) ","starter",1,starter.processBA,starter.mostCurrent,83);
if (RapidSub.canDelegate("astream_terminated")) { return b4a.example.starter.remoteMe.runUserSub(false, "starter","astream_terminated");}
 BA.debugLineNum = 83;BA.debugLine="Sub AStream_Terminated";
Debug.ShouldStop(262144);
 BA.debugLineNum = 84;BA.debugLine="UpdateState(False)";
Debug.ShouldStop(524288);
_updatestate(starter.mostCurrent.__c.getField(true,"False"));
 BA.debugLineNum = 85;BA.debugLine="End Sub";
Debug.ShouldStop(1048576);
return RemoteObject.createImmutable("");
}
catch (Exception e) {
			throw Debug.ErrorCaught(e);
		} 
finally {
			Debug.PopSubsStack();
		}}
public static RemoteObject  _closeexistingconnection() throws Exception{
try {
		Debug.PushSubsStack("CloseExistingConnection (starter) ","starter",1,starter.processBA,starter.mostCurrent,67);
if (RapidSub.canDelegate("closeexistingconnection")) { return b4a.example.starter.remoteMe.runUserSub(false, "starter","closeexistingconnection");}
 BA.debugLineNum = 67;BA.debugLine="Sub CloseExistingConnection";
Debug.ShouldStop(4);
 BA.debugLineNum = 68;BA.debugLine="If astream.IsInitialized Then astream.Close";
Debug.ShouldStop(8);
if (starter._astream.runMethod(true,"IsInitialized").<Boolean>get().booleanValue()) { 
starter._astream.runVoidMethod ("Close");};
 BA.debugLineNum = 70;BA.debugLine="If client.IsInitialized Then client.Close";
Debug.ShouldStop(32);
if (starter._client.runMethod(true,"IsInitialized").<Boolean>get().booleanValue()) { 
starter._client.runVoidMethod ("Close");};
 BA.debugLineNum = 71;BA.debugLine="UpdateState (False)";
Debug.ShouldStop(64);
_updatestate(starter.mostCurrent.__c.getField(true,"False"));
 BA.debugLineNum = 72;BA.debugLine="End Sub";
Debug.ShouldStop(128);
return RemoteObject.createImmutable("");
}
catch (Exception e) {
			throw Debug.ErrorCaught(e);
		} 
finally {
			Debug.PopSubsStack();
		}}
public static void  _connecttoserver(RemoteObject _host) throws Exception{
try {
		Debug.PushSubsStack("ConnectToServer (starter) ","starter",1,starter.processBA,starter.mostCurrent,43);
if (RapidSub.canDelegate("connecttoserver")) { b4a.example.starter.remoteMe.runUserSub(false, "starter","connecttoserver", _host); return;}
ResumableSub_ConnectToServer rsub = new ResumableSub_ConnectToServer(null,_host);
rsub.resume(null, null);
}
catch (Exception e) {
			throw Debug.ErrorCaught(e);
		} 
finally {
			Debug.PopSubsStack();
		}}
public static class ResumableSub_ConnectToServer extends BA.ResumableSub {
public ResumableSub_ConnectToServer(b4a.example.starter parent,RemoteObject _host) {
this.parent = parent;
this._host = _host;
}
java.util.LinkedHashMap<String, Object> rsLocals = new java.util.LinkedHashMap<String, Object>();
b4a.example.starter parent;
RemoteObject _host;
RemoteObject _successful = RemoteObject.createImmutable(false);

@Override
public void resume(BA ba, RemoteObject result) throws Exception{
try {
		Debug.PushSubsStack("ConnectToServer (starter) ","starter",1,starter.processBA,starter.mostCurrent,43);
Debug.locals = rsLocals;Debug.currentSubFrame.locals = rsLocals;

    while (true) {
        switch (state) {
            case -1:
return;

case 0:
//C
this.state = 1;
Debug.locals.put("Host", _host);
 BA.debugLineNum = 44;BA.debugLine="Log(\"Trying to connect to: \" & Host)";
Debug.ShouldStop(2048);
parent.mostCurrent.__c.runVoidMethod ("LogImpl","21310721",RemoteObject.concat(RemoteObject.createImmutable("Trying to connect to: "),_host),0);
 BA.debugLineNum = 45;BA.debugLine="CloseExistingConnection";
Debug.ShouldStop(4096);
_closeexistingconnection();
 BA.debugLineNum = 46;BA.debugLine="Dim client As Socket";
Debug.ShouldStop(8192);
parent._client = RemoteObject.createNew ("anywheresoftware.b4a.objects.SocketWrapper");
 BA.debugLineNum = 47;BA.debugLine="client.Initialize(\"client\")";
Debug.ShouldStop(16384);
parent._client.runVoidMethod ("Initialize",(Object)(RemoteObject.createImmutable("client")));
 BA.debugLineNum = 48;BA.debugLine="client.Connect(Host, PORT, 10000)";
Debug.ShouldStop(32768);
parent._client.runVoidMethod ("Connect",starter.processBA,(Object)(_host),(Object)(parent._port),(Object)(BA.numberCast(int.class, 10000)));
 BA.debugLineNum = 49;BA.debugLine="Wait For Client_Connected (Successful As Boolean)";
Debug.ShouldStop(65536);
parent.mostCurrent.__c.runVoidMethod ("WaitFor","client_connected", starter.processBA, anywheresoftware.b4a.pc.PCResumableSub.createDebugResumeSub(this, "starter", "connecttoserver"), null);
this.state = 7;
return;
case 7:
//C
this.state = 1;
_successful = (RemoteObject) result.getArrayElement(true,RemoteObject.createImmutable(0));Debug.locals.put("Successful", _successful);
;
 BA.debugLineNum = 51;BA.debugLine="If Successful Then";
Debug.ShouldStop(262144);
if (true) break;

case 1:
//if
this.state = 6;
if (_successful.<Boolean>get().booleanValue()) { 
this.state = 3;
}else {
this.state = 5;
}if (true) break;

case 3:
//C
this.state = 6;
 BA.debugLineNum = 53;BA.debugLine="astream.Initialize(client.InputStream, client.Ou";
Debug.ShouldStop(1048576);
parent._astream.runVoidMethod ("Initialize",starter.processBA,(Object)(parent._client.runMethod(false,"getInputStream")),(Object)(parent._client.runMethod(false,"getOutputStream")),(Object)(RemoteObject.createImmutable("astream")));
 BA.debugLineNum = 55;BA.debugLine="UpdateState (True)";
Debug.ShouldStop(4194304);
_updatestate(parent.mostCurrent.__c.getField(true,"True"));
 if (true) break;

case 5:
//C
this.state = 6;
 BA.debugLineNum = 58;BA.debugLine="Log(\"Failed to connect: \" & LastException)";
Debug.ShouldStop(33554432);
parent.mostCurrent.__c.runVoidMethod ("LogImpl","21310735",RemoteObject.concat(RemoteObject.createImmutable("Failed to connect: "),parent.mostCurrent.__c.runMethod(false,"LastException",starter.processBA)),0);
 if (true) break;

case 6:
//C
this.state = -1;
;
 BA.debugLineNum = 60;BA.debugLine="End Sub";
Debug.ShouldStop(134217728);
if (true) break;

            }
        }
    }
catch (Exception e) {
			throw Debug.ErrorCaught(e);
		} 
finally {
			Debug.PopSubsStack();
		}}
}
public static void  _client_connected(RemoteObject _successful) throws Exception{
}
public static RemoteObject  _disconnect() throws Exception{
try {
		Debug.PushSubsStack("Disconnect (starter) ","starter",1,starter.processBA,starter.mostCurrent,62);
if (RapidSub.canDelegate("disconnect")) { return b4a.example.starter.remoteMe.runUserSub(false, "starter","disconnect");}
 BA.debugLineNum = 62;BA.debugLine="Public Sub Disconnect";
Debug.ShouldStop(536870912);
 BA.debugLineNum = 64;BA.debugLine="CloseExistingConnection";
Debug.ShouldStop(-2147483648);
_closeexistingconnection();
 BA.debugLineNum = 65;BA.debugLine="End Sub";
Debug.ShouldStop(1);
return RemoteObject.createImmutable("");
}
catch (Exception e) {
			throw Debug.ErrorCaught(e);
		} 
finally {
			Debug.PopSubsStack();
		}}
public static void  _listenforconnections() throws Exception{
try {
		Debug.PushSubsStack("ListenForConnections (starter) ","starter",1,starter.processBA,starter.mostCurrent,24);
if (RapidSub.canDelegate("listenforconnections")) { b4a.example.starter.remoteMe.runUserSub(false, "starter","listenforconnections"); return;}
ResumableSub_ListenForConnections rsub = new ResumableSub_ListenForConnections(null);
rsub.resume(null, null);
}
catch (Exception e) {
			throw Debug.ErrorCaught(e);
		} 
finally {
			Debug.PopSubsStack();
		}}
public static class ResumableSub_ListenForConnections extends BA.ResumableSub {
public ResumableSub_ListenForConnections(b4a.example.starter parent) {
this.parent = parent;
}
java.util.LinkedHashMap<String, Object> rsLocals = new java.util.LinkedHashMap<String, Object>();
b4a.example.starter parent;
RemoteObject _successful = RemoteObject.createImmutable(false);
RemoteObject _newsocket = RemoteObject.declareNull("anywheresoftware.b4a.objects.SocketWrapper");

@Override
public void resume(BA ba, RemoteObject result) throws Exception{
try {
		Debug.PushSubsStack("ListenForConnections (starter) ","starter",1,starter.processBA,starter.mostCurrent,24);
Debug.locals = rsLocals;Debug.currentSubFrame.locals = rsLocals;

    while (true) {
        switch (state) {
            case -1:
return;

case 0:
//C
this.state = 1;
 BA.debugLineNum = 25;BA.debugLine="Do While working";
Debug.ShouldStop(16777216);
if (true) break;

case 1:
//do while
this.state = 8;
while (parent._working.<Boolean>get().booleanValue()) {
this.state = 3;
if (true) break;
}
if (true) break;

case 3:
//C
this.state = 4;
 BA.debugLineNum = 26;BA.debugLine="server.Listen";
Debug.ShouldStop(33554432);
parent._server.runVoidMethod ("Listen");
 BA.debugLineNum = 27;BA.debugLine="Wait For Server_NewConnection (Successful As Boo";
Debug.ShouldStop(67108864);
parent.mostCurrent.__c.runVoidMethod ("WaitFor","server_newconnection", starter.processBA, anywheresoftware.b4a.pc.PCResumableSub.createDebugResumeSub(this, "starter", "listenforconnections"), null);
this.state = 9;
return;
case 9:
//C
this.state = 4;
_successful = (RemoteObject) result.getArrayElement(true,RemoteObject.createImmutable(0));Debug.locals.put("Successful", _successful);
_newsocket = (RemoteObject) result.getArrayElement(false,RemoteObject.createImmutable(1));Debug.locals.put("NewSocket", _newsocket);
;
 BA.debugLineNum = 29;BA.debugLine="If Successful Then";
Debug.ShouldStop(268435456);
if (true) break;

case 4:
//if
this.state = 7;
if (_successful.<Boolean>get().booleanValue()) { 
this.state = 6;
}if (true) break;

case 6:
//C
this.state = 7;
 BA.debugLineNum = 30;BA.debugLine="CloseExistingConnection";
Debug.ShouldStop(536870912);
_closeexistingconnection();
 BA.debugLineNum = 31;BA.debugLine="client = NewSocket";
Debug.ShouldStop(1073741824);
parent._client = _newsocket;
 BA.debugLineNum = 33;BA.debugLine="astream.Initialize(client.InputStream ,client.O";
Debug.ShouldStop(1);
parent._astream.runVoidMethod ("Initialize",starter.processBA,(Object)(parent._client.runMethod(false,"getInputStream")),(Object)(parent._client.runMethod(false,"getOutputStream")),(Object)(RemoteObject.createImmutable("astream")));
 BA.debugLineNum = 34;BA.debugLine="UpdateState(True)";
Debug.ShouldStop(2);
_updatestate(parent.mostCurrent.__c.getField(true,"True"));
 if (true) break;

case 7:
//C
this.state = 1;
;
 if (true) break;

case 8:
//C
this.state = -1;
;
 BA.debugLineNum = 37;BA.debugLine="End Sub";
Debug.ShouldStop(16);
if (true) break;

            }
        }
    }
catch (Exception e) {
			throw Debug.ErrorCaught(e);
		} 
finally {
			Debug.PopSubsStack();
		}}
}
public static void  _server_newconnection(RemoteObject _successful,RemoteObject _newsocket) throws Exception{
}
public static RemoteObject  _process_globals() throws Exception{
 //BA.debugLineNum = 6;BA.debugLine="Sub Process_Globals";
 //BA.debugLineNum = 7;BA.debugLine="Public connected As Boolean";
starter._connected = RemoteObject.createImmutable(false);
 //BA.debugLineNum = 8;BA.debugLine="Private client As Socket";
starter._client = RemoteObject.createNew ("anywheresoftware.b4a.objects.SocketWrapper");
 //BA.debugLineNum = 9;BA.debugLine="Public server As ServerSocket";
starter._server = RemoteObject.createNew ("anywheresoftware.b4a.objects.SocketWrapper.ServerSocketWrapper");
 //BA.debugLineNum = 10;BA.debugLine="Private astream As AsyncStreams";
starter._astream = RemoteObject.createNew ("anywheresoftware.b4a.randomaccessfile.AsyncStreams");
 //BA.debugLineNum = 12;BA.debugLine="Private const PORT As Int = 9999";
starter._port = BA.numberCast(int.class, 9999);
 //BA.debugLineNum = 13;BA.debugLine="Private working As Boolean = True";
starter._working = starter.mostCurrent.__c.getField(true,"True");
 //BA.debugLineNum = 14;BA.debugLine="Public return_data_TPlink As Boolean=False";
starter._return_data_tplink = starter.mostCurrent.__c.getField(true,"False");
 //BA.debugLineNum = 16;BA.debugLine="End Sub";
return RemoteObject.createImmutable("");
}
public static RemoteObject  _senddata(RemoteObject _data) throws Exception{
try {
		Debug.PushSubsStack("SendData (starter) ","starter",1,starter.processBA,starter.mostCurrent,97);
if (RapidSub.canDelegate("senddata")) { return b4a.example.starter.remoteMe.runUserSub(false, "starter","senddata", _data);}
Debug.locals.put("data", _data);
 BA.debugLineNum = 97;BA.debugLine="Public Sub SendData (data() As Byte)";
Debug.ShouldStop(1);
 BA.debugLineNum = 99;BA.debugLine="If connected Then astream.Write(data)";
Debug.ShouldStop(4);
if (starter._connected.<Boolean>get().booleanValue()) { 
starter._astream.runVoidMethod ("Write",(Object)(_data));};
 BA.debugLineNum = 100;BA.debugLine="End Sub";
Debug.ShouldStop(8);
return RemoteObject.createImmutable("");
}
catch (Exception e) {
			throw Debug.ErrorCaught(e);
		} 
finally {
			Debug.PopSubsStack();
		}}
public static RemoteObject  _service_create() throws Exception{
try {
		Debug.PushSubsStack("Service_Create (starter) ","starter",1,starter.processBA,starter.mostCurrent,18);
if (RapidSub.canDelegate("service_create")) { return b4a.example.starter.remoteMe.runUserSub(false, "starter","service_create");}
 BA.debugLineNum = 18;BA.debugLine="Sub Service_Create";
Debug.ShouldStop(131072);
 BA.debugLineNum = 19;BA.debugLine="server.Initialize(PORT, \"server\")";
Debug.ShouldStop(262144);
starter._server.runVoidMethod ("Initialize",starter.processBA,(Object)(starter._port),(Object)(RemoteObject.createImmutable("server")));
 BA.debugLineNum = 20;BA.debugLine="ListenForConnections";
Debug.ShouldStop(524288);
_listenforconnections();
 BA.debugLineNum = 22;BA.debugLine="End Sub";
Debug.ShouldStop(2097152);
return RemoteObject.createImmutable("");
}
catch (Exception e) {
			throw Debug.ErrorCaught(e);
		} 
finally {
			Debug.PopSubsStack();
		}}
public static RemoteObject  _service_destroy() throws Exception{
try {
		Debug.PushSubsStack("Service_Destroy (starter) ","starter",1,starter.processBA,starter.mostCurrent,108);
if (RapidSub.canDelegate("service_destroy")) { return b4a.example.starter.remoteMe.runUserSub(false, "starter","service_destroy");}
 BA.debugLineNum = 108;BA.debugLine="Sub Service_Destroy";
Debug.ShouldStop(2048);
 BA.debugLineNum = 110;BA.debugLine="End Sub";
Debug.ShouldStop(8192);
return RemoteObject.createImmutable("");
}
catch (Exception e) {
			throw Debug.ErrorCaught(e);
		} 
finally {
			Debug.PopSubsStack();
		}}
public static RemoteObject  _service_start(RemoteObject _startingintent) throws Exception{
try {
		Debug.PushSubsStack("Service_Start (starter) ","starter",1,starter.processBA,starter.mostCurrent,39);
if (RapidSub.canDelegate("service_start")) { return b4a.example.starter.remoteMe.runUserSub(false, "starter","service_start", _startingintent);}
Debug.locals.put("StartingIntent", _startingintent);
 BA.debugLineNum = 39;BA.debugLine="Sub Service_Start (StartingIntent As Intent)";
Debug.ShouldStop(64);
 BA.debugLineNum = 41;BA.debugLine="End Sub";
Debug.ShouldStop(256);
return RemoteObject.createImmutable("");
}
catch (Exception e) {
			throw Debug.ErrorCaught(e);
		} 
finally {
			Debug.PopSubsStack();
		}}
public static RemoteObject  _updatestate(RemoteObject _newstate) throws Exception{
try {
		Debug.PushSubsStack("UpdateState (starter) ","starter",1,starter.processBA,starter.mostCurrent,74);
if (RapidSub.canDelegate("updatestate")) { return b4a.example.starter.remoteMe.runUserSub(false, "starter","updatestate", _newstate);}
Debug.locals.put("NewState", _newstate);
 BA.debugLineNum = 74;BA.debugLine="Sub UpdateState (NewState As Boolean)";
Debug.ShouldStop(512);
 BA.debugLineNum = 75;BA.debugLine="connected = NewState";
Debug.ShouldStop(1024);
starter._connected = _newstate;
 BA.debugLineNum = 76;BA.debugLine="CallSub(Main, \"SetState\")";
Debug.ShouldStop(2048);
starter.mostCurrent.__c.runMethodAndSync(false,"CallSubNew",starter.processBA,(Object)((starter.mostCurrent._main.getObject())),(Object)(RemoteObject.createImmutable("SetState")));
 BA.debugLineNum = 77;BA.debugLine="End Sub";
Debug.ShouldStop(4096);
return RemoteObject.createImmutable("");
}
catch (Exception e) {
			throw Debug.ErrorCaught(e);
		} 
finally {
			Debug.PopSubsStack();
		}}
}