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

Scripts reviewed and updated for new WS Editor.

Extended some functionalities/inheritances.
parent 9188d5e4
No related branches found
No related tags found
1 merge request!6Scripts reviewed and updated for new WS Editor.
Showing
with 159 additions and 53 deletions
//
// ARF - Augmented Reality Framework (ETSI ISG ARF)
//
// Copyright 2022 ETSI
// 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.
......
//
// ARF - Augmented Reality Framework (ETSI ISG ARF)
//
// Copyright 2022 ETSI
// 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.
......
//
// ARF - Augmented Reality Framework (ETSI ISG ARF)
//
// Copyright 2022 ETSI
// 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.
......
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace ETSI.ARF.OpenAPI
{
/// <summary>
/// Simple class to debug the requests
/// </summary>
public class BaseClient
{
static public bool EnableClientLog = false;
public string lastJsonText;
public long lastPayload;
protected void _prepareRequest(ETSI.ARF.OpenAPI.IHttpClient client, System.Net.Http.HttpRequestMessage request, string url)
{
if (EnableClientLog)
{
Debug.Log("[REST][URL] Send request: " + client.BaseAddress + url);
Debug.Log("[REST][URL] Send request: " + request);
}
}
protected void _processResponse(ETSI.ARF.OpenAPI.IHttpClient client, System.Net.Http.HttpResponseMessage response)
{
lastJsonText = response.Content.ReadAsStringAsync().Result.ToString();
lastPayload = response.Content.Headers.ContentLength.Value;
var status_ = (int)response.StatusCode;
if (EnableClientLog)
{
Debug.Log("[REST][Data] Status: " + status_ + " Response: " + client.BaseAddress + " Len: " + lastPayload + " JSON: " + lastJsonText);
}
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 2e0af995ecbb4654a9191f8157a1cf0e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
......@@ -8,6 +8,23 @@ namespace ETSI.ARF.OpenAPI.WorldStorage
public interface IModel
{
public System.Guid UUID { get; set; }
public string ToJson();
}
// Class to monitor the server
public class Server : IModel
{
public System.Guid UUID { get; set; }
public string Name { get; set; }
public Server(string name)
{
UUID = Guid.Empty;
Name = name;
}
public string ToJson() { return JsonUtility.ToJson(this); }
}
//
......@@ -20,6 +37,8 @@ namespace ETSI.ARF.OpenAPI.WorldStorage
UUID = Guid.NewGuid();
Name = name;
}
public string ToJson() { return JsonUtility.ToJson(this); }
}
public partial class WorldAnchor : IModel
......@@ -29,6 +48,8 @@ namespace ETSI.ARF.OpenAPI.WorldStorage
UUID = Guid.NewGuid();
Name = name;
}
public string ToJson() { return JsonUtility.ToJson(this); }
}
public partial class WorldLink : IModel
......@@ -37,5 +58,7 @@ namespace ETSI.ARF.OpenAPI.WorldStorage
{
UUID = Guid.NewGuid();
}
public string ToJson() { return JsonUtility.ToJson(this); }
}
}
\ No newline at end of file
......@@ -15,13 +15,26 @@ using UnityEngine;
namespace ETSI.ARF.OpenAPI
{
public class ResponseObject<T>
public class CancelToken
{
protected CancellationTokenSource tokenSource;
protected CancellationToken ct;
public CancellationToken cancellationToken { get => ct; }
public void Cancel()
{
tokenSource.Cancel();
}
}
public class ResponseObject<T> : CancelToken
{
// Management stuffs
static int ID = 0;
public int transactionId = 0;
public string message = ""; // custom message, type of data...
// Time monitoring
public TimeSpan DeltaTime { get => responseTime - requestTime; }
public DateTime requestTime;
......@@ -30,34 +43,23 @@ namespace ETSI.ARF.OpenAPI
// Incoming data
public T result;
public int payload; // size of data
//public string result = ""; // text result
//public object data = null; // custom result
// Callback
public Action<ResponseObject<T>> callback;
// Task cancelllation
public CancellationToken cancellationToken { get => ct; }
private CancellationTokenSource tokenSource;
private CancellationToken ct;
public ResponseObject(string msg, Action<ResponseObject<T>> func = null)
{
requestTime = DateTime.Now;
transactionId = ++ID;
message = msg;
callback = func;
transactionId = ++ID;
tokenSource = new CancellationTokenSource();
ct = tokenSource.Token;
}
public void Cancel()
{
tokenSource.Cancel();
}
}
}
\ No newline at end of file
//
// 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: June 2024
//
// Depends on UniTask to support cancellation token and GetAwaiter: https://github.com/Cysharp/UniTask
// Otherwise, the code can be adapted using https://gist.github.com/krzys-h/9062552e33dd7bd7fe4a6c12db109a1a
......
//
// 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.Collections;
using System.Collections.Generic;
using UnityEngine;
......@@ -25,28 +5,24 @@ using UnityEngine.Networking;
namespace ETSI.ARF.OpenAPI.WorldStorage
{
// SylR
public partial class WorldStorageClient
/// <summary>
/// Catch the pre/pos request methods from the autogenerated classes
/// </summary>
public partial class WorldStorageClient : BaseClient
{
public string lastJsonText;
public long lastPayload;
partial void PrepareRequest(IHttpClient client, System.Net.Http.HttpRequestMessage request, string url)
partial void PrepareRequest(ETSI.ARF.OpenAPI.IHttpClient client, System.Net.Http.HttpRequestMessage request, string url)
{
// If needed to make some special things !!!
_prepareRequest(client, request, url);
}
partial void PrepareRequest(IHttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder)
partial void PrepareRequest(ETSI.ARF.OpenAPI.IHttpClient client, System.Net.Http.HttpRequestMessage request, System.Text.StringBuilder urlBuilder)
{
// do something...
}
partial void ProcessResponse(IHttpClient client, System.Net.Http.HttpResponseMessage response)
partial void ProcessResponse(ETSI.ARF.OpenAPI.IHttpClient client, System.Net.Http.HttpResponseMessage response)
{
lastJsonText = response.Content.ReadAsStringAsync().Result.ToString();
lastPayload = response.Content.Headers.ContentLength.Value;
// If needed to make some special things !!!
_processResponse(client, response);
}
}
}
\ No newline at end of file
//
// ARF - Augmented Reality Framework (ETSI ISG ARF)
//
// Copyright 2022 ETSI
// 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.
......
using ETSI.ARF.OpenAPI.WorldStorage;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class WorldStorageUnityHelper
{
/// <summary>
/// Convert a float array of length 16 to a Matrix
/// </summary>
/// <param name="matrix">the values to convert</param>
/// <returns>Converted Unity Matrix</returns>
public static ETSI.ARF.OpenAPI.WorldStorage.Transform3D ConvertUnityToETSIARFTransform3D(Matrix4x4 value)
{
Transform3D result = new Transform3D
{
value.m00, value.m01, value.m02, value.m03,
value.m10, value.m11, value.m12, value.m13,
value.m20, value.m21, value.m22, value.m23,
value.m30, value.m31, value.m32, value.m33,
};
return result;
}
}
fileFormatVersion: 2
guid: dc92958843a03644e8524fd2312c3f42
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: a94d6effd437d7842907e9a5cfd2732f
guid: 7cf3a1fe1b3964e41afa78147db793b0
DefaultImporter:
externalObjects: {}
userData:
......
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