Skip to content

Commit

Permalink
Making MPSCRingBuffer and Logging common
Browse files Browse the repository at this point in the history
  • Loading branch information
pat committed Oct 7, 2015
1 parent c228b8c commit 9486b5c
Show file tree
Hide file tree
Showing 22 changed files with 58 additions and 208 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
all: libs
tls: libs
OUTDIR=./sdk
LIBDIR=$(OUTDIR)/lib
INCLUDEDIR=$(OUTDIR)/include
MODULES=$(sort $(patsubst ./%/,%,$(dir $(wildcard ./*/Makefile))))
LIBS=$(addprefix $(LIBDIR)/,$(MODULES))
LIBS:=$(addsuffix .a,$(LIBS))
tls:TLS=tls

clean-%:
-cd $* && make clean
Expand All @@ -13,8 +15,8 @@ clean: $(addprefix clean-,$(MODULES))
-rm -R $(OUTDIR)

$(LIBDIR)/%.a:%
cd $< && make
mv $</$<.a $@
cd $< && make $(TLS)
-mv $</$<.a $@
mkdir -p $(INCLUDEDIR)/$<
cp $</*.h $(INCLUDEDIR)/$<

Expand Down
1 change: 1 addition & 0 deletions json/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
all: tests
tls: tests
OBJECTS = JSON.o List.o Object.o Value.o Parser.o
SOURCES=$(OBJECTS:.o=.cpp)

Expand Down
1 change: 1 addition & 0 deletions rest/Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
all: lib
tls: lib


SOURCESCPP = RESTEngine.cpp RESTCallBack.cpp RESTParameters.cpp
Expand Down
2 changes: 1 addition & 1 deletion websocket/Logging.cpp → utils/Logging.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ SOFTWARE.
#include <stdio.h>
#include <stdarg.h>

using namespace Dumais::WebSocket;
using namespace Dumais::Utils;

ILogger* Logging::logger = 0;

Expand Down
4 changes: 2 additions & 2 deletions websocket/Logging.h → utils/Logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,11 @@ SOFTWARE.
#pragma once
#include <sstream>

#define LOG(x) {std::stringstream logss; logss << x; Dumais::WebSocket::Logging::log(logss.str());}
#define LOG(x) {std::stringstream logss; logss << x; Dumais::Utils::Logging::log(logss.str());}

namespace Dumais
{
namespace WebSocket
namespace Utils
{
class ILogger
{
Expand Down
4 changes: 2 additions & 2 deletions websocket/MPSCRingBuffer.h → utils/MPSCRingBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ typedef unsigned int uint32_t;

namespace Dumais
{
namespace WebSocket
namespace Utils
{

// Multi-Producer, Single-Consumer, lock-free ring buffer
Expand Down Expand Up @@ -96,4 +96,4 @@ namespace Dumais

};
}
}
}
19 changes: 19 additions & 0 deletions utils/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
tls:lib
EXCEPTIONS=./main.cpp
SOURCES=$(filter-out $(EXCEPTIONS),$(wildcard ./*.cpp))
OBJECTS=$(SOURCES:.cpp=.o)
CFLAGS=-std=c++11 -g
LDFLAGS=-lpthread -lcurl

clean:
-rm *.o
-rm *.a

.cpp.o:
$(CXX) $(CFLAGS) -c $< -o $@

lib: $(OBJECTS)
$(AR) rcs utils.a $(OBJECTS)

all: lib
#g++ main.o webserver.a -std=c++0x -o test $(LDFLAGS)
73 changes: 0 additions & 73 deletions webserver/MPSCRingBuffer.h

This file was deleted.

10 changes: 5 additions & 5 deletions webserver/Makefile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
all: tests
tls: tests
all: lib
tls: lib
EXCEPTIONS=./main.cpp
SOURCES=$(filter-out $(EXCEPTIONS),$(wildcard ./*.cpp))
OBJECTS=$(SOURCES:.cpp=.o)
CFLAGS=-std=c++11 -g
LDFLAGS=-lpthread -lcurl
CFLAGS+=-std=c++11 -g -I ../
LDFLAGS+=-lpthread -lcurl
tls:CFLAGS+=-DUSING_OPENSSL
tls:LDFLAGS+=-lssl -lcrypto

Expand All @@ -20,4 +20,4 @@ lib: $(OBJECTS)
$(AR) rcs webserver.a $(OBJECTS)

tests: lib main.o
g++ main.o webserver.a -std=c++0x -o test $(LDFLAGS)
g++ main.o webserver.a ../utils/utils.a -std=c++0x -o test $(LDFLAGS)
1 change: 1 addition & 0 deletions webserver/TcpClient.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#define MAX_INTERNAL_TX_COUNT 4000
using namespace Dumais::WebServer;
using namespace Dumais::Utils;


TcpClient::TcpClient(ITcpClientContext* ctx, IFramingStrategy* fs)
Expand Down
4 changes: 2 additions & 2 deletions webserver/TcpClient.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <queue>
#include "ITcpClientContext.h"
#include "IFramingStrategy.h"
#include "MPSCRingBuffer.h"
#include "utils/MPSCRingBuffer.h"
#include "ISocket.h"

namespace Dumais{
Expand Down Expand Up @@ -48,7 +48,7 @@ class TcpClient
bool mustDeleteBuffer;
};

MPSCRingBuffer<SendBuffer>* txList;
Dumais::Utils::MPSCRingBuffer<SendBuffer>* txList;
SendBuffer currentSendBuffer;
ITcpClientContext* context;
IFramingStrategy *framingStrategy;
Expand Down
2 changes: 1 addition & 1 deletion webserver/TcpServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#include <netdb.h>
#include "PlainSocket.h"
#include "SecureSocket.h"
#include "WebServerLogging.h"
#include "utils/Logging.h"

using namespace Dumais::WebServer;

Expand Down
47 changes: 0 additions & 47 deletions webserver/WebServerLogging.cpp

This file was deleted.

58 changes: 0 additions & 58 deletions webserver/WebServerLogging.h

This file was deleted.

2 changes: 1 addition & 1 deletion websocket/HTTPProtocolParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "HTTPProtocolParser.h"
#include "Logging.h"
#include "utils/Logging.h"
#include "sha1.h"
#include "base64.h"
#include <sstream>
Expand Down
11 changes: 7 additions & 4 deletions websocket/Makefile
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
SOURCES = WebSocketServer.cpp WebSocket.cpp Logging.cpp sha1.cpp base64.cpp HTTPProtocolParser.cpp WSProtocolParser.cpp
SOURCES = WebSocketServer.cpp WebSocket.cpp sha1.cpp base64.cpp HTTPProtocolParser.cpp WSProtocolParser.cpp
OBJECTS=$(SOURCES:.cpp=.o)

CFLAGS=-I ../ -g -std=c++11
.cpp.o:
g++ -g -std=c++11 -c $< -o $@
g++ $(CFLAGS) -c $< -o $@


all: lib
g++ -g -std=c++11 main.cpp websocket.a
tls: lib

test: lib
g++ -g $(CFLAGS) main.cpp websocket.a

lib: $(OBJECTS)
$(AR) rcs websocket.a $(OBJECTS)
Expand Down
2 changes: 1 addition & 1 deletion websocket/WSProtocolParser.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include "WSProtocolParser.h"
#include "Logging.h"
#include "utils/Logging.h"
#include <string.h>

#define DEFAULT_DATA_SIZE 1024
Expand Down
3 changes: 2 additions & 1 deletion websocket/WebSocket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#include "Logging.h"
#include "utils/Logging.h"
#include "WebSocket.h"
#include <string.h>
#include <sstream>
Expand All @@ -32,6 +32,7 @@ SOFTWARE.
#define CLOSING_TIMEOUT 5

using namespace Dumais::WebSocket;
using namespace Dumais::Utils;

WebSocket::WebSocket(std::function<bool(const std::string& request,
std::map<std::string,std::string> protocols,
Expand Down
Loading

0 comments on commit 9486b5c

Please sign in to comment.