fanch 3 anni fa
parent
commit
6a0d354345
7 ha cambiato i file con 220 aggiunte e 17 eliminazioni
  1. 1 1
      CMakeLists.txt.user
  2. 2 0
      main.cpp
  3. 6 0
      src/socket.cpp
  4. 206 0
      src/socket.h
  5. 1 1
      ui/main.py
  6. 3 0
      ui/setup.py
  7. 1 15
      ui/simplemidi.py

+ 1 - 1
CMakeLists.txt.user

@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE QtCreatorProject>
-<!-- Written by QtCreator 4.13.3, 2020-12-12T22:19:44. -->
+<!-- Written by QtCreator 4.13.3, 2021-01-24T17:05:06. -->
 <qtcreator>
  <data>
   <variable>EnvironmentId</variable>

+ 2 - 0
main.cpp

@@ -18,6 +18,8 @@ class TMP : public IMidiPortListener
         virtual void on_new_message(double ts, const MidiMessage* m){
             std::cout << m->to_string() << "\n";
         }
+
+
 };
 
 #include "Socket.h"

+ 6 - 0
src/socket.cpp

@@ -0,0 +1,6 @@
+#include "socket.h"
+
+Socket::Socket()
+{
+
+}

+ 206 - 0
src/socket.h

@@ -0,0 +1,206 @@
+#ifndef SOCKET_H
+#define SOCKET_H
+
+
+#ifdef WIN32 /* si vous êtes sous Windows */
+
+#include <winsock2.h>
+
+#elif defined (linux) /* si vous êtes sous Linux */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <unistd.h> /* close */
+#include <netdb.h> /* gethostbyname */
+#define INVALID_SOCKET -1
+#define SOCKET_ERROR -1
+#define closesocket(s) close(s)
+typedef int SOCKET;
+typedef struct sockaddr_in SOCKADDR_IN;
+typedef struct sockaddr SOCKADDR;
+typedef struct in_addr IN_ADDR;
+#include <sys/un.h>
+#else /* sinon vous êtes sur une plateforme non supportée */
+
+#error not defined for this platform
+
+#endif
+#include <string>
+#include <istream>
+#include <ostream>
+
+class SocketError
+{
+        public:
+                SocketError(const std::string& s, const std::string& t) : error(s), type(t){}
+                virtual ~SocketError(){}
+                std::string error;
+                std::string type;
+};
+#define DefineSocketError(__Err__) class __Err__ : public SocketError{ public: __Err__(const std::string& e, const std::string& t) : SocketError(e, t){} ~__Err__(){} };
+
+DefineSocketError(ConnectSocketError)
+DefineSocketError(FileSocketNotFoundError)
+DefineSocketError(SendSocketError)
+DefineSocketError(RecieveSocketError)
+DefineSocketError(AcceptSocketError)
+DefineSocketError(BindSocketError)
+DefineSocketError(ListenSocketError)
+DefineSocketError(HostSocketError)
+DefineSocketError(OptSocketError)
+
+#ifndef THROW
+        #define THROW(__ERR__, __MSG__) {std::ostringstream os; os << #__ERR__<< " : " << __MSG__ <<"\n"; std::cerr << os.str(); throw __ERR__(os.str(), #__ERR__);}
+#endif
+
+
+class _AbsSocket
+{
+    public:
+                enum                    SocketType { INET, UNIX, STDIO } ;
+                                _AbsSocket(SocketType);
+        virtual                 ~_AbsSocket();
+        virtual void            close();
+                virtual	bool			is_open();
+
+
+    protected:
+        SocketType              m_type;
+        SOCKET                  m_sock;
+        bool                    m_is_open;
+};
+
+
+class ISocket : public std::istream, public std::ostream
+{
+        public:
+                virtual ~ISocket(){}
+
+                virtual void            write(const void* data, int size)=0;
+                virtual int             read(void* data, int n, bool blocking)=0;
+                virtual ISocket&        putc(int c) {write(&c,1); return *(ISocket*)this;}
+                virtual void            write(const std::string& data){write(data.c_str(), data.size());}
+
+
+                virtual int             read(void* data, int n){return read(data,n,false);};
+                virtual int             readc(){int c; return (read(&c,1)==1)?c:-1;}
+                virtual std::string&    readline(std::string&);
+                virtual	_AbsSocket::SocketType get_type() const =0;
+                virtual void            close()=0;
+                virtual	bool			is_open()=0;
+};
+
+class Socket : public _AbsSocket, public ISocket
+{
+        public:
+                Socket(SocketType t) : _AbsSocket(t){}
+        Socket(SocketType type, SOCKET client) : Socket(type){m_sock=client; m_is_open=true;}
+        virtual ~Socket(){}
+
+                virtual void            write(const void* data, int size);
+                virtual int             read(void* data, int n, bool blocking);
+                virtual	SocketType		get_type() const {return m_type;}
+                virtual void			close(){_AbsSocket::close();};
+                virtual bool			is_open(){return _AbsSocket::is_open();}
+
+};
+
+
+class InetSocket : public Socket
+{
+        public:
+                InetSocket() : Socket(INET){}
+                InetSocket(SOCKET sock) : Socket(INET, sock){}
+        virtual ~InetSocket(){}
+
+                virtual bool    connect(const std::string& addr, int port);
+                virtual Socket::SocketType	get_type() const {return Socket::INET;}
+
+    protected:
+        std::string     m_hostname;
+        int             m_port;
+};
+
+class UnixSocket : public Socket
+{
+    public:
+        UnixSocket() : Socket(UNIX){}
+        virtual ~UnixSocket(){}
+
+                virtual bool    connect(const std::string& addr);
+                virtual Socket::SocketType	get_type() const {return Socket::UNIX;}
+
+    protected:
+        std::string     m_hostname;
+        int             m_port;
+};
+
+
+class IAbsServer
+{
+        public:
+                virtual						~IAbsServer(){}
+                virtual ISocket*			accept()=0;
+                virtual Socket::SocketType	get_type() const=0;
+
+};
+
+class InetServer : public _AbsSocket, public IAbsServer
+{
+        public:
+                                                InetServer();
+        virtual         ~InetServer(){}
+
+        virtual void    listen(int port);
+                virtual ISocket* accept();
+                virtual Socket::SocketType	get_type() const {return Socket::INET;}
+
+
+};
+
+class UnixServer : public _AbsSocket, public IAbsServer
+{
+    public:
+        UnixServer();
+        virtual         ~UnixServer();
+
+        virtual void    listen(const std::string& path){return listen(path, true);}
+        virtual void    listen(const std::string& path, bool);
+                virtual ISocket* accept();
+                virtual Socket::SocketType	get_type() const {return Socket::UNIX;}
+
+    protected:
+        std::string     m_path;
+};
+
+
+class StdioSocket :  public ISocket
+{
+        public:
+                                                                        StdioSocket(int first){m_first=first;}
+                virtual						~StdioSocket(){}
+
+                virtual void				write(const void* data, int size);
+                virtual int					read(void* data, int n, bool blocking);
+                virtual	Socket::SocketType	get_type() const {return Socket::STDIO;}
+                virtual void				close(){};
+                virtual bool				is_open(){return false;}
+
+        public:
+                int     m_first;
+
+};
+
+
+class StdioServer : public IAbsServer
+{
+        public:
+                                                                        StdioServer() {}
+                virtual						~StdioServer(){}
+                virtual ISocket*			accept();
+                virtual Socket::SocketType	get_type() const {return Socket::STDIO;}
+};
+
+#endif // SOCKET_H

