diff --git a/plugins/unity/com.bl.pocketpy/JsonRpcServer.cs b/plugins/unity/com.bl.pocketpy/JsonRpcServer.cs index 8affa519..d007fab0 100644 --- a/plugins/unity/com.bl.pocketpy/JsonRpcServer.cs +++ b/plugins/unity/com.bl.pocketpy/JsonRpcServer.cs @@ -1,18 +1,31 @@ +using PlasticPipe.PlasticProtocol.Messages; +using System; using System.Collections; using System.Collections.Generic; -using UnityEngine; +using System.Threading.Tasks; -public class JsonRpcServer : MonoBehaviour +namespace pkpy { - // Start is called before the first frame update - void Start() + public abstract class JsonRpcServer { - - } + protected abstract Task dispatch(ThreadedVM vm, string request); - // Update is called once per frame - void Update() - { - + public async Task attach(ThreadedVM vm) + { + while (vm.state <= ThreadState.running) await Task.Yield(); + switch (vm.state) + { + case ThreadState.suspended: + string request = vm.read_jsonrpc_request(); + string response = await dispatch(vm, request); + vm.write_jsonrpc_response(response); + await attach(vm); + break; + case ThreadState.finished: + break; + default: + throw new Exception("Unexpected state"); + } + } } -} +} \ No newline at end of file diff --git a/plugins/unity/com.bl.pocketpy/PocketPy.cs.meta b/plugins/unity/com.bl.pocketpy/PocketPy.cs.meta new file mode 100644 index 00000000..2d0c124f --- /dev/null +++ b/plugins/unity/com.bl.pocketpy/PocketPy.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: dd15753450212f045aa08d30ba3cca6e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: