Skip to content

Commit b29629e

Browse files
Bardo91Bardo91
authored andcommitted
Merge branch '2.x.x'
2 parents c4ebdb1 + e75b5cd commit b29629e

35 files changed

+1015
-1532
lines changed

CMakeLists.txt

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,12 @@
2222
cmake_minimum_required(VERSION 3.8 FATAL_ERROR)
2323
PROJECT(fastcom VERSION 1.3.0)
2424

25-
2625
#########################################
2726
###### General config ######
2827
#########################################
2928

3029
option(BUILD_EXAMPLES "Compile examples" ON)
31-
option(BUILD_TESTS "Prepare tests" ON)
30+
option(BUILD_TESTS "Prepare tests" OFF)
3231

3332
if(UNIX)
3433
add_definitions(-std=c++11 -pthread -lpthread)
@@ -42,11 +41,6 @@ endif()
4241
#########################################
4342
set(Boost_USE_MULTITHREAD ON)
4443

45-
find_package(Boost REQUIRED COMPONENTS system thread regex)
46-
47-
find_package(OpenCV)
48-
49-
5044
#########################################
5145
###### Library ######
5246
#########################################
@@ -58,7 +52,7 @@ if(UNIX)
5852
elseif(WIN32)
5953
add_library(${PROJECT_NAME} STATIC ${FASTCOM_SOURCES} ${FASTCOM_HEADERS})
6054
endif()
61-
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_11)
55+
target_compile_features(${PROJECT_NAME} PUBLIC cxx_std_17)
6256
set_target_properties(${PROJECT_NAME} PROPERTIES LINKER_LANGUAGE C)
6357

