- reworked completly the JNetwork, JSocket interface (had to ifdef out the PSP socket code)
- added 2 menus to wait for connection and wait for deck selection - tested compilation on Qt Linux, Qt Windows and PSP - deactivated everywhere (NETWORK_SUPPORT to activate).
This commit is contained in:
+25
-31
@@ -6,47 +6,41 @@
|
||||
|
||||
#include "JGE.h"
|
||||
#include <string>
|
||||
#include <map>
|
||||
using namespace std;
|
||||
class JSocket;
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include "Threading.h"
|
||||
|
||||
class JNetwork{
|
||||
typedef void(*processCmd)(istream&, ostream&);
|
||||
|
||||
class JNetwork {
|
||||
private:
|
||||
static JNetwork * mInstance;
|
||||
static int connected_to_ap;
|
||||
|
||||
int connected_to_ap;
|
||||
JSocket* socket;
|
||||
boost::mutex sendMutex;
|
||||
boost::mutex receiveMutex;
|
||||
stringstream received;
|
||||
stringstream toSend;
|
||||
static map<string, processCmd> sCommandMap;
|
||||
|
||||
public:
|
||||
static string error;
|
||||
JNetwork();
|
||||
static JNetwork * GetInstance();
|
||||
static void EndInstance();
|
||||
static string serverIP;
|
||||
int receive(char * buffer, int length);
|
||||
int send(char * buffer, int length);
|
||||
~JNetwork();
|
||||
string serverIP;
|
||||
|
||||
int connect(string serverIP = "");
|
||||
static int isConnected();
|
||||
#if defined (WIN32)
|
||||
static int net_thread(void* param);
|
||||
#elif defined (LINUX)
|
||||
static void* net_thread(void* param);
|
||||
#else
|
||||
bool isConnected();
|
||||
static void ThreadProc(void* param);
|
||||
#if !defined (WIN32) && !defined (LINUX)
|
||||
static int connect_to_apctl(int config);
|
||||
#endif
|
||||
bool sendCommand(string command);
|
||||
static void registerCommand(string command, processCmd processCommand, processCmd processResponse);
|
||||
|
||||
private:
|
||||
|
||||
#if defined (WIN32)
|
||||
static DWORD netthread;
|
||||
#elif defined (LINUX)
|
||||
static pthread_t netthread;
|
||||
#else
|
||||
static int netthread;
|
||||
#endif
|
||||
|
||||
boost::thread *mpWorkerThread;
|
||||
};
|
||||
|
||||
#if defined (WIN32)
|
||||
#elif defined (LINUX)
|
||||
#else
|
||||
static int net_thread(SceSize args, void *argp);
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
+34
-15
@@ -2,29 +2,48 @@
|
||||
#define _JSOCKET_H_
|
||||
|
||||
#include <queue>
|
||||
#include "Threading.h"
|
||||
using namespace std;
|
||||
|
||||
//TODO config ?
|
||||
#define SERVER_PORT 20666
|
||||
|
||||
class JSocket{
|
||||
public:
|
||||
queue<char> received_data;
|
||||
queue<char> tosend_data;
|
||||
static JSocket * mInstance;
|
||||
int start_server(const char *szIpAddr);
|
||||
int start_client(const char *szIpAddr);
|
||||
|
||||
typedef enum {
|
||||
// no network available currently from the device
|
||||
NOT_AVAILABLE,
|
||||
// network available but disconnected from another socket
|
||||
DISCONNECTED,
|
||||
// connected with another socket
|
||||
CONNECTED,
|
||||
// some fatal problem
|
||||
FATAL_ERROR,
|
||||
} SOCKET_STATE;
|
||||
|
||||
|
||||
// Server creation
|
||||
JSocket(string ipAddr);
|
||||
// Client creation
|
||||
JSocket();
|
||||
~JSocket();
|
||||
static int connected;
|
||||
|
||||
JSocket* Accept();
|
||||
int Read(char* buff, int size);
|
||||
int Write(char* buff, int size);
|
||||
bool isConnected() { return state == CONNECTED; };
|
||||
void Disconnect();
|
||||
|
||||
private:
|
||||
void init();
|
||||
void readWrite(int sock);
|
||||
#if defined (WIN32) || defined (LINUX)
|
||||
#else
|
||||
int make_socket(uint16_t port);
|
||||
// socket creation when server accepts a connection
|
||||
JSocket(int fd);
|
||||
// convert the socket into non-blocking state
|
||||
bool SetNonBlocking(int sock);
|
||||
// socket handle
|
||||
#ifdef WIN32
|
||||
SOCKET mfd;
|
||||
#elif LINUX
|
||||
int mfd;
|
||||
#endif
|
||||
// socket state
|
||||
SOCKET_STATE state;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user