Skip to content

Commit

Permalink
sync win
Browse files Browse the repository at this point in the history
  • Loading branch information
Shaji Khan committed Nov 15, 2024
1 parent 804e3d6 commit 234efd4
Show file tree
Hide file tree
Showing 43 changed files with 292 additions and 14 deletions.
Binary file modified FileWriter.o
Binary file not shown.
Binary file modified LockFreeQueue.o
Binary file not shown.
10 changes: 5 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#~ GTKMM=`pkg-config --cflags --libs gtkmm-4.0`

TARGET=linux
#TARGET=win32
TARGET=win32

VERSION=`git rev-list --count HEAD`

Expand All @@ -27,10 +27,10 @@ OPUS=`x86_64-w64-mingw32-pkg-config --cflags --libs opus opusfile`
LAME=-llibmp3lame
X11=
GLIB=`mingw64-pkg-config glib-2.0 --libs --cflags`
OPTIMIZE=-fast
OPTIMIZE=-Ofast
CC=x86_64-w64-mingw32-gcc -g -mwindows -mconsole
CPP=x86_64-w64-mingw32-g++ -std=c++17 -g -mwindows -mconsole
DLFCN=-llibdl
DLFCN=-llibdl -lws2_32 -lwsock32
endif
all: amprack

Expand Down Expand Up @@ -107,8 +107,8 @@ win32-release:
sync.o: sync.cc sync.h server.o
$(CPP) -c sync.cc $(GTK)

server.o: server.cc server.h client.cc client.h
$(CPP) -c server.cc client.cc $(GTK) -Wall
server.o: server.cc server.h client.cc client.h winserver.cc winserver.h
$(CPP) -c winserver.cc server.cc client.cc $(GTK) -Wall

echo-client: echo-client.cc server.o
$(CPP) -o echo-client echo-client.cc client.cc $(GTK) -Wall
Expand Down
Binary file modified Plugin.o
Binary file not shown.
Binary file modified PluginControl.o
Binary file not shown.
Binary file modified SharedLibrary.o
Binary file not shown.
Binary file modified a.out
Binary file not shown.
Binary file removed amprack
Binary file not shown.
Binary file modified amprack.exe
Binary file not shown.
Binary file modified cairo.o
Binary file not shown.
2 changes: 2 additions & 0 deletions client.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#ifdef __linux__
#include "client.h"