6458
target_include_directories(${PROJECT_NAME} PUBLIC
@@ -72,16 +66,22 @@ elseif(WIN32)
7266
target_compile_options(${PROJECT_NAME} PUBLIC "/EHsc")
7367
endif()
7468

69+
find_package(Boost REQUIRED COMPONENTS system thread regex)
7570
target_include_directories(${PROJECT_NAME} PUBLIC ${Boost_INCLUDE_DIRS})
7671
target_link_libraries(${PROJECT_NAME} LINK_PUBLIC ${Boost_LIBRARIES})
7772

73+
find_package(OpenCV)
7874
if(OpenCV_FOUND)
7975
target_include_directories(${PROJECT_NAME} PUBLIC ${OpenCV_INCLUDE_DIRS})
8076
target_link_libraries(${PROJECT_NAME} LINK_PUBLIC ${OpenCV_LIBRARIES})
8177
target_compile_definitions(${PROJECT_NAME} PUBLIC FASTCOM_HAS_OPENCV)
8278
endif(OpenCV_FOUND)
8379

8480

81+
find_package(websocketpp REQUIRED)
82+
target_link_libraries(${PROJECT_NAME} LINK_PUBLIC websocketpp::websocketpp)
83+
84+
8585
if(WIN32)
8686
target_compile_definitions(${PROJECT_NAME} PUBLIC "_WIN32_WINNT=0x0601")
8787
endif()
@@ -120,21 +120,21 @@ endif()
120120
###### Test ######
121121
#########################################
122122

123-
if(${BUILD_TESTS})
124-
if(WIN32)
125-
enable_testing()
126-
add_definitions("-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING")
127-
include(cmake/AddGoogleTest.cmake)
128-
add_subdirectory(tests)
129-
endif()
130-
if(UNIX)
131-
find_package(GTest)
132-
if(${GTest_FOUND})
133-
enable_testing()
134-
add_subdirectory(tests)
135-
endif()
136-
endif()
137-
endif()
123+
# if(${BUILD_TESTS})
124+
# if(WIN32)
125+
# enable_testing()
126+
# add_definitions("-D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING")
127+
# include(cmake/AddGoogleTest.cmake)
128+
# add_subdirectory(tests)
129+
# endif()
130+
# if(UNIX)
131+
# find_package(GTest)
132+
# if(${GTest_FOUND})
133+
# enable_testing()
134+
# add_subdirectory(tests)
135+
# endif()
136+
# endif()
137+
# endif()
138138

139139

140140
#########################################

README.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,30 @@
44

55
[![Build Status](https://travis-ci.org/Bardo91/fastcom.svg?branch=master)](https://travis-ci.org/Bardo91/fastcom)
66

7+
8+
9+
# Installation
10+
11+
Clone the repository into any folder, and create a build folder for the compilation
12+
13+
```
14+
git clone https://github.com/Bardo91/fastcom
15+
cd fastcom && mkdir build && cd build
16+
```
17+
18+
Configure with cmake and compile the project
19+
20+
```
21+
cmake .. && make
22+
```
23+
24+
Install fastcom to use it at any project you want.
25+
```
26+
sudo make install
27+
```
28+
29+
Create fastcom mole IP environment variable. If you are using fastcom in the same computer, this step is not necessary. If you are using multiple computers, this variable should have the IP of where the first fastcom app is instantiated.
30+
```
31+
echo "export FASTCOM_MOLE_IP=\"127.0.0.1\"" >> ~/.bashrc
32+
```
33+

doc/fastcom_logo.png

1.02 KB
Loading

examples/CMakeLists.txt

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,18 @@
2020
##---------------------------------------------------------------------------------------------------------------------
2121

2222
add_executable(example_sender "sender.cpp")
23-
target_include_directories(example_sender PRIVATE "../include")
2423
target_link_libraries(example_sender LINK_PUBLIC fastcom)
2524

2625
add_executable(example_receiver "receiver.cpp")
27-
target_include_directories(example_receiver PRIVATE "../include")
2826
target_link_libraries(example_receiver LINK_PUBLIC fastcom)
2927

30-
3128
add_executable(example_sender_image "sender_image.cpp")
32-
target_include_directories(example_sender_image PRIVATE "../include")
3329
target_link_libraries(example_sender_image LINK_PUBLIC fastcom)
3430

3531
add_executable(example_receiver_image "receiver_image.cpp")
36-
target_include_directories(example_receiver_image PRIVATE "../include")
3732
target_link_libraries(example_receiver_image LINK_PUBLIC fastcom)
3833

39-
add_executable(example_destruction "destruction.cpp")
40-
target_include_directories(example_destruction PRIVATE "../include")
41-
target_link_libraries(example_destruction LINK_PUBLIC fastcom)
42-
4334

44-
add_executable(example_service_client "service_client.cpp")
45-
target_include_directories(example_service_client PRIVATE "../include")
46-
target_link_libraries(example_service_client LINK_PUBLIC fastcom)
4735

48-
add_executable(example_service_server "service_server.cpp")
49-
target_include_directories(example_service_server PRIVATE "../include")
50-
target_link_libraries(example_service_server LINK_PUBLIC fastcom)
36+
add_executable(sample "sample.cpp")
37+
target_link_libraries(sample LINK_PUBLIC fastcom)

examples/SerializableMat.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
2+
#ifndef SERIALIZABLEMAT_H_
3+
#define SERIALIZABLEMAT_H_
4+
5+
#include <vector>
6+
#include <string_view>
7+
#include <opencv2/opencv.hpp>
8+
9+
class SerializableMat{
10+
public:
11+
SerializableMat(cv::Mat _img = cv::Mat(), int _jpegQuality = 50){
12+
imgRef_ = _img;
13+
params_.push_back(CV_IMWRITE_JPEG_QUALITY);
14+
params_.push_back(_jpegQuality);
15+
}
16+
17+
operator const cv::Mat &() const { return imgRef_; };
18+
operator cv::Mat &() { return imgRef_; };
19+
const cv::Mat & getCvMat() const { return imgRef_; };
20+
21+
friend std::ostream & operator<<(std::ostream &_out, SerializableMat &_v) {
22+
std::vector<uchar> buffer;
23+
cv::imencode(".jpg", _v.imgRef_, buffer, _v.params_);
24+
std::string_view res((char*)buffer.data(), buffer.size());
25+
_out << res;
26+
std::cout << "Serialized image of size " << buffer.size() << std::endl;
27+
return _out;
28+
}
29+
friend std::istream & operator>>(std::istream &_in, SerializableMat &_v) {
30+
31+
std::cout << "Deserializing image. ";
32+
std::vector<uint8_t> buffer;
33+
std::for_each(std::istreambuf_iterator<char>(_in),
34+
std::istreambuf_iterator<char>(),
35+
[&buffer](const char c){
36+
buffer.push_back(c);
37+
});
38+
39+
std::cout << "Final size: " << buffer.size() << std::endl;
40+
41+
_v.imgRef_=cv::imdecode(buffer,1);
42+
return _in;
43+
}
44+
45+
private:
46+
std::vector<int> params_;
47+
cv::Mat imgRef_;
48+
};
49+
50+
51+
#endif

examples/SerializableVector.h

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
2+
#ifndef SERIALIZABLEVECTOR_H_
3+
#define SERIALIZABLEVECTOR_H_
4+
5+
6+
template<typename Type_>
7+
class SerializableVector{
8+
public:
9+
void push_back(Type_ _t){ v_.push_back(_t);};
10+
11+
typename std::vector<Type_>::iterator begin() { return v_.begin();};
12+
typename std::vector<Type_>::iterator end() { return v_.end();};
13+
14+
typename std::vector<Type_>::const_iterator begin() const { return v_.begin();};
15+
typename std::vector<Type_>::const_iterator end() const { return v_.end();};
16+
17+
friend std::ostream & operator<<(std::ostream &_out, SerializableVector<Type_> &_v) {
18+
std::string res((char*)_v.data(), sizeof(Type_)*_v.size());
19+
_out << res;
20+
return _out;
21+
}
22+
friend std::istream & operator>>(std::istream &_in, SerializableVector<Type_> &_v) {
23+
24+
char *buffer = new char[sizeof(float)];
25+
while (_in) {
26+
_in.read(buffer, sizeof(float));
27+
_v.push_back(*((float*)buffer));
28+
}
29+
30+
delete[] buffer;
31+
}
32+
33+
void resize(unsigned int _s) { v_.resize(_s);};
34+
35+
Type_ *data() { return v_.data(); };
36+
37+
size_t size() { return v_.size(); };
38+
39+
private:
40+
std::vector<Type_> v_;
41+
42+
};
43+
44+
45+
#endif

examples/receiver.cpp

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
//---------------------------------------------------------------------------------------------------------------------
22
// FASTCOM
33
//---------------------------------------------------------------------------------------------------------------------
4-
// Copyright 2019 - Pablo Ramon Soria (a.k.a. Bardo91)
4+
// Copyright 2020 - Manuel Perez Jimenez (a.k.a. manuoso)
5+
// Marco A. Montes Grova (a.k.a. mgrova)
6+
// Pablo Ramon Soria (a.k.a. Bardo91)
7+
// Ricardo Lopez Lopez (a.k.a. ric92)
58
//---------------------------------------------------------------------------------------------------------------------
69
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software
710
// and associated documentation files (the "Software"), to deal in the Software without restriction,
@@ -19,29 +22,42 @@
1922
// CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2023
//---------------------------------------------------------------------------------------------------------------------
2124

25+
26+
#include <fastcom/Publisher.h>
2227
#include <fastcom/Subscriber.h>
2328

29+
#include <fastcom/ConnectionManager.h>
30+
31+
#include <string>
2432
#include <thread>
25-
#include <iostream>
2633
#include <chrono>
34+
#include <iostream>
2735

36+
#include "SerializableVector.h"
2837

29-
struct SimpleFloat{
30-
float a;
31-
float b;
32-
float c;
33-
};
38+
int main(){
3439

35-
int main(int _argc, char **_argv){
40+
fastcom::Subscriber<int> s1("/integer_count");
41+
fastcom::Subscriber<std::string> s2("/jojo");
42+
fastcom::Subscriber<SerializableVector<float>> s3("/custom");
43+
44+
s1.addCallback([&](const int &_msg){
45+
std::cout << _msg << std::endl;
46+
});
3647

37-
fastcom::Subscriber<SimpleFloat> subscriber(_argv[1], 8888);
48+
s2.addCallback([&](const std::string &_msg){
49+
std::cout << _msg << std::endl;
50+
});
3851

39-
subscriber.attachCallback([&](SimpleFloat &_data){
40-
std::cout << _data.a << std::endl;
52+
s3.addCallback([&](const SerializableVector<float> &_msg){
53+
for(auto elem: _msg)
54+
std::cout << elem << ", "<< std::endl;
4155
});
4256

43-
for(;;){
44-
std::this_thread::sleep_for(std::chrono::milliseconds(100));
57+
58+
while (true) {
59+
std::this_thread::sleep_for(std::chrono::seconds(1));
4560
}
61+
4662

4763
}

examples/receiver_image.cpp

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
//---------------------------------------------------------------------------------------------------------------------
22
// FASTCOM
33
//---------------------------------------------------------------------------------------------------------------------
4-
// Copyright 2019 - Pablo Ramon Soria (a.k.a. Bardo91)
4+
// Copyright 2020 - Manuel Perez Jimenez (a.k.a. manuoso)
5+
// Marco A. Montes Grova (a.k.a. mgrova)
6+
// Pablo Ramon Soria (a.k.a. Bardo91)
7+
// Ricardo Lopez Lopez (a.k.a. ric92)
58
//---------------------------------------------------------------------------------------------------------------------
69
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software
710
// and associated documentation files (the "Software"), to deal in the Software without restriction,
@@ -20,35 +23,33 @@
2023
//---------------------------------------------------------------------------------------------------------------------
2124

2225

23-
#ifdef FASTCOM_HAS_OPENCV
26+
#include <fastcom/Publisher.h>
27+
#include <fastcom/Subscriber.h>
2428

25-
#include <fastcom/ImageSubscriber.h>
29+
#include <fastcom/ConnectionManager.h>
2630

31+
#include <string>
2732
#include <thread>
28-
#include <iostream>
2933
#include <chrono>
34+
#include <iostream>
3035

31-
int main(int _argc, char**_argv){
36+
#include "SerializableMat.h"
37+
#include <opencv2/opencv.hpp>
3238

33-
fastcom::ImageSubscriber subscriber(_argv[1], 8888);
39+
int main(){
3440

35-
std::function<void(cv::Mat &)> callback = [&](cv::Mat &_data){
36-
cv::imshow("display", _data);
41+
fastcom::Subscriber<SerializableMat> s1("/beauty_face");
42+
43+
s1.addCallback([&](const SerializableMat &_msg){
44+
auto mat = _msg.getCvMat();
45+
cv::imshow("face", mat);
3746
cv::waitKey(3);
38-
};
47+
});
3948

40-
subscriber.attachCallback(callback);
4149

42-
for(;;){
43-
std::this_thread::sleep_for(std::chrono::milliseconds(100));
50+
while (true) {
51+
std::this_thread::sleep_for(std::chrono::seconds(1));
4452
}
53+
4554

46-
}
47-
48-
#else
49-
50-
int main() {
51-
52-
}
53-
54-
#endif
55+
}

0 commit comments

Comments
 (0)