Skip to content

Commit 9289e68

Browse files
committed
Merge pull request #1 from tempodb/tempodb_config
Tempodb config
2 parents 30fd485 + 8e6db73 commit 9289e68

File tree

16 files changed

+186
-128
lines changed

16 files changed

+186
-128
lines changed

.gitignore

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
1-
TempoDb_CppUTest_tests
2-
libTempoDb_CppUTest.a
3-
objs/
1+
tempodb_tests
2+
tempodb_tests.txt
3+
lib/libtempodb.a
4+
lib/test/libtempodb.a
5+
objs/*
46
a.out
57
examples/example-authed.c
8+
CppUTest/CppUTest_tests
9+
CppUTest/lib/libCppUTest.a
10+
CppUTest/lib/libCppUTestExt.a
11+
CppUTest/objs

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
language: cpp
22
compiler:
33
- gcc
4-
- clang
5-
script: make
4+
script: cd CppUTest && make && echo "Done building CppUTest" && cd .. && pwd && make vtest

CppUTest/CppUTest_tests

-1.47 MB
Binary file not shown.

CppUTest/Makefile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#Set this to @ to keep the makefile quiet
2-
SILENCE = @
2+
#SILENCE = @
33

44
#--- Inputs ----#
55
COMPONENT_NAME = CppUTest
@@ -17,6 +17,10 @@ TEST_SRC_DIRS = \
1717
INCLUDE_DIRS =\
1818
include
1919

20+
CPPUTEST_LIB_DIR = lib
21+
22+
CPPUTEST_WARNINGFLAGS = NONE
23+
2024
include $(CPPUTEST_HOME)/build/MakefileWorker.mk
2125

2226
#these are a sample of the other alternative flag settings

CppUTest/build/MakefileWorker.mk

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,12 @@ endif
9090

9191
# Default dir for temporary files (d, o)
9292
ifndef CPPUTEST_OBJS_DIR
93-
CPPUTEST_OBJS_DIR = objs
93+
CPPUTEST_OBJS_DIR = objs/test
9494
endif
9595

9696
# Default dir for the outout library
9797
ifndef CPPUTEST_LIB_DIR
98-
CPPUTEST_LIB_DIR = lib
98+
CPPUTEST_LIB_DIR = lib/test
9999
endif
100100

101101
# No map by default
@@ -144,7 +144,9 @@ ifeq ($(CPPUTEST_USE_GCOV), Y)
144144
CPPUTEST_CPPFLAGS += -fprofile-arcs -ftest-coverage
145145
endif
146146

147-
CPPUTEST_CPPFLAGS += $(CPPUTEST_WARNINGFLAGS)
147+
ifneq ($(CPPUTEST_WARNINGFLAGS), NONE)
148+
CPPUTEST_CPPFLAGS += $(CPPUTEST_WARNINGFLAGS)
149+
endif
148150
CPPUTEST_CXXFLAGS += $(CPPUTEST_MEMLEAK_DETECTOR_NEW_MACRO_FILE)
149151
CPPUTEST_CFLAGS += $(CPPUTEST_MEMLEAK_DETECTOR_MALLOC_MACRO_FILE)
150152

@@ -251,12 +253,8 @@ LDFLAGS = $(CPPUTEST_LDFLAGS) $(CPPUTEST_ADDITIONAL_LDFLAGS)
251253

252254
# Targets
253255

254-
.PHONY: all
255-
all: start $(TEST_TARGET)
256-
$(RUN_TEST_TARGET)
257-
258256
.PHONY: start
259-
start: $(TEST_TARGET)
257+
start: $(TEST_TARGET)
260258
$(SILENCE)START_TIME=$(call time)
261259

262260
.PHONY: all_no_tests
@@ -290,10 +288,10 @@ $(TARGET_LIB): $(OBJ)
290288
$(SILENCE)ranlib $@
291289

292290
test: $(TEST_TARGET)
293-
$(RUN_TEST_TARGET) | tee $(TEST_OUTPUT)
291+
$(RUN_TEST_TARGET)
294292

295293
vtest: $(TEST_TARGET)
296-
$(RUN_TEST_TARGET) -v | tee $(TEST_OUTPUT)
294+
$(RUN_TEST_TARGET) -v
297295

298296
$(CPPUTEST_OBJS_DIR)/%.o: %.cpp
299297
@echo compiling $(notdir $<)

CppUTest/lib/.git_empty_dir

Whitespace-only changes.

CppUTest/lib/libCppUTest.a

-760 KB
Binary file not shown.

CppUTest/lib/libCppUTestExt.a

-788 KB
Binary file not shown.

Makefile

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
SILENCE = @
55

66
#---- Outputs ----#
7-
COMPONENT_NAME = TempoDb_CppUTest
7+
COMPONENT_NAME = tempodb
88

99
#--- Inputs ----#
1010
CPPUTEST_HOME = CppUTest
@@ -17,7 +17,7 @@ SRC_DIRS = \
1717
TEST_SRC_DIRS = \
1818
.\
1919
mocks\
20-
tests/tempodb\
20+
tests/TempoDb\
2121
tests\
2222

2323

@@ -35,4 +35,22 @@ CPPUTEST_WARNINGFLAGS = -Wall -Wswitch-default -Werror
3535
CPPUTEST_CFLAGS += -Wall -Wstrict-prototypes -pedantic
3636
LD_LIBRARIES = -lpthread
3737

38+
STUFF_TO_CLEAN += objs/* objs/src/tempodb/* objs/tests/* objs/mocks/* objs/tests/tempodb/* lib/libtempodb.a
39+
40+
CC = cc
41+
42+
all: lib/libtempodb.a
43+
44+
lib/libtempodb.a: objs/base64.o objs/tempodb.o
45+
ar rv lib/libtempodb.a objs/base64.o objs/tempodb.o
46+
47+
objs/base64.o:
48+
$(CC) -c -I include/tempodb -o objs/base64.o src/tempodb/base64.c
49+
50+
objs/tempodb.o:
51+
$(CC) -c -I include/tempodb -o objs/tempodb.o src/tempodb/tempodb.c
52+
53+
CppUTest/lib/libCppUTest.a:
54+
cd CppUTest && make lib/libCppUTest.a
55+
3856
include $(CPPUTEST_HOME)/build/MakefileWorker.mk

examples/example.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,18 @@
1010
* The general strategy is:
1111
*
1212
* 1) Initialize the connection with:
13-
* tempodb_create("YOUR_KEY", "YOUR_SECRET");
13+
* struct tempodb_config *config = tempodb_create("YOUR_KEY", "YOUR_SECRET");
1414
*
1515
* 2) Make one or more requests:
16-
* status = tempodb_write_by_key("temperature", 45.3, response_buffer, 255);
16+
* status = tempodb_write_by_key(config, "temperature", 45.3, response_buffer, 255);
1717
* if (status == -1) {
1818
* perror("Error sending to tempodb:");
1919
* } else {
2020
* printf("Response: %s\n", response_buffer);
2121
* }
2222
*
2323
* 3) Free TempoDB allocations
24-
* tempodb_destroy();
24+
* tempodb_destroy(config);
2525
*
2626
*
2727
* An important note on timestamps:
@@ -43,7 +43,7 @@
4343
*/
4444

