Skip to content

Commit

Permalink
[mod] delete unused files
Browse files Browse the repository at this point in the history
  • Loading branch information
tsymiar committed Jan 18, 2025
1 parent 1ce46ac commit 34aa285
Show file tree
Hide file tree
Showing 12 changed files with 169 additions and 167 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ lib
build
Debug
jniLibs
target*
*.exe
*.so
out
2 changes: 1 addition & 1 deletion build.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
if [ "$1" == "clean" ]; then
rm -rvf .vs* build jniLibs lib out
rm -rvf .vs* build jniLibs target lib out
# export TERM=xterm
# clear
else
Expand Down
9 changes: 8 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ endif()
if("${ANDROID}" EQUAL "1")
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/../../../../jniLibs/${ANDROID_ABI})
else()
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/../../lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/../target/lib)
add_definitions(-DFULLY_COMPILE)
include_directories(..)
endif()
Expand All @@ -49,3 +49,10 @@ else()
endif()

target_link_libraries(${TARGET} ${EXTERN})
add_custom_command(TARGET ${PROJECT_NAME}
POST_BUILD
COMMAND ${CMAKE_COMMAND} -E
copy_if_different
"${PROJECT_SOURCE_DIR}/common/Scadup.h"
"${PROJECT_SOURCE_DIR}/../target/include/${TARGET}.h"
)
153 changes: 150 additions & 3 deletions src/common/Scadup.h
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,150 @@
#include "scadup/Broker.h"
#include "scadup/Publisher.h"
#include "scadup/Subscriber.h"
#pragma once
#include <algorithm>
#include <chrono>
#include <cmath>
#include <csignal>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fcntl.h>
#include <fstream>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <mutex>
#include <string>
#include <thread>
#include <vector>
#ifdef _WIN32
#define _WIN32_WINNT 0x0600
#include <Ws2tcpip.h>
#include <Windows.h>
#else
#include <arpa/inet.h>
#include <netinet/in.h>
#include <unistd.h>
#endif
#ifdef _WIN32
#define __attribute__(x)
#define MSG_NOSIGNAL 0
#define signal(_1,_2) {}
inline void Close(SOCKET x)
{
#ifdef _MSC_VER
::closesocket(x);
#else
::close(x);
#endif
WSACleanup();
}
#ifdef _MSC_VER
typedef int ssize_t;
#endif
#else
using SOCKET = int;
#define Close ::close
#endif
const unsigned int Time100ms = 100;
#define Write(x,y,z) ::send(x,(char*)(y),z,MSG_NOSIGNAL)
#define Delete(s) { if (s != nullptr) { delete[] s; s = nullptr; } }

inline void wait(unsigned int tms)
{
std::this_thread::sleep_for(std::chrono::microseconds(tms));
}

namespace Scadup {
enum G_ScaFlag {
NONE = 0,
BROKER,
PUBLISHER,
SUBSCRIBER,
MAX_VAL
};
struct Header {
uint8_t rsvp;
uint8_t cmd;
G_ScaFlag flag;
uint32_t size;
uint32_t topic;
volatile uint64_t ssid; // ssid = (port | key | ip)
} __attribute__((aligned(4)));
struct Message {
Header head{};
struct Payload {
char status[8];
char* content = nullptr;
} __attribute__((aligned(4))) payload { };
void* operator new(size_t, const Message& msg)
{
static void* mss = (void*)(&msg);
return mss;
}
} __attribute__((aligned(4)));
struct Network {
SOCKET socket = 0;
Header head;
char IP[INET_ADDRSTRLEN];
unsigned short PORT = 0;
volatile bool active = false;
};
const size_t HEAD_SIZE = sizeof(Header);
typedef void(*RECV_CALLBACK)(const Message&);
typedef std::map<G_ScaFlag, std::vector<Network>> Networks;
extern bool makeSocket(SOCKET& socket);
extern SOCKET socket2Broker(const char* ip, unsigned short port, uint64_t& ssid, uint32_t timeout);
extern int connect(const char* ip, unsigned short port, unsigned int total);
extern ssize_t writes(SOCKET socket, const uint8_t* data, size_t len);
}

namespace Scadup {
class Broker {
public:
static Broker& instance();
int setup(unsigned short = 9999);
int broker();
void exit();
private:
int ProxyTask(Networks&, const Network&);
void checkAlive(Networks&, bool*);
void setOffline(Networks&, SOCKET);
uint64_t setSession(const std::string&, unsigned short, SOCKET = 0);
bool checkSsid(SOCKET, uint64_t);
void taskAllot(Networks&, const Network&);
private:
std::mutex m_lock = {};
Networks m_networks{};
SOCKET m_socket = -1;
bool m_active = false;
};
}

namespace Scadup {
class Publisher {
public:
void setup(const char*, unsigned short = 9999);
int publish(uint32_t, const std::string&, ...);
private:
ssize_t broadcast(const uint8_t*, size_t);
private:
SOCKET m_socket = -1;
uint64_t m_ssid = 0;
};
}

namespace Scadup {
class Subscriber {
public:
void setup(const char*, unsigned short = 9999);
ssize_t subscribe(uint32_t, RECV_CALLBACK = nullptr);
void quit();
static void exit();
private:
void keepAlive(SOCKET, bool&);
private:
static bool m_exit;
uint64_t m_ssid = 0;
SOCKET m_socket = -1;
};
}
103 changes: 0 additions & 103 deletions src/common/common.h

This file was deleted.

8 changes: 6 additions & 2 deletions src/scadup/Broker.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#include "Broker.h"
#include "common/Scadup.h"

extern "C" {
#include "../utils/msg_que.h"
}

#define LOG_TAG "Broker"
#include "../utils/logging.h"
Expand Down Expand Up @@ -61,7 +65,7 @@ ssize_t Scadup::writes(SOCKET socket, const uint8_t* data, size_t len)
memcpy(buff, data, left);
ssize_t sent = 0;
while (left > 0 && (size_t)sent < len) {
if ((sent = write(socket, reinterpret_cast<char*>(buff + sent), left)) <= 0) {
if ((sent = Write(socket, reinterpret_cast<char*>(buff + sent), left)) <= 0) {
if (sent < 0) {
if (errno == EINTR) {
sent = 0; /* call write() again */
Expand Down
23 changes: 0 additions & 23 deletions src/scadup/Broker.h

This file was deleted.

2 changes: 1 addition & 1 deletion src/scadup/Publisher.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "Publisher.h"
#include "common/Scadup.h"

#define LOG_TAG "Publisher"
#include "../utils/logging.h"
Expand Down
14 changes: 0 additions & 14 deletions src/scadup/Publisher.h

This file was deleted.

2 changes: 1 addition & 1 deletion src/scadup/Subscriber.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "Subscriber.h"
#include "common/Scadup.h"

#define LOG_TAG "Subscriber"
#include "../utils/logging.h"
Expand Down
17 changes: 0 additions & 17 deletions src/scadup/Subscriber.h

This file was deleted.

2 changes: 1 addition & 1 deletion src/utils/FileUtils.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ class FileUtils {
FileUtils& operator=(const FileUtils&);
};

#endif //DEVIDROID_FILEUTILS_H
#endif //DEVICE2DEVICE_FILEUTILS_H

0 comments on commit 34aa285

Please sign in to comment.