//void InputFrame_fromImageBuffer(String partnerUUID, BabylonMS.BMSPack imagebufferPack, StreamReader imagebufferReader, StreamWriter imagebufferWriter) void InputFrame_fromImageBuffer(BabylonMS.BMSEventSessionParameter imagebuffersession) { // The Imgebuffer sent some hwnd image data //please send to requester android try { byte cmd = (byte)imagebuffersession.inputPack.GetFieldByName("CMD").getValue(0); Int64 ID = (Int64)imagebuffersession.inputPack.GetFieldByName("REQID").getValue(0); AndroidDescriptor thisAndroid = getAndroidDescriptor(ID); switch (cmd) { case VRCEShared.CONST_COMMAND_RETRIEVE: if (imagebuffersession.inputPack.FieldsCount() > 2) { BabylonMS.BMSPack pack = new BabylonMS.BMSPack(); pack.AddField("CMD", BabylonMS.BabylonMS.CONST_FT_INT8).Value(VRCEShared.CONST_ANDROIDCOMMAND_RETRIEVE_ALL); pack.AddField("PCKCNT", BabylonMS.BabylonMS.CONST_FT_INT8).Value((byte)thisAndroid.sentPackCounter++); int cnt = (imagebuffersession.inputPack.FieldsCount() - 2) / 3; for (int i = 0; i < cnt; i++) { byte idx = (byte)imagebuffersession.inputPack.GetField((i * 4) + 2).getValue(0); pack.AddField("IDX", BabylonMS.BabylonMS.CONST_FT_INT8).Value(idx); pack.AddField("HWND", BabylonMS.BabylonMS.CONST_FT_INT64).Value(imagebuffersession.inputPack.GetField((i * 4) + 3).getValue(0)); pack.AddField("GROUP", BabylonMS.BabylonMS.CONST_FT_UUID).ValueAsUUID(imagebuffersession.inputPack.GetField((i * 4) + 4).GetUUIDValue(0)); pack.AddField("IMAGE", BabylonMS.BabylonMS.CONST_FT_BYTE).Value(imagebuffersession.inputPack.GetField((i * 4) + 5).getValue()); } BabylonMS.BabylonMS.TransferPacket(thisAndroid.writer, pack, true, thisAndroid.locker); //transfer images to requester android } break; } } finally { } }
//void NewAndroidConnected(TcpClient client, StreamReader reader, StreamWriter writer) void NewAndroidConnected(BabylonMS.BMSEventSessionParameter session) { Console.WriteLine("Android Connected"); AndroidDescriptor thisAndroid = new AndroidDescriptor(session); if (!Program.DEBUG_InputControllerOnly) { thisAndroid.bms_imagebuffer = BabylonMS.BabylonMS.LaunchMiniShip(Program.ip_imagebuffer, Program.port_imagebuffer, ImageBuffer.ImageBufferUUID, ImageBuffer.ImageBufferUUID, Program.instanceUUID); //UUID thisAndroid.bms_imagebuffer.IsReady = false; thisAndroid.bms_imagebuffer.NewInputFrame += InputFrame_fromImageBuffer; thisAndroid.bms_imagebuffer.Disconnected += (ses) => { Console.WriteLine("Disconnect from imagebuffer"); }; thisAndroid.bms_imagebuffer.Connected += (ses) => { thisAndroid.bms_imagebuffer.Tag = ses; AndroidsList.Add(thisAndroid); }; thisAndroid.bms_imagebuffer.PrepareGate();//Nonblocking net Client while ((!thisAndroid.bms_imagebuffer.IsReady)) { Thread.Sleep(100); } ; //although the device connected but need time so device can retrieve all windows //Message_To_ImageBuffer_CONST_COMMAND_RETRIEVE(thisAndroid, (BabylonMS.BMSEventSessionParameter)thisAndroid.bms_imagebuffer.Tag); Console.WriteLine("Android personal Imagebuffer Connected "); } else { AndroidsList.Add(thisAndroid); Console.WriteLine("Inputcontroller only so Android personal Imagebuffer not connected"); } }
void Message_To_ImageBuffer_CONST_COMMAND_RETRIEVE(AndroidDescriptor thisAndroid, BabylonMS.BMSEventSessionParameter imagebufferSession) { // after connect send first packet for all content imagebufferSession.outputPack.Clear(); imagebufferSession.outputPack.AddField("CMD", BabylonMS.BabylonMS.CONST_FT_INT8). Value(VRCEShared.CONST_COMMAND_RETRIEVE); imagebufferSession.outputPack.AddField("REQID", BabylonMS.BabylonMS.CONST_FT_INT64). Value(thisAndroid.ID); imagebufferSession.outputPack.SetAttribs(BabylonMS.BabylonMS.CONST_AutosendOutputpack); //A felkapcsolódás után az alábbi packot fogja elküldeni vissza List <Selection> windows = thisAndroid.allRetrieveHwnd(); if ((windows != null) && (windows.Count > 0)) { foreach (var b in windows) { imagebufferSession.outputPack.AddField("HWND", BabylonMS.BabylonMS.CONST_FT_INT64).Value(b.hwnd); imagebufferSession.outputPack.AddField("GROUP", BabylonMS.BabylonMS.CONST_FT_UUID).ValueAsUUID(b.hwndgroupUUID); } } //Így megspórolhatunk egy event-et és nem várunk semmire //ha nincs HWND akkor mindet keri imagebufferSession.TransferPacket(true); //InputFrame_fromAnAndroid }
//F R O M A N D R O I D //void InputFrame_fromAnAndroid(String partnerUUID, BabylonMS.BMSPack pack, TcpClient client, StreamReader reader, StreamWriter writer) void InputFrame_fromAnAndroid(BabylonMS.BMSEventSessionParameter session) { AndroidDescriptor thisAndroid = getAndroidDescriptor(session.client); //Nothing //- direct retrieve images //- setup mouse behaviour // etc... select requested images byte cmd = (byte)session.inputPack.GetField(0).getValue(0); switch (cmd) { case VRCEShared.CONST_ANDROIDCOMMAND_SUBSCRIBE_HWND: //subscribe hwnd break; case VRCEShared.CONST_ANDROIDCOMMAND_SUBSCRIBE_TYPE: //subscribe type (images,mouse,keyboard.... break; case VRCEShared.CONST_ANDROIDCOMMAND_RETRIEVE_HWND: //Direct retrieve a buffer element if need independently from refresh { //TODO szerintem nincs kész nem tesztelt...! //request from IMAGEBUFFER byte index = (byte)session.inputPack.GetField(1).getValue(0); //Request imagebuffer on tcp session.outputPack.Clear(); session.outputPack.SetAttribs(BabylonMS.BabylonMS.CONST_AutosendOutputpack); //A felkapcsolódás után az alábbi packot fogja elküldeni vissza //Így megspórolhatunk egy event-et és nem várunk semmire session.outputPack.AddField("CMD", BabylonMS.BabylonMS.CONST_FT_INT8).Value(VRCEShared.CONST_COMMAND_RETRIEVE_IDX); //TODO session.outputPack.AddField("IDX", BabylonMS.BabylonMS.CONST_FT_INT8).Value(index); session.TransferPacket(true); } break; case VRCEShared.CONST_ANDROIDCOMMAND_RETRIEVE_ALL: //Elküldi a legfrissebb tartalmat minden feliratkozott képről.(feliratkozások minden Androidhoz előzőleg letárolva) { //Message_To_ImageBuffer_CONST_COMMAND_RETRIEVE(thisAndroid,session.); Message_To_ImageBuffer_CONST_COMMAND_RETRIEVE(thisAndroid, (BabylonMS.BMSEventSessionParameter)thisAndroid.bms_imagebuffer.Tag); Console.WriteLine("First retrieve for imagebuffer"); } break; case VRCEShared.CONST_ANDROIDCOMMAND_FOCUS_WINDOW: //Rááll egy ablakra //TODO kapcsolt hálózat? egyelőre ez a gép { String groupUUID = session.inputPack.GetFieldByName("GROUP").GetUUIDValue(0); if (BabylonMS.BabylonMS.compareUUID(Program.instanceUUID, groupUUID)) { //this instance Int64 hwnd = session.inputPack.GetFieldByName("HWND").getValue(0); HandlesList win = HandlesList.getw(hwnd, HandlesList.windows); if (win != null) { win.sc.BringToFront(); } } break; } } }