4545
int main(int argc, char **argv) {
46-
tempodb_create("YOUR_KEY", "YOUR_SECRET");
46+
struct tempodb_config *config = tempodb_create("YOUR_KEY", "YOUR_SECRET");
4747

4848
char *response_buffer = (char *)malloc(255);
4949
int status;
@@ -60,7 +60,7 @@ int main(int argc, char **argv) {
6060
*
6161
* Also available: tempodb_write_by_id, which takes an TempoDB-generated id instead of the user-specified key
6262
*/
63-
status = tempodb_write_by_key("temperature", 45.3, response_buffer, 255);
63+
status = tempodb_write_by_key(config, "temperature", 45.3, response_buffer, 255);
6464

6565
/*
6666
* Increment By Key
@@ -76,7 +76,7 @@ int main(int argc, char **argv) {
7676
*
7777
* Also available: tempodb_increment_by_id, which takes an TempoDB-generated id instead of the user-specified key
7878
*/
79-
status = tempodb_increment_by_key("button_clicks", 1, response_buffer, 255);
79+
status = tempodb_increment_by_key(config, "button_clicks", 1, response_buffer, 255);
8080

8181
/* Bulk Write & Bulk Increment
8282
*
@@ -91,8 +91,8 @@ int main(int argc, char **argv) {
9191
updates[1] = update2;
9292

9393
/* use whichever makes sense for you */
94-
status = tempodb_bulk_write(updates, 2, response_buffer, 255);
95-
status = tempodb_bulk_increment(updates, 2, response_buffer, 255);
94+
status = tempodb_bulk_write(config, updates, 2, response_buffer, 255);
95+
status = tempodb_bulk_increment(config, updates, 2, response_buffer, 255);
9696

9797
free(updates);
9898

@@ -103,5 +103,5 @@ int main(int argc, char **argv) {
103103
}
104104

105105
free(response_buffer);
106-
tempodb_destroy();
106+
tempodb_destroy(config);
107107
}

include/tempodb/tempodb.h

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,27 +9,30 @@
99
#define TEMPODB_GET "GET"
1010
#define TEMPODB_POST "POST"
1111

12+
typedef struct tempodb_config tempodb_config;
13+
typedef struct tempodb_bulk_update tempodb_bulk_update;
14+
1215
enum id_or_key {TEMPODB_ID, TEMPODB_KEY};
1316

14-
struct tempodb_bulk_update {
17+
struct tempodb_bulk_update{
1518
const char *series;
1619
enum id_or_key type;
1720
float value;
1821
};
1922

20-
void tempodb_create(const char *key, const char *secret);
21-
void tempodb_destroy(void);
23+
tempodb_config * tempodb_create(const char *key, const char *secret);
24+
void tempodb_destroy(tempodb_config *config);
2225

23-
void tempodb_build_query(char *buffer, const size_t buffer_size, const char *verb, const char *path, const char *payload);
26+
void tempodb_build_query(tempodb_config *config, char *buffer, const size_t buffer_size, const char *verb, const char *path, const char *payload);
2427

25-
int tempodb_write_by_id(const char *series_id, const float value, char *response_buffer, const ssize_t response_buffer_size);
26-
int tempodb_write_by_key(const char *series_key, const float value, char *response_buffer, const ssize_t response_buffer_size);
28+
int tempodb_write_by_id(tempodb_config *config, const char *series_id, const float value, char *response_buffer, const ssize_t response_buffer_size);
29+
int tempodb_write_by_key(tempodb_config *config, const char *series_key, const float value, char *response_buffer, const ssize_t response_buffer_size);
2730

28-
int tempodb_increment_by_key(const char *series_key, const float value, char *response_buffer, const ssize_t response_buffer_size);
29-
int tempodb_increment_by_id(const char *series_id, const float value, char *response_buffer, const ssize_t response_buffer_size);
31+
int tempodb_increment_by_key(tempodb_config *config, const char *series_key, const float value, char *response_buffer, const ssize_t response_buffer_size);
32+
int tempodb_increment_by_id(tempodb_config *config, const char *series_id, const float value, char *response_buffer, const ssize_t response_buffer_size);
3033

31-
int tempodb_bulk_increment(const struct tempodb_bulk_update *updates, ssize_t update_count, char *response_buffer, const ssize_t response_buffer_size);
32-
int tempodb_bulk_write(const struct tempodb_bulk_update *updates, ssize_t update_count, char *response_buffer, const ssize_t response_buffer_size);
34+
int tempodb_bulk_increment(tempodb_config *config, const tempodb_bulk_update *updates, ssize_t update_count, char *response_buffer, const ssize_t response_buffer_size);
35+
int tempodb_bulk_write(tempodb_config *config, const tempodb_bulk_update *updates, ssize_t update_count, char *response_buffer, const ssize_t response_buffer_size);
3336

3437
#define ACCESS_KEY_SIZE 32
3538

lib/test/.git_empty_dir

Whitespace-only changes.

mocks/TCPSocketStub.c

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,26 +73,22 @@ void set_test_response(const char *buffer) {
7373
response_buffer_bytes_sent = 0;
7474
}
7575

76-
const char * test_ip(void) {
77-
return "1.2.3.4";
78-
}
79-
8076
void test_init(void) {
8177
int inet_pton_result;
8278

8379
inet_ips = malloc(32);
8480
last_request = malloc(last_request_size + 1);
8581
memset(last_request, 0, last_request_size + 1);
8682

87-
inet_pton_result = inet_pton(AF_INET, test_ip(), inet_ips);
83+
inet_pton_result = inet_pton(AF_INET, "1.2.3.4", inet_ips);
8884
if (inet_pton_result == 0) {
89-
printf("Invalid IP for testing: %s\n", test_ip());
85+
printf("Invalid IP for testing: %s\n", "1.2.3.4");
9086
exit(1);
9187
} else if (inet_pton_result == -1) {
9288
perror("Invalid address class");
9389
exit(1);
9490
}
95-
hent = (struct hostent *)malloc(sizeof(struct hostent *));
91+
hent = (struct hostent *)malloc(sizeof(struct hostent));
9692

9793
response_buffer = malloc(response_buffer_size + 1);
9894
memset(response_buffer, 0, response_buffer_size + 1);

objs/.git_empty_dir

Whitespace-only changes.

0 commit comments

Comments
 (0)