+ 1 - 1
ui/main.py

@@ -47,7 +47,7 @@ pad.write("../pads/apc.json")
 
 
 
-
+cd
 
 
 

+ 3 - 0
ui/setup.py

@@ -0,0 +1,3 @@
+import os
+src="application.py"
+os.system("pyinstaller -y '%s'" % src)

+ 1 - 15
ui/simplemidi.py

@@ -124,22 +124,8 @@ class SimpleMidi:
         if not self.connect and not self.is_alive():
             padsdir = os.path.normpath(os.path.join(os.getcwd(), "../pads"))
             args=(os.path.join(os.getcwd(), config.PAD_ROUTER_BIN), "--command", "inet", "8081", "-k", "--pads-dir", padsdir)
-            fd = open("_stderr", "wb")
+            fd = open("stderr", "wb")
             self.process=subprocess.Popen(args, stderr=fd)
-            """if (self.pid>0):
-                os.kill(self.pid, 9)
-                os.wait()
-            "ui/" + config.PAD_ROUTER_BIN, ".", "--command", "inet", "8081", "-k", "--pads-dir", padsdir)
-            self.pid = os.fork()
-
-            if not self.pid:
-                Gtk.main_quit()
-                print("Start: ", config.PAD_ROUTER_BIN + " --pads-dir " + SimpleMidi.TEMP_FILE)
-                os.chdir("..")
-                padsdir = os.path.normpath(os.path.join(os.getcwd(), "pads"))
-                args=("ui/" + config.PAD_ROUTER_BIN, ".",  "--command", "inet", "8081", "-k", "--pads-dir", padsdir)
-                print(" ".join(args))
-                os.execl(*args)"""
 
         self.socket = Socket()
         for i in range(SimpleMidi.NB_TRIES):