Commit 85fac656 authored by Ru Cindrea's avatar Ru Cindrea

Initial commit

parents
*.apk filter=lfs diff=lfs merge=lfs -text
*.ipa filter=lfs diff=lfs merge=lfs -text
**/[Ll]ibrary/
**/[Tt]emp/
**/[Oo]bj/
**/[Bb]uild/
**/[Bb]uilds/
**/[Aa]ssets/AssetStoreTools*
**/[Pp]rojectSettings/
**/[Bb]in
.vscode/
**/.DS_Store
#Intellij
**/.idea/
# Autogenerated VS/MD/Consulo solution and project files
ExportedObj/
.consulo/
*.csproj
*.unityproj
*.sln
*.suo
*.tmp
*.user
*.userprefs
*.pidb
*.booproj
*.svd
*.pdb
# Unity3D generated meta files
*.pidb.meta
# Unity3D Generated File On Crash Reports
sysinfo.txt
# Builds
**/target
**/iosBuild/
# Test results
TestResults*.xml InitTestScene*
*.log
# Python related
*.pyc
.cache/
__pycache__/
__pycache__.meta
Assets/AltUnityTester/Bindings/python/altunityrunner.egg-info/
Assets/AltUnityTester/Bindings/python/altunityrunner.egg-info.meta
Assets/AltUnityTester/Bindings/python/dist
Assets/AltUnityTester/Bindings/python/dist.meta
Assets/AltUnityTester/Bindings/python/build.meta
fileFormatVersion: 2
guid: 0fc973c33aa6b441a8caad53406fb6e4
folderAsset: yes
timeCreated: 1507722365
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: ed8724c7e77dc400c9a827628781acd0
folderAsset: yes
timeCreated: 1516878874
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using System.Collections;
using System.Net.Sockets;
using System.IO;
using System.Text;
using System.Threading;
using System;
public interface AltIClientSocketHandlerDelegate
{
// callback, will be NOT be invoked on main thread, so make sure to synchronize in Unity
void ClientSocketHandlerDidReadMessage(AltClientSocketHandler handler, string message);
}
public class AltClientSocketHandler {
protected readonly TcpClient client;
protected readonly string separatorSequence;
protected readonly char [] separatorSequenceChars;
protected readonly Encoding encoding;
protected AltIClientSocketHandlerDelegate clientSocketHandlerDelegate;
public AltClientSocketHandler (TcpClient client,
AltIClientSocketHandlerDelegate clientSocketHandlerDelegate,
string separatorString,
Encoding encoding)
{
this.client = client;
this.encoding = encoding;
this.separatorSequence = separatorString;
this.separatorSequenceChars = separatorString.ToCharArray();
this.clientSocketHandlerDelegate = clientSocketHandlerDelegate;
}
public void Cleanup()
{
if (this.client != null) {
this.client.Close();
}
}
public void SendResponse(string response) {
response = "altstart::" + response + "::altend";
Debug.Log("sending response: " + response);
this.client.Client.Send(encoding.GetBytes(response));
}
public void Run()
{
try {
StringBuilder dataBuffer = new StringBuilder();
while (true)
{
byte [] read_buffer = new byte[256];
int read_length = this.client.Client.Receive(read_buffer);
// append to token
if (read_length > 0)
{
dataBuffer.Append(this.encoding.GetString(read_buffer, 0, read_length));
string data = dataBuffer.ToString();
dataBuffer = new StringBuilder();
string [] tokens = data.Split(this.separatorSequenceChars);
bool ends_with_separator = data.EndsWith(this.separatorSequence);
// all except the last piece
for(int i = 0; i < (tokens.Length - 1); i++)
{
this.clientSocketHandlerDelegate.ClientSocketHandlerDidReadMessage(this, tokens[i]);
}
// for the last piece, if the data ended with separator than this is a full token
// otherwise, its not so append to data buffer
if (ends_with_separator)
{
if (tokens[tokens.Length - 1].Length > 0)
{
this.clientSocketHandlerDelegate.ClientSocketHandlerDidReadMessage(this, tokens[tokens.Length - 1]);
}
}
else
{
dataBuffer.Append(tokens[tokens.Length - 1]);
}
}
}
}
catch (ThreadAbortException exception)
{
Debug.Log ("Thread aborted(" + exception + ")");
}
catch (SocketException exception)
{
Debug.Log ("Socket exception(" + exception + ")");
}
finally
{
this.client.Close();
Debug.Log("AltClientSocketHandler - Client closed");
}
}
}
fileFormatVersion: 2
guid: 1f3e1842b5fcd47a19d2f3595c276809
timeCreated: 1507702564
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public delegate void SendResponse();
public class AltResponseQueue {
private Queue<SendResponse> ResponseQueue = new Queue<SendResponse>();
private object _queueLock = new object();
public void Cycle() {
lock (_queueLock) {
if (ResponseQueue.Count > 0)
ResponseQueue.Dequeue()();
}
}
public void ScheduleResponse(SendResponse newResponse) {
lock (_queueLock) {
if (ResponseQueue.Count < 100)
ResponseQueue.Enqueue(newResponse);
}
}
}
fileFormatVersion: 2
guid: f4a5946d541c84f289438d11c187816c
timeCreated: 1516877872
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using UnityEngine;
using System;
using System.Collections;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Globalization;
using System.Text;
using System.Reflection;
using System.Threading;
public class AltSocketClientThreadHolder {
protected readonly Thread thread;
protected readonly AltClientSocketHandler handler;
public Thread Thread {
get {
return this.thread;
}
}
public AltClientSocketHandler Handler {
get {
return this.handler;
}
}
public AltSocketClientThreadHolder(Thread thread, AltClientSocketHandler handler) {
this.thread = thread;
this.handler = handler;
}
}
public class AltTcpListener : TcpListener {
public AltTcpListener(IPEndPoint localEP) : base(localEP) {
}
public AltTcpListener(IPAddress localaddr, int port) : base(localaddr, port) {
}
public new bool Active {
get { return base.Active; }
}
}
public class AltSocketServer {
protected readonly AltTcpListener listener;
protected readonly AltIClientSocketHandlerDelegate clientSocketHandlerDelegate;
protected readonly string separatorString;
protected readonly Encoding encoding;
protected ArrayList clientHandlerThreads;
protected readonly int portNumber;
protected readonly IPEndPoint localEndPoint;
protected readonly int maxClients;
public int PortNumber {
get {
return this.portNumber;
}
}
public IPEndPoint LocalEndPoint {
get {
return this.localEndPoint;
}
}
public int MaxClients {
get {
return this.maxClients;
}
}
public int ClientCount {
get {
return this.clientHandlerThreads.Count;
}
}
public AltSocketServer(AltIClientSocketHandlerDelegate clientSocketHandlerDelegate,
int portNumber = 13000,
int maxClients = 1,
string separatorString = "\n",
Encoding encoding = null) {
this.portNumber = portNumber;
this.clientSocketHandlerDelegate = clientSocketHandlerDelegate;
this.separatorString = separatorString;
this.encoding = (encoding != null) ? encoding : Encoding.UTF8;
this.clientHandlerThreads = ArrayList.Synchronized(new ArrayList());
this.maxClients = maxClients;
IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
this.localEndPoint = new IPEndPoint(ipAddress, this.portNumber);
this.listener = new AltTcpListener(this.localEndPoint.Address, this.portNumber);
Debug.Log("Created TCP listener.");
}
public void StartListeningForConnections() {
Debug.Log("Began listening for TCP clients.");
this.listener.Start();
this.ListenForConnection();
}
protected void ListenForConnection() {
this.listener.BeginAcceptTcpClient(new AsyncCallback(this.AcceptCallback), this.listener);
}
// NOT on main thread
protected void AcceptCallback(IAsyncResult ar) {
int threadId = Thread.CurrentThread.ManagedThreadId;
Debug.Log("Accept thread id: " + threadId);
TcpListener listener = (TcpListener)ar.AsyncState;
TcpClient client = listener.EndAcceptTcpClient(ar);
Debug.Log("thread id " + threadId + " accepted client " + client.Client.RemoteEndPoint);
Debug.Log("thread id " + threadId + " beginning read from client " + client.Client.RemoteEndPoint);
AltClientSocketHandler clientHandler =
new AltClientSocketHandler(client,
this.clientSocketHandlerDelegate,
this.separatorString,
this.encoding);
Thread clientThread = new Thread(new ThreadStart(clientHandler.Run));
this.clientHandlerThreads.Add(new AltSocketClientThreadHolder(clientThread, clientHandler));
clientThread.Start();
Debug.Log("Client thread started");
if (this.ClientCount < this.maxClients) {
Debug.Log("client handler threads less than max clients. Listening again");
this.ListenForConnection();
} else {
Debug.Log(String.Format("Max number of clients reached ({0}), stopping listening", this.maxClients));
this.StopListeningForConnections();
}
}
public void StopListeningForConnections() {
this.listener.Stop();
Debug.Log("Stopped listening for connections");
}
public void Cleanup() {
StopListeningForConnections();
foreach (AltSocketClientThreadHolder holder in this.clientHandlerThreads) {
Debug.Log("calling stop on thread " + holder.Thread.ManagedThreadId);
holder.Handler.Cleanup();
Debug.Log("Calling thread abort on thread: " + holder.Thread.ManagedThreadId);
holder.Thread.Abort();
}
this.clientHandlerThreads = null;
}
public bool IsStarted() {
return listener != null && listener.Active;
}
}
fileFormatVersion: 2
guid: 83f4713fae5af4672a66f0cbe6679fe9
timeCreated: 1507702564
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 64b015cfc961e445c926dd271792d19f
folderAsset: yes
timeCreated: 1516878881
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Events;
public class FindObjectByNameCommand : UnityEvent<string, AltClientSocketHandler> { }
public class FindObjectWhereNameContainsCommand : UnityEvent<string, AltClientSocketHandler> { }
public class FindObjectByComponentCommand : UnityEvent<string, AltClientSocketHandler> { }
public class FindObjectsByNameCommand : UnityEvent<string, AltClientSocketHandler> { }
public class FindObjectsWhereNameContainsCommand : UnityEvent<string, AltClientSocketHandler> { }
public class FindObjectsByComponentCommand : UnityEvent<string, AltClientSocketHandler> { }
public class GetCurrentSceneCommand : UnityEvent<AltClientSocketHandler> { }
public class GetAllObjectsCommand : UnityEvent<AltClientSocketHandler> { }
public class TapCommand : UnityEvent<string, AltClientSocketHandler> { }
public class GetComponentPropertyCommand : UnityEvent<string, string, AltClientSocketHandler> {}
public class SetComponentPropertyCommand : UnityEvent<string, string, string, AltClientSocketHandler> {}
public class CallComponentMethodCommand: UnityEvent<string, string, AltClientSocketHandler> {}
public class GetTextCommand: UnityEvent<string, AltClientSocketHandler>{}
public class CloseConnectionCommand : UnityEvent<AltClientSocketHandler> { }
public class UnknownStringCommand : UnityEvent<AltClientSocketHandler> { }
public class AltUnityEvents {
public UnityEvent ResponseReceived;
public FindObjectByNameCommand FindObjectByName;
public FindObjectWhereNameContainsCommand FindObjectWhereNameContains;
public FindObjectByComponentCommand FindObjectByComponent;
public FindObjectsByNameCommand FindObjectsByName;
public FindObjectsWhereNameContainsCommand FindObjectsWhereNameContains;
public FindObjectsByComponentCommand FindObjectsByComponent;
public GetCurrentSceneCommand GetCurrentScene;
public GetAllObjectsCommand GetAllObjects;
public TapCommand Tap;
public GetComponentPropertyCommand GetComponentProperty;
public SetComponentPropertyCommand SetComponentProperty;
public CallComponentMethodCommand CallComponentMethod;
public GetTextCommand GetText;
public CloseConnectionCommand CloseConnection;
public UnknownStringCommand UnknownString;
// We are a singleton!
private static AltUnityEvents _instance;
public static AltUnityEvents Instance {
get {
if (_instance == null) {
_instance = new AltUnityEvents();
_instance.FindObjectByName = new FindObjectByNameCommand();
_instance.FindObjectWhereNameContains = new FindObjectWhereNameContainsCommand();
_instance.FindObjectByComponent = new FindObjectByComponentCommand();
_instance.FindObjectsByName = new FindObjectsByNameCommand();
_instance.FindObjectsWhereNameContains = new FindObjectsWhereNameContainsCommand();
_instance.FindObjectsByComponent = new FindObjectsByComponentCommand();
_instance.GetAllObjects = new GetAllObjectsCommand();
_instance.GetCurrentScene = new GetCurrentSceneCommand();
_instance.Tap = new TapCommand();
_instance.GetComponentProperty = new GetComponentPropertyCommand();
_instance.SetComponentProperty = new SetComponentPropertyCommand();
_instance.CallComponentMethod = new CallComponentMethodCommand();
_instance.GetText = new GetTextCommand();
_instance.UnknownString = new UnknownStringCommand();
_instance.ResponseReceived = new UnityEvent();
_instance.CloseConnection = new CloseConnectionCommand();
}
return _instance;
}
}
}
\ No newline at end of file
fileFormatVersion: 2
guid: 53c1ef4cdc3a5441aaeb481f1eed0685
timeCreated: 1516857363
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public struct AltUnityObject {
public string name;
public int id;
public int x;
public int y;
public int mobileY;
public string text;
public string type;
public bool enabled;
public AltUnityObject(string name, int id=0, int x=0, int y=0, int mobileY=0, string text="", string type="", bool enabled = true) {
this.name = name;
this.id = id;
this.x = x;
this.y = y;
this.mobileY = mobileY;
this.text = text;
this.type = type;
this.enabled = enabled;
}
}
fileFormatVersion: 2
guid: fe75b462096664ca89da36caea8cacdb
timeCreated: 1516878909
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

using System.Collections.Generic;
public struct AltUnityObjectAction {
public string component;
public string method;
// public Dictionary<string, string> parameters;
public string parameters;
public AltUnityObjectAction(string componentName = "", string methodName = "", string parameters = null) {
this.component = componentName;
this.method = methodName;
this.parameters = parameters;
}
}
fileFormatVersion: 2
guid: b0674894021154b2884d5894d4bccf69
timeCreated: 1518694471
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

using System.Collections.Generic;
public struct AltUnityObjectProperty {
public string component;
public string property;
public AltUnityObjectProperty(string componentName = "", string propertyName = "") {
this.component = componentName;
this.property = propertyName;
}
}
fileFormatVersion: 2
guid: cd59071dbb33a40bfbfcaf97fe45b0bb
timeCreated: 1518696264
licenseType: Pro
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
This diff is collapsed.
fileFormatVersion: 2
guid: d64f576b163a84c53be56deef13c731f
timeCreated: 1507702564
licenseType: Pro
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: fffc16dc34d9d4bce977a684784fc5d6
folderAsset: yes
timeCreated: 1516344002
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: 95d92e49bc55c4431bb0902506525aac
folderAsset: yes
timeCreated: 1513589494
licenseType: Pro
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:
fileFormatVersion: 2
guid: a814c9275d3584d0081fc105e591bdad
folderAsset: yes
timeCreated: 1519132927
licenseType: Pro
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
from runner import AltElement, AltrunUnityDriver
\ No newline at end of file