Client::Client(string host, int port) {
Expand Down Expand Up @@ -189,3 +190,4 @@ Client::get_response() {
OUT
return true;
}
#endif
Binary file modified client.o
Binary file not shown.
8 changes: 4 additions & 4 deletions defs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
#define DEFS_H

#define null NULL
#define true TRUE
#define false FALSE
//~ #define true TRUE
//~ #define false FALSE
#define oooooh -1
#define File FILE
#define reutern return
Expand All @@ -13,8 +13,8 @@
#define vodi void
#define MinusOne -1
#define simply
#define yes true
#define no false
//~ #define yes true
//~ #define no false
#define brake break
#define wtf LOGD
#define GW (GtkWidget *)
Expand Down
Binary file modified dictionary.o
Binary file not shown.
Binary file modified engine.o
Binary file not shown.
Binary file modified jack.o
Binary file not shown.
Binary file modified knob.o
Binary file not shown.
Binary file modified log.o
Binary file not shown.
Binary file modified lv2_ext.o
Binary file not shown.
Binary file modified main.o
Binary file not shown.
Binary file modified mem.o
Binary file not shown.
Binary file modified objects.o
Binary file not shown.
Binary file modified pango.o
Binary file not shown.
Binary file modified pluginui.o
Binary file not shown.
Binary file modified presets.o
Binary file not shown.
Binary file modified process.o
Binary file not shown.
Binary file modified rack.o
Binary file not shown.
6 changes: 5 additions & 1 deletion server.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "server.h"
#ifdef __linux__
#include "sync.h"

#include "server.h"

Server::Server() {
IN
// setup variables
Expand Down Expand Up @@ -209,3 +211,5 @@ Server::send_response(int client, string response) {
//~ close_socket ();
return true;
}

#endif
1 change: 1 addition & 0 deletions server.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,4 @@ class Server {
int buflen_;
char* buf_;
};

Binary file modified server.o
Binary file not shown.
Binary file modified settings.o
Binary file not shown.
Binary file modified snd.o
Binary file not shown.
3 changes: 3 additions & 0 deletions sync.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# include "sync.h"

# ifdef __linux__
# include "net.cc"
#endif

void sync_send (Sync * sync) {
IN
Expand Down
12 changes: 9 additions & 3 deletions sync.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@
# define __SYNC_H

# include "rack.h"
# include "defs.h"
# include "server.h"
//# include "defs.h"

# ifdef __linux__
# include "server.h"
# include "client.h"
# else
# include "winserver.h"
# endif

# include "util.h"
# include "client.h"
# include "random"

class Sync {
Expand Down
Binary file modified sync.o
Binary file not shown.
Binary file modified upwaker.o
Binary file not shown.
Binary file modified util.o
Binary file not shown.
2 changes: 1 addition & 1 deletion version.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define VERSION 155
#define VERSION 156
Binary file modified vringbuffer.o
Binary file not shown.
91 changes: 91 additions & 0 deletions win_net.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
#include <boost/asio.hpp>
#include <boost/bind/bind.hpp>
#include <boost/optional.hpp>
#include <iomanip>
#include <iostream>

namespace asio = boost::asio;
using asio::ip::tcp;
using namespace std::chrono_literals;
using boost::system::error_code;

void read_session(tcp::socket sock) {
std::cout << "Connection established " << sock.remote_endpoint() << std::endl;

std::array<char, 1000> buffer;

for (error_code ec;;) {
size_t n = sock.read_some(asio::buffer(buffer), ec);
std::cout << "Received " << n << " " << quoted(std::string(buffer.data(), n)) << " (" << ec.message() << ")" << std::endl;

if (ec.failed())
break;
}

std::cout << "Connection closed" << std::endl;
}

class TheServer {
public:
TheServer(asio::any_io_executor ex, uint16_t port) //
: m_Acceptor{ex, tcp::endpoint{tcp::v4(), port}} //
{
m_Acceptor.set_option(tcp::acceptor::reuse_address(true));
do_accept();
}

private:
void do_accept() {
m_Acceptor.async_accept([this](error_code ec, tcp::socket s) {
if (!ec) {
std::thread(read_session, std::move(s)).detach();
do_accept(); // and immediately accept new connection(s)
} else {
std::cout << "Connection error (" << ec.message() << ")" << std::endl;
}
});
}

tcp::acceptor m_Acceptor;
};

constexpr uint16_t s_port = 1900;

void run_server() {
asio::thread_pool ioc(1);
TheServer server(ioc.get_executor(), s_port);

std::cout << "Press Enter to quit" << std::endl;
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');

ioc.stop();
ioc.join();
}

void run_client() {
std::cout << "Starting client" << std::endl;

asio::io_service ioc(1);

try {
tcp::socket m_Socket(ioc);
m_Socket.connect({{}, s_port});

std::cout << "Client connected" << std::endl;

for (std::string msg : {"Hello World", "Bye World"}) {
write(m_Socket, asio::buffer(msg));
std::this_thread::sleep_for(100ms);
}
} catch (std::exception& e) {
std::cerr << "Exception: " << e.what() << "\n";
}
}

int main(int argc, char**) {
if (argc>1)
run_server();
else
run_client();
}

73 changes: 73 additions & 0 deletions winserver.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#include "winserver.h"

asio::thread_pool ioc(1);


void read_session(tcp::socket sock) {
std::cout << "Connection established " << sock.remote_endpoint() << std::endl;

std::array<char, 1000> buffer;

for (boost::system::error_code ec;;) {
size_t n = sock.read_some(asio::buffer(buffer), ec);
std::cout << "Received " << n << " " << quoted(std::string(buffer.data(), n)) << " (" << ec.message() << ")" << std::endl;

if (ec.failed())
break;
}

std::cout << "Connection closed" << std::endl;
}

void Client::create () {
IN

OUT
}

Client::Client (string host, int port) {
IN
host_ = host ;
port_ = port ;
OUT
}

std::string Client::send_preset (json j) {
IN
asio::io_service ioc(1);

try {
tcp::socket m_Socket(ioc);
///| todo enter hostname here
m_Socket.connect({{}, port_});

std::cout << "Client connected" << std::endl;

///| todo: add extra } here
std::string msg = j.dump ().append (string ("}")) ;
write(m_Socket, asio::buffer(msg));
std::this_thread::sleep_for(100ms);
} catch (std::exception& e) {
std::cerr << "Exception: " << e.what() << "\n";
}

return string ("");
OUT
}

void Server::close_socket () {
ioc.stop();
ioc.join();
}

void Client::close_socket () {
}

Server::Server () {

}

void Server::run () {
TheServer server(ioc.get_executor(), 6906);
}

98 changes: 98 additions & 0 deletions winserver.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# ifndef WINSERVER
# define WINSERVER
# include "presets.h"
#include <winsock2.h>
#include <boost/asio.hpp>
#include <boost/bind/bind.hpp>
#include <boost/optional.hpp>
#include <iomanip>
#include <iostream>

using namespace std;
using json = nlohmann::json;

namespace asio = boost::asio;
using asio::ip::tcp;
using namespace std::chrono_literals;
using boost::system::error_code;

void read_session(tcp::socket sock) ;

class TheServer {
public:
TheServer(asio::any_io_executor ex, uint16_t port) //
: m_Acceptor{ex, tcp::endpoint{tcp::v4(), port}} //
{
m_Acceptor.set_option(tcp::acceptor::reuse_address(true));
do_accept();
}

private:

void do_accept() {
m_Acceptor.async_accept([this](boost::system::error_code ec, tcp::socket s) {
if (!ec) {
std::thread(read_session, std::move(s)).detach();
do_accept(); // and immediately accept new connection(s)
} else {
std::cout << "Connection error (" << ec.message() << ")" << std::endl;
}
});
}

tcp::acceptor m_Acceptor;
};

class Client {
public:
Client(string host, int port);
~Client();

void run();
std::string send_preset(json j) ;
virtual void create();
virtual void close_socket();
void echo();
bool get_response();

private:
bool send_request(string);

string host_;
int port_;
int server_;
int buflen_;
char* buf_;
};

class Server {
public:
Server();
~Server();

Presets * presets ;
void * sync ;
void run();

GMainContext * context ;
void create();
void close_socket();
void serve();
void handle(int);
string get_request(int);
bool send_response(int, string);

int port_;
int server_;
int buflen_;
char* buf_;
};


class NET {
public:
vector <string> addresses;
} ;


# endif
Binary file added winserver.o
Binary file not shown.

0 comments on commit 234efd4

Please sign in to comment.