Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
rexbu committed Mar 17, 2018
1 parent 5b2da91 commit 3bf3fde
Show file tree
Hide file tree
Showing 120 changed files with 8,941 additions and 1,063 deletions.
Binary file renamed 3rdparty/cJSON/.DS_Store → .DS_Store
Binary file not shown.
Binary file renamed basic/.DS_Store → 3rdparty/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion 3rdparty/Android.mk
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include $(all-subdir-makefiles)
include $(all-subdir-makefiles)
5 changes: 0 additions & 5 deletions 3rdparty/README.md

This file was deleted.

13 changes: 0 additions & 13 deletions 3rdparty/cJSON/Android.mk

This file was deleted.

2 changes: 1 addition & 1 deletion 3rdparty/libzip/Android.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ LOCAL_PATH:= $(call my-dir)
include $(CLEAR_VARS)

LOCAL_CPP_EXTENSION := .cpp .cc
LIBZIP_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.c)
LIBZIP_SRC_FILES := $(wildcard $(LOCAL_PATH)/*.c $(LOCAL_PATH)/*.cpp)
LOCAL_C_INCLUDES := $(LOCAL_PATH)/
LOCAL_SRC_FILES := $(LIBZIP_SRC_FILES:$(LOCAL_PATH)/%=%)
LOCAL_MODULE := zip
Expand Down
3 changes: 0 additions & 3 deletions 3rdparty/libzip/Application.mk

This file was deleted.

2 changes: 1 addition & 1 deletion Android.mk
Original file line number Diff line number Diff line change
@@ -1 +1 @@
include $(all-subdir-makefiles)
include $(all-subdir-makefiles)
3 changes: 3 additions & 0 deletions Application.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# NDK_TOOLCHAIN_VERSION := 4.9
APP_STL := gnustl_static
APP_ABI := armeabi-v7a
42 changes: 29 additions & 13 deletions basic/Android.mk
Original file line number Diff line number Diff line change
@@ -1,30 +1,46 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)

LOCAL_CFLAGS += -D__ANDROID__ -g
LOCAL_CFLAGS += -D__ANDROID__ -g -DDEBUG
#APP_PLATFORM := android-19

LOCAL_C_INCLUDES = \
$(LOCAL_PATH)/../3rdparty/cJSON \
$(LOCAL_PATH)/../3rdparty/libzip \
$(LOCAL_PATH)/../3rdparty/libzippp \
$(LOCAL_PATH)/../bs
$(LOCAL_PATH)/../bs \
$(LOCAL_PATH)/

SRCFILES = $(wildcard $(LOCAL_PATH)/*.cpp $(LOCAL_PATH)/*/*.cpp)
SRCS = $(patsubst $(LOCAL_PATH)/%, ./%,$(SRCFILES))

LOCAL_SRC_FILES += \
$(SRCS)

LOCAL_STATIC_LIBRARIES := \
libbs \
libcjson \
libzippp \
libzip
#LOCAL_SHARED_LIBRARIES := libnative
#LOCAL_LDLIBS := -llog -landroid -lz -ldl

LOCAL_MODULE := basic_d

include $(BUILD_STATIC_LIBRARY)

include $(CLEAR_VARS)

LOCAL_CFLAGS += -D__ANDROID__ -g
#APP_PLATFORM := android-19

LOCAL_C_INCLUDES = \
$(LOCAL_PATH)/../3rdparty/libzip \
$(LOCAL_PATH)/../bs \
$(LOCAL_PATH)/

SRCFILES = $(wildcard $(LOCAL_PATH)/*.cpp $(LOCAL_PATH)/*/*.cpp)
SRCS = $(patsubst $(LOCAL_PATH)/%, ./%,$(SRCFILES))

LOCAL_SRC_FILES += \
$(SRCS)

LOCAL_SHARED_LIBRARIES := libnative
LOCAL_LDLIBS := -llog -landroid -lz -ldl
#LOCAL_SHARED_LIBRARIES := libnative
#LOCAL_LDLIBS := -llog -landroid -lz -ldl

LOCAL_MODULE := MobileCross
LOCAL_MODULE := basic_r

include $(BUILD_SHARED_LIBRARY)
include $(BUILD_STATIC_LIBRARY)
28 changes: 16 additions & 12 deletions basic/JSON.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "JSON.h"
#include "McZip.h"
#include <float.h>

using namespace mc;

Expand Down Expand Up @@ -326,8 +327,7 @@ double JSONObject::doubleValue(const char* name, double dv){
cJSON* json = cJSON_GetObjectItem(m_root, name);
if (json != NULL && json->type==cJSON_Number) {
return json->valuedouble;
}
else{
} else {
return dv;
}
}
Expand All @@ -336,13 +336,13 @@ bool_t JSONObject::boolValue(const char* name){
cJSON* json = cJSON_GetObjectItem(m_root, name);
if (json != NULL && json->type==cJSON_True) {
return BS_TRUE;
} else if (json != NULL && json->type==cJSON_Number) {
if (json->valueint != 0) {
return BS_TRUE;
}
}
else if(json != NULL && json->type==cJSON_True){
return BS_FALSE;
}
else{
return BS_NOTBOOL;
}

return BS_FALSE;
}

const char* JSONObject::stringValue(const char* name){
Expand Down Expand Up @@ -400,17 +400,21 @@ map<string, string> JSONObject::stringdict() {
cJSON* obj = m_root->child;
while (obj!=NULL) {
std::string s = obj->string;
if (obj->type == cJSON_False || obj->type == cJSON_True || obj->type == cJSON_Number) {
if (obj->type == cJSON_Number) {
char temp[64];
if (obj->valueint == 0) {
sprintf(temp, "%f", obj->valuedouble);
} else {
if (fabs((obj->valueint) - obj->valuedouble) <= DBL_EPSILON) {
sprintf(temp, "%d", obj->valueint);
} else {
sprintf(temp, "%f", obj->valuedouble);
}
string s(temp);
ks[obj->string] = s;
} else if (obj->type == cJSON_String) {
ks[obj->string] = obj->valuestring;
} else if (obj->type == cJSON_False) {
ks[obj->string] = "false";
} else if (obj->type == cJSON_True) {
ks[obj->string] = "true";
}

obj = obj->next;
Expand Down
1 change: 0 additions & 1 deletion basic/JSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#include <map>
#include <typeinfo>
#include "bs.h"
#include "cJSON.h"

using namespace std;
// 只支持Ojbect和Array类型拷贝
Expand Down
71 changes: 33 additions & 38 deletions basic/McHttp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,17 +143,12 @@ void HttpSession::http(const char *url, const char *method, const char *body, ui
http_set_body(h->http, body, length);
h->http_callback = callback;

display_http_log(h->http->req.mem);

void **para = (void **) malloc(sizeof(void *) * 2);
para[0] = h;
para[1] = this;
((ThreadPool *) m_thread_pool)->add(thread_http, para);

#if DEBUG
if (http_show_log) {
info_log("%s", h->http->req.mem);
}
#else
#endif
}

void HttpSession::download(const char *url, const char *path, HttpFileCallback *callback) {
Expand All @@ -168,6 +163,8 @@ void HttpSession::download(const char *url, const char *path, HttpFileCallback *
http_add_newline(h->http);
snprintf(h->path, sizeof(h->path), "%s", path);
h->file_callback = callback;

display_http_log(h->http->req.mem);

pthread_t download_thread;
pthread_create(&download_thread, NULL, thread_down, h);
Expand All @@ -187,13 +184,14 @@ void HttpSession::upload(const char *url, const char *path, vector<pair<string,
http_add_newline(h->http);
snprintf(h->path, sizeof(h->path), "%s", path);
h->file_callback = callback;

display_http_log(h->http->req.mem);

pthread_t upload_thread;
pthread_create(&upload_thread, NULL, thread_up_file, h);
}

void
HttpSession::upload(const char *url, uint8_t *data, int size, vector<pair<string, string> > auths,
void HttpSession::upload(const char *url, uint8_t *data, int size, vector<pair<string, string> > auths,
HttpFileCallback *callback) {
mc_http_data_t *h = bs_new(mc_http_data);
h->http = http_create(url, "PUT");
Expand All @@ -208,11 +206,12 @@ HttpSession::upload(const char *url, uint8_t *data, int size, vector<pair<string
mc_http_data_set(h, data, size);
h->http->body_size = (uint32_t) size;
h->file_callback = callback;


display_http_log(h->http->req.mem);

void **para = (void **) malloc(sizeof(void *) * 2);
para[0] = h;
para[1] = this;

pthread_t post_data_thread;
pthread_create(&post_data_thread, NULL, thread_post_data, para);
}
Expand All @@ -233,20 +232,14 @@ void HttpSession::postData(const char *url, uint8_t *data, int size, HttpFileCal
mc_http_data_set(h, data, size);
h->http->body_size = (uint32_t) size;
h->file_callback = callback;

display_http_log(h->http->req.mem);

void **para = (void **) malloc(sizeof(void *) * 2);
para[0] = h;
para[1] = this;

pthread_t post_data_thread;
pthread_create(&post_data_thread, NULL, thread_post_data, para);

#if DEBUG
if (http_show_log) {
info_log("%s", h->http->req.mem);
}
#else
#endif
}

void HttpSession::addHttpHeader(const char *key, const char *value) {
Expand Down Expand Up @@ -284,6 +277,15 @@ void HttpSession::clearCookie() {
m_headers.erase(cookie);
}

void HttpSession::display_http_log(const char *log) {
#if DEBUG
if (http_show_log) {
info_log("%s", log);
}
#else
#endif
}

#pragma --mark "http回调及线程"
void *thread_http(void *para) {
void **arg = (void **) para;
Expand All @@ -297,9 +299,9 @@ void *thread_http(void *para) {

// http->http会在http_perform中被删除
free(arg);
bs_delete(http->http);
bs_delete(http);
bs_delete(res);

return NULL;
}

Expand All @@ -325,8 +327,9 @@ void *thread_down(void *para) {
down->file_callback->done(res->response_code, res->response_code, res->body);
}
// http->http会在http_perform中被删除
bs_delete(down->http);
bs_delete(down);

bs_delete(res);
return NULL;
}

Expand All @@ -339,9 +342,9 @@ void *thread_up_file(void *para) {
thread_http_response(res, NULL);
up->file_callback->done(res->response_code, res->response_code, res->body);
}
// http->http会在http_perform中被删除
bs_delete(up->http);
bs_delete(up);

bs_delete(res);
return NULL;
}

Expand All @@ -355,21 +358,23 @@ void *thread_post_data(void *para) {
thread_http_response(res, (HttpSession *) arg[1]);
up->file_callback->done(res->response_code, res->response_code, res->body);
}
// http->http会在http_perform中被删除
free(arg);
bs_delete(up->http);
bs_delete(up);
bs_delete(res);
return NULL;
}

void thread_http_response(http_res_t *res, HttpSession *session) {
if (res->response_code < 0) {
const char *error = "http connect error!";
if (res->response_code <= 0) {
const char *error = "网络连接失败,请稍后再试";
if (res->response_code == BS_TIMEOUT) {
error = "http time-out";
error = "网络连接超时,请稍后再试";
}

res->body = (char *)error;
session->display_http_log(res->body);
return;
} else {
if (session != NULL) {
res->cookie = bs_strrstr(res->response.mem, "\r\nSet-Cookie");
Expand All @@ -380,15 +385,5 @@ void thread_http_response(http_res_t *res, HttpSession *session) {
}
}

#if DEBUG
if (session->http_show_log) {
if (res->response_code == HTTP_OK) {
JSONObject response(res->body);
info_log("%s", response.toString());
} else {
info_log("%s", res->response.mem);
}
}
#else
#endif
session->display_http_log(res->response.mem);
}
3 changes: 2 additions & 1 deletion basic/McHttp.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ class HttpSession{
const char* cookie();
static void setTimeout(uint32_t timeout);
static void showLog(bool show);
void display_http_log(const char *log);

static uint32_t http_timeout; // 过期时间
static bool http_show_log; // 展示日志
static bool http_show_log; // 展示日志
protected:
void setOpt(void* curl, http_method_t method, const char* body, uint32_t length);
map<string, string> m_headers;
Expand Down
1 change: 0 additions & 1 deletion basic/McReference.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ namespace mc {
bool unLock(){
if (m_is_reference && m_referencecount<=0)
{
err_log("unlock error! referencecount[%d]", m_referencecount);
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion basic/ThreadPool.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class ThreadPool{
static ThreadPool* shareInstance();
static void destroyInstance();

ThreadPool(int thread_num = 2);
ThreadPool(int thread_num = 20);
~ThreadPool();

void add(void* (*run)(void*),void* arg);
Expand Down
Loading

0 comments on commit 3bf3fde

Please sign in to comment.