Skip to content
Snippets Groups Projects
Commit cafd4e6c authored by Sylvain Renault's avatar Sylvain Renault
Browse files

Preparation of REST and websocket client functions.

Some namepsace changes.
parent 7e30b844
No related branches found
No related tags found
1 merge request!2Finalisation of REST and websocket client functions and subscription methodics.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Networking;
namespace ETSI.ARF.OpenAPI.WorldAnalysis
{
/// <summary>
/// Catch the pre/pos request methods from the autogenerated classes
/// </summary>
public partial class WorldAnalysisClient : BaseClient
{
partial void PrepareRequest(ETSI.ARF.OpenAPI.WorldAnalysis.IHttpClient client, System.Net.Http.HttpRequestMessage request, string url)
{
_prepareRequest(client, request, url);
}
partial void PrepareRequest(ETSI.ARF.OpenAPI.WorldAnalysis.IHttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder)
{
// do something...
}
partial void ProcessResponse(ETSI.ARF.OpenAPI.WorldAnalysis.IHttpClient client, System.Net.Http.HttpResponseMessage response)
{
_processResponse(client, response);
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 748d04737c53fc04697ac6888226e399
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 6f0fd52fd30564a4c838a545fe0d00ec
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
//
// ARF - Augmented Reality Framework (ETSI ISG ARF)
//
// Copyright 2024 ETSI
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Last change: March 2024
//
using System;
using System.Threading.Tasks;
using UnityEngine;
using ETSI.ARF.OpenAPI;
using ETSI.ARF.OpenAPI.WorldAnalysis;
namespace ETSI.ARF.WorldAnalysis.REST
{
public class AdminRequest : RequestBase<string>
{
//
// Wrapper for the endpoints
//
static public string PingSync(WorldAnalysisServer ws)
{
wsServer = ws;
var httpClient = new BasicHTTPClient(ws.URI);
apiClient = new WorldAnalysisClient(httpClient);
string response = apiClient.GetPing();
return response;
}
static public ResponseObject<string> PingAsync(WorldAnalysisServer ws, Action<ResponseObject<string>> func)
{
wsServer = ws;
var httpClient = new UnityWebRequestHttpClient(ws.URI);
apiClient = new WorldAnalysisClient(httpClient);
Debug.Log("[REST] Request Ping...");
ResponseObject<string> ro = new ResponseObject<string>("Request Ping", func);
apiClient.GetPingAsync(ro.cancellationToken).ContinueWith(OnReceiveObject<string>, ro);
return ro;
}
static public string AdminSync(WorldAnalysisServer ws)
{
wsServer = ws;
var httpClient = new BasicHTTPClient(ws.URI);
apiClient = new WorldAnalysisClient(httpClient);
string response = apiClient.GetAdmin();
return response;
}
static public ResponseObject<string> AdminAsync(WorldAnalysisServer ws, Action<ResponseObject<string>> func)
{
wsServer = ws;
var httpClient = new UnityWebRequestHttpClient(ws.URI);
apiClient = new WorldAnalysisClient(httpClient);
Debug.Log("[REST] Request Admin...");
ResponseObject<string> ro = new ResponseObject<string>("Request Admin", func);
apiClient.GetAdminAsync(ro.cancellationToken).ContinueWith(OnReceiveObject<string>, ro);
return ro;
}
static public string VersionSync(WorldAnalysisServer ws)
{
wsServer = ws;
var httpClient = new BasicHTTPClient(ws.URI);
apiClient = new WorldAnalysisClient(httpClient);
string response = apiClient.GetVersion();
return response;
}
static public ResponseObject<string> VersionAsync(WorldAnalysisServer ws, Action<ResponseObject<string>> func)
{
wsServer = ws;
var httpClient = new UnityWebRequestHttpClient(ws.URI);
apiClient = new WorldAnalysisClient(httpClient);
Debug.Log("[REST] Request Version...");
ResponseObject<string> ro = new ResponseObject<string>("Request Version", func);
apiClient.GetVersionAsync(ro.cancellationToken).ContinueWith(OnReceiveObject<string>, ro);
return ro;
}
}
}
fileFormatVersion: 2
guid: f287a535887d14c46859e33386b90b0e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
//
// ARF - Augmented Reality Framework (ETSI ISG ARF)
//
// Copyright 2024 ETSI
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Last change: March 2024
//
using System;
using System.Threading.Tasks;
using System.Collections.Generic;
using UnityEngine;
using ETSI.ARF.OpenAPI;
using ETSI.ARF.OpenAPI.WorldAnalysis;
namespace ETSI.ARF.WorldAnalysis.REST
{
public class RequestBase<T> // where T : Trackable, WorldAnchor, WorldLink
{
static protected WorldAnalysisServer wsServer;
static protected WorldAnalysisClient apiClient;
static protected string token = "ARF_Permission";
// Cache the current list
static public Dictionary<Guid, object> listOfObjects = new Dictionary<Guid, object>();
//
// Helpers
//
static protected void OnReceiveObject<TObj>(Task<TObj> t, object id)
{
if (t.IsCompleted)
{
ResponseObject<TObj> o = (ResponseObject<TObj>)id;
o.responseTime = DateTime.Now;
o.result = t.Result;
Debug.Log($"[REST] Server Response = {o.result.ToString()} (ID={o.transactionId}, Msg={o.message})");
o.callback?.Invoke(o);
}
else Debug.Log("[REST] OpenAPI Timeout!");
}
static protected void OnReceiveListOfObjects<TObj>(Task<List<TObj>> t, object id) where TObj : IModel
{
if (t.IsCompleted)
{
ResponseObject<List<TObj>> o = (ResponseObject<List<TObj>>)id;
o.responseTime = DateTime.Now;
o.result = t.Result;
Debug.Log($"[REST] Server Response = Got {o.result.Count} entrie(s) (ID={o.transactionId}, Msg={o.message})");
listOfObjects.Clear();
foreach (var i in o.result)
{
listOfObjects.Add(i.Uuid, i);
}
o.callback?.Invoke(o);
}
else Debug.Log("[REST] OpenAPI Timeout!");
}
}
}
fileFormatVersion: 2
guid: c6453e5289606a848ae29ddffa0f7288
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
//
// ARF - Augmented Reality Framework (ETSI ISG ARF)
//
// Copyright 2024 ETSI
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Last change: August 2024
//
using ETSI.ARF.WorldAnalysis;
using UnityEngine;
public class WorldAnalysisInfo : MonoBehaviour
{
public WorldAnalysisServer worldAnalysisServer;
//public bool isServerAlive()
//{
// if (worldStorageServer == null) return false;
// return !string.IsNullOrEmpty(ETSI.ARF.WorldStorage.REST.AdminRequest.Ping(worldStorageServer));
//}
//public string GetServerState()
//{
// if (worldStorageServer == null) return "No Server Defined!";
// return ETSI.ARF.WorldStorage.REST.AdminRequest.GetAdminInfo(worldStorageServer);
//}
//public string GetAPIVersion()
//{
// if (worldStorageServer == null) return "Unknown Version!";
// return ETSI.ARF.WorldStorage.REST.AdminRequest.GetVersion(worldStorageServer);
//}
}
fileFormatVersion: 2
guid: 269d5f98c3c478c4983c24ec09d10a70
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System;
using UnityEngine;
using ETSI.ARF.OpenAPI.WorldAnalysis;
using ETSI.ARF.WorldAnalysis;
using static WorldAnalysisInterface;
using System;
using ETSI.ARF.WorldAnalysis.REST;
//Implementation of the WorldAnalysis interface
public class WorldAnalysisREST : MonoBehaviour, WorldAnalysisInterface
{
static protected string token = "ARF_Permission";
public WorldAnalysisServer waServer;
// For sync calls
private WorldAnalysisClient apiClient;
// For async calls
private WorldAnalysisClient apiClientAsync;
#region Unity_Methods
......@@ -14,6 +26,13 @@ public class WorldAnalysisREST : MonoBehaviour, WorldAnalysisInterface
/// </summary>
protected void Awake()
{
// sync
var httpClient = new BasicHTTPClient(waServer.URI);
apiClient = new WorldAnalysisClient(httpClient);
// async
//var httpClientAsync = new UnityWebRequestHttpClient(waServer.URI);
//apiClientAsync = new WorldAnalysisClient(httpClientAsync);
}
/// <summary>
......@@ -32,10 +51,48 @@ public class WorldAnalysisREST : MonoBehaviour, WorldAnalysisInterface
#endregion
#region Test methods
public void CheckServer()
{
string ping = AdminRequest.PingSync(waServer);
string state = AdminRequest.AdminSync(waServer);
string ver = AdminRequest.VersionSync(waServer);
Debug.Log("[REST] WA Ping: " + ping);
Debug.Log("[REST] WA State: " + state);
Debug.Log("[REST] WA Version: " + ver);
}
#region ARF_API
public string GetWebSocketEndpoint()
{
string res = "empty";
SubscriptionSingleRequest param = new SubscriptionSingleRequest();
param.Mode = Mode_WorldAnalysis.DEVICE_TO_TRACKABLES;
param.Target = Guid.Parse("fa8bbe40-8052-11ec-a8a3-0242ac120002"); // test
SubscriptionSingle response = apiClient.SubscribeToPose(token, "1", param);
res = response.WebsocketUrl;
return res;
}
public void PrintCapabilities()
{
string res = "Capabilities:";
Response2 cap = apiClient.GetCapabilities(token, "1");
foreach (var item in cap.Capabilities)
{
res += "\n" + item.TrackableType;
}
Debug.Log("[REST] Capabilities: " + res);
}
#endregion
public AskFrameRateResult SetPoseEstimationFramerate(string token, PoseConfigurationTrackableType type, EncodingInformationStructure encodingInformation, int minimumFramerate)
#region ARF_API
//
// Implementation of the endpoints
//
public AskFrameRateResult SetPoseEstimationFramerate(string token, PoseConfigurationTrackableType type, EncodingInformationStructure encodingInformation, int minimumFramerate)
{
return AskFrameRateResult.NOT_SUPPORTED; ///We cannot set any framerate for tracking on ARKit and ARCore
}
......@@ -47,7 +104,7 @@ public class WorldAnalysisREST : MonoBehaviour, WorldAnalysisInterface
}
public PoseEstimationResult[] GetLastPoses(string token, Guid[] uuids, Mode_WorldAnalysis [] modes, out ETSI.ARF.OpenAPI.WorldAnalysis.Pose[] poses)
public PoseEstimationResult[] GetLastPoses(string token, Guid[] uuids, Mode_WorldAnalysis[] modes, out ETSI.ARF.OpenAPI.WorldAnalysis.Pose[] poses)
{
poses = null;
return null;
......@@ -59,7 +116,7 @@ public class WorldAnalysisREST : MonoBehaviour, WorldAnalysisInterface
return InformationSubscriptionResult.OK;
}
public InformationSubscriptionResult[] SubscribeToPoses(string token, Guid[] uuids, Mode_WorldAnalysis [] modes, PoseCallback callback, ref int validity, out Guid[] subscriptionUUIDs)
public InformationSubscriptionResult[] SubscribeToPoses(string token, Guid[] uuids, Mode_WorldAnalysis[] modes, PoseCallback callback, ref int validity, out Guid[] subscriptionUUIDs)
{
subscriptionUUIDs = null;
return null;
......@@ -90,7 +147,7 @@ public class WorldAnalysisREST : MonoBehaviour, WorldAnalysisInterface
return CapabilityResult.OK;
}
public CapabilityResult GetCapability(string token, Guid uuid, out bool isSupported, out TypeWorldStorage type, out Capability [] capability)
public CapabilityResult GetCapability(string token, Guid uuid, out bool isSupported, out TypeWorldStorage type, out Capability[] capability)
{
isSupported = false;
type = TypeWorldStorage.UNKNOWN;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment