Skip to content

Commit 36effb6

Browse files
committed
Merge pull request #20 from jameslennon321/master
Java wrapper
2 parents 8f386d4 + 2b65f14 commit 36effb6

41 files changed

Lines changed: 5989 additions & 20 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎Documentation/protocol.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ These JSON objects are referenced in the above protocol specification.
230230
},
231231
"id":# /* The ID of this control */
232232
"img":<base64> /* Optional: an image (.png) to skin the control with */
233+
/* if this control is a button, it has a "btntype" value (0=>A, 1=>B, 2=>X, 3=>Y) */
233234
}
234235
```
235236

‎ServerAPI/Build/libopenpad.jnilib‎

378 KB
Binary file not shown.

‎ServerAPI/Example/DebugGame.cpp‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,21 @@ void DebugGame::onStart(){
1919
printf("Game started\n");
2020
}
2121

22-
bool DebugGame::canJoin(Client *cli, string &why){
22+
bool DebugGame::canJoin(Client *cli){
2323
if(cli->clientID->firstname == "Christian"){
24-
why = "Get outta here Christian";
2524
return false;
2625
}else{
2726
return true;
2827
}
2928
}
3029

30+
string DebugGame::whyIsBanned(openpad::Client *cli){
31+
if(cli->getID().firstname == "Christian"){
32+
return "Get outta here Christian";
33+
}
34+
return "";
35+
}
36+
3137
string DebugGame::getName(){
3238
return "Debug Game";
3339
}
@@ -54,11 +60,11 @@ void DebugGame::onJoin(Client *cli){
5460

5561
PadConfig DebugGame::getDefaultControls(){
5662
PadConfig conf;
57-
ButtonControl *btn1 = new ButtonControl(.5, .5, .25, 0, BUTTON_A);
58-
DPadControl *dpad = new DPadControl(0, 0, .2, 1);
63+
ButtonControl *btn1 = new ButtonControl(.2, .2, .1, 0, BUTTON_A);
64+
DPadControl *dpad = new DPadControl(.5, .75, .2, 1);
5965

60-
conf.controls.push_back(btn1);
61-
conf.controls.push_back(dpad);
66+
conf.addControl(btn1);
67+
conf.addControl(dpad);
6268

6369
return conf;
6470
}
@@ -69,5 +75,5 @@ void DebugGame::onDisconnect(Client *cli){
6975

7076
void DebugGame::onPadUpdate(Client *cli, PadUpdateObject update){
7177
//Player controller action
72-
printf("Player did something with controll %d\n", update.controlid);
78+
printf("Player did something with control %d\n", update.controlid);
7379
}

‎ServerAPI/Example/DebugGame.h‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ class DebugGame: public ServerHandler {
2222

2323
//Override Methods
2424
void onStart();
25-
bool canJoin(Client* cli, string& why);
25+
virtual bool canJoin(Client* cli);
26+
virtual string whyIsBanned(Client* cli);
2627
string getName();
2728
string getDesc();
2829
int getFilledSlots();
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* ----------------------------------------------------------------------------
2+
* This file was automatically generated by SWIG (http://www.swig.org).
3+
* Version 3.0.2
4+
*
5+
* Do not make changes to this file unless you know what you are doing--modify
6+
* the SWIG interface file instead.
7+
* ----------------------------------------------------------------------------- */
8+
9+
package com.openpad.server;
10+
11+
public class ButtonControl extends ControlObject {
12+
private long swigCPtr;
13+
14+
protected ButtonControl(long cPtr, boolean cMemoryOwn) {
15+
super(openpadJNI.ButtonControl_SWIGUpcast(cPtr), cMemoryOwn);
16+
swigCPtr = cPtr;
17+
}
18+
19+
protected static long getCPtr(ButtonControl obj) {
20+
return (obj == null) ? 0 : obj.swigCPtr;
21+
}
22+
23+
protected void finalize() {
24+
delete();
25+
}
26+
27+
public synchronized void delete() {
28+
if (swigCPtr != 0) {
29+
if (swigCMemOwn) {
30+
swigCMemOwn = false;
31+
openpadJNI.delete_ButtonControl(swigCPtr);
32+
}
33+
swigCPtr = 0;
34+
}
35+
super.delete();
36+
}
37+
38+
public ButtonControl(float x, float y, float w, int controlid, int btntype) {
39+
this(openpadJNI.new_ButtonControl(x, y, w, controlid, btntype), true);
40+
}
41+
42+
public SWIGTYPE_p_Value serializeJSON(SWIGTYPE_p_Document__AllocatorType a) {
43+
return new SWIGTYPE_p_Value(openpadJNI.ButtonControl_serializeJSON(swigCPtr, this, SWIGTYPE_p_Document__AllocatorType.getCPtr(a)), false);
44+
}
45+
46+
public void setBtntype(int value) {
47+
openpadJNI.ButtonControl_btntype_set(swigCPtr, this, value);
48+
}
49+
50+
public int getBtntype() {
51+
return openpadJNI.ButtonControl_btntype_get(swigCPtr, this);
52+
}
53+
54+
}

‎ServerAPI/Java Wrapper/Client.java‎

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
/* ----------------------------------------------------------------------------
2+
* This file was automatically generated by SWIG (http://www.swig.org).
3+
* Version 3.0.2
4+
*
5+
* Do not make changes to this file unless you know what you are doing--modify
6+
* the SWIG interface file instead.
7+
* ----------------------------------------------------------------------------- */
8+
9+
package com.openpad.server;
10+
11+
public class Client {
12+
private long swigCPtr;
13+
protected boolean swigCMemOwn;
14+
15+
protected Client(long cPtr, boolean cMemoryOwn) {
16+
swigCMemOwn = cMemoryOwn;
17+
swigCPtr = cPtr;
18+
}
19+
20+
protected static long getCPtr(Client obj) {
21+
return (obj == null) ? 0 : obj.swigCPtr;
22+
}
23+
24+
protected void finalize() {
25+
delete();
26+
}
27+
28+
public synchronized void delete() {
29+
if (swigCPtr != 0) {
30+
if (swigCMemOwn) {
31+
swigCMemOwn = false;
32+
openpadJNI.delete_Client(swigCPtr);
33+
}
34+
swigCPtr = 0;
35+
}
36+
}
37+
38+
public void setSocketID(int value) {
39+
openpadJNI.Client_socketID_set(swigCPtr, this, value);
40+
}
41+
42+
public int getSocketID() {
43+
return openpadJNI.Client_socketID_get(swigCPtr, this);
44+
}
45+
46+
public void setSock(SWIGTYPE_p_TCPSocket value) {
47+
openpadJNI.Client_sock_set(swigCPtr, this, SWIGTYPE_p_TCPSocket.getCPtr(value));
48+
}
49+
50+
public SWIGTYPE_p_TCPSocket getSock() {
51+
long cPtr = openpadJNI.Client_sock_get(swigCPtr, this);
52+
return (cPtr == 0) ? null : new SWIGTYPE_p_TCPSocket(cPtr, false);
53+
}
54+
55+
public void setServ(Server value) {
56+
openpadJNI.Client_serv_set(swigCPtr, this, Server.getCPtr(value), value);
57+
}
58+
59+
public Server getServ() {
60+
long cPtr = openpadJNI.Client_serv_get(swigCPtr, this);
61+
return (cPtr == 0) ? null : new Server(cPtr, false);
62+
}
63+
64+
public void setUserData(SWIGTYPE_p_void value) {
65+
openpadJNI.Client_userData_set(swigCPtr, this, SWIGTYPE_p_void.getCPtr(value));
66+
}
67+
68+
public SWIGTYPE_p_void getUserData() {
69+
long cPtr = openpadJNI.Client_userData_get(swigCPtr, this);
70+
return (cPtr == 0) ? null : new SWIGTYPE_p_void(cPtr, false);
71+
}
72+
73+
public void setShouldRun(boolean value) {
74+
openpadJNI.Client_shouldRun_set(swigCPtr, this, value);
75+
}
76+
77+
public boolean getShouldRun() {
78+
return openpadJNI.Client_shouldRun_get(swigCPtr, this);
79+
}
80+
81+
public void setHasJoined(boolean value) {
82+
openpadJNI.Client_hasJoined_set(swigCPtr, this, value);
83+
}
84+
85+
public boolean getHasJoined() {
86+
return openpadJNI.Client_hasJoined_get(swigCPtr, this);
87+
}
88+
89+
public void setClientID(SWIGTYPE_p_shared_ptrT_openpad__IDObject_t value) {
90+
openpadJNI.Client_clientID_set(swigCPtr, this, SWIGTYPE_p_shared_ptrT_openpad__IDObject_t.getCPtr(value));
91+
}
92+
93+
public SWIGTYPE_p_shared_ptrT_openpad__IDObject_t getClientID() {
94+
long cPtr = openpadJNI.Client_clientID_get(swigCPtr, this);
95+
return (cPtr == 0) ? null : new SWIGTYPE_p_shared_ptrT_openpad__IDObject_t(cPtr, false);
96+
}
97+
98+
public Client(SWIGTYPE_p_TCPSocket sock, int sockID, Server serv) {
99+
this(openpadJNI.new_Client(SWIGTYPE_p_TCPSocket.getCPtr(sock), sockID, Server.getCPtr(serv), serv), true);
100+
}
101+
102+
public void send(Serializable s) {
103+
openpadJNI.Client_send(swigCPtr, this, Serializable.getCPtr(s), s);
104+
}
105+
106+
public void run() {
107+
openpadJNI.Client_run(swigCPtr, this);
108+
}
109+
110+
public IDObject getID() {
111+
return new IDObject(openpadJNI.Client_getID(swigCPtr, this), false);
112+
}
113+
114+
public void setControls(ControlObject ctrls) {
115+
openpadJNI.Client_setControls(swigCPtr, this, ControlObject.getCPtr(ctrls), ctrls);
116+
}
117+
118+
public void disconnect(SWIGTYPE_p_std__string msg) {
119+
openpadJNI.Client_disconnect(swigCPtr, this, SWIGTYPE_p_std__string.getCPtr(msg));
120+
}
121+
122+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
/* ----------------------------------------------------------------------------
2+
* This file was automatically generated by SWIG (http://www.swig.org).
3+
* Version 3.0.2
4+
*
5+
* Do not make changes to this file unless you know what you are doing--modify
6+
* the SWIG interface file instead.
7+
* ----------------------------------------------------------------------------- */
8+
9+
package com.openpad.server;
10+
11+
public class ControlObject extends Serializable {
12+
private long swigCPtr;
13+
14+
protected ControlObject(long cPtr, boolean cMemoryOwn) {
15+
super(openpadJNI.ControlObject_SWIGUpcast(cPtr), cMemoryOwn);
16+
swigCPtr = cPtr;
17+
}
18+
19+
protected static long getCPtr(ControlObject obj) {
20+
return (obj == null) ? 0 : obj.swigCPtr;
21+
}
22+
23+
protected void finalize() {
24+
delete();
25+
}
26+
27+
public synchronized void delete() {
28+
if (swigCPtr != 0) {
29+
if (swigCMemOwn) {
30+
swigCMemOwn = false;
31+
openpadJNI.delete_ControlObject(swigCPtr);
32+
}
33+
swigCPtr = 0;
34+
}
35+
super.delete();
36+
}
37+
38+
public SWIGTYPE_p_Value serializeJSON(SWIGTYPE_p_Document__AllocatorType a) {
39+
return new SWIGTYPE_p_Value(openpadJNI.ControlObject_serializeJSON(swigCPtr, this, SWIGTYPE_p_Document__AllocatorType.getCPtr(a)), false);
40+
}
41+
42+
public boolean parseJSON(SWIGTYPE_p_Value v) {
43+
return openpadJNI.ControlObject_parseJSON(swigCPtr, this, SWIGTYPE_p_Value.getCPtr(v));
44+
}
45+
46+
public void setType(int value) {
47+
openpadJNI.ControlObject_type_set(swigCPtr, this, value);
48+
}
49+
50+
public int getType() {
51+
return openpadJNI.ControlObject_type_get(swigCPtr, this);
52+
}
53+
54+
public void setFrame(FrameObject value) {
55+
openpadJNI.ControlObject_frame_set(swigCPtr, this, FrameObject.getCPtr(value), value);
56+
}
57+
58+
public FrameObject getFrame() {
59+
long cPtr = openpadJNI.ControlObject_frame_get(swigCPtr, this);
60+
return (cPtr == 0) ? null : new FrameObject(cPtr, false);
61+
}
62+
63+
public void setControlID(int value) {
64+
openpadJNI.ControlObject_controlID_set(swigCPtr, this, value);
65+
}
66+
67+
public int getControlID() {
68+
return openpadJNI.ControlObject_controlID_get(swigCPtr, this);
69+
}
70+
71+
public void setImg(String value) {
72+
openpadJNI.ControlObject_img_set(swigCPtr, this, value);
73+
}
74+
75+
public String getImg() {
76+
return openpadJNI.ControlObject_img_get(swigCPtr, this);
77+
}
78+
79+
public ControlObject() {
80+
this(openpadJNI.new_ControlObject(), true);
81+
}
82+
83+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* ----------------------------------------------------------------------------
2+
* This file was automatically generated by SWIG (http://www.swig.org).
3+
* Version 3.0.2
4+
*
5+
* Do not make changes to this file unless you know what you are doing--modify
6+
* the SWIG interface file instead.
7+
* ----------------------------------------------------------------------------- */
8+
9+
package com.openpad.server;
10+
11+
public class DPadControl extends ControlObject {
12+
private long swigCPtr;
13+
14+
protected DPadControl(long cPtr, boolean cMemoryOwn) {
15+
super(openpadJNI.DPadControl_SWIGUpcast(cPtr), cMemoryOwn);
16+
swigCPtr = cPtr;
17+
}
18+
19+
protected static long getCPtr(DPadControl obj) {
20+
return (obj == null) ? 0 : obj.swigCPtr;
21+
}
22+
23+
protected void finalize() {
24+
delete();
25+
}
26+
27+
public synchronized void delete() {
28+
if (swigCPtr != 0) {
29+
if (swigCMemOwn) {
30+
swigCMemOwn = false;
31+
openpadJNI.delete_DPadControl(swigCPtr);
32+
}
33+
swigCPtr = 0;
34+
}
35+
super.delete();
36+
}
37+
38+
public DPadControl(float x, float y, float w, int controlid) {
39+
this(openpadJNI.new_DPadControl(x, y, w, controlid), true);
40+
}
41+
42+
}

0 commit comments

Comments
 (0)