Change Project Structs

This commit is contained in:
HuangXin 2018-09-18 16:09:12 +08:00
parent 4581d7a82a
commit b8320cc85a
18 changed files with 864 additions and 7139 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1909,7 +1909,7 @@ void test_nl80211(void)
nl_recvmsgs_default(sk);
}
#endif
#include <malloc.h>
int main(int argc, char **argv)
{
@ -1922,7 +1922,7 @@ int main(int argc, char **argv)
struct tm tm;
memset(&tm, 0, sizeof(struct tm));
strptime("2001-11-12 18:31:01", "%Y-%m-%d %H:%M:%S", &tm);
strftime(buf, sizeof(buf), "%d %b %Y %H:%M", &tm);
@ -2001,6 +2001,7 @@ int main(int argc, char **argv)
return 0;
}
SetHBLAutoExit(TRUE);
//SysPointMarkInit(NULL, -1, -1);
//test_task_new(__uvThreadSysPointUpload, NULL);
@ -2202,7 +2203,7 @@ int main(int argc, char **argv)
if(modIdx == 18)
{
SkinInit();
//SkinIsVerifyRes(TRUE);
SkinIsVerifyRes(TRUE);
#if 0
char* path = "/mnt/UDISK/skinupgrade.txt";
char* pUpgCmd = "[{\"createTime\":1517832224000,\"enable\":1,\"id\":170,"
@ -2237,8 +2238,9 @@ int main(int argc, char **argv)
}
#else
//const char* GetSkinsResource(const char [in] *pKeyName, int [out] *pResType, int [out] *pVersion, const char [out] **pComeFrom)
//fprintf(stdout, "[v401] = {%s}\n", GetSkinsResource("v401", NULL, NULL, NULL));
#if 0
fprintf(stdout, "[v401] = {%s}\n", GetSkinsResource("v401", NULL, NULL, NULL));
fprintf(stdout, "[v109] = {%s}\n", GetSkinsResource("v109", NULL, NULL, NULL));
fprintf(stdout, "[v311] = {%s}\n", GetSkinsResource("v311", NULL, NULL, NULL));
fprintf(stdout, "[v401] = {%s}\n", GetSkinsResource("v401", NULL, NULL, NULL));
@ -2253,6 +2255,7 @@ int main(int argc, char **argv)
fprintf(stdout, "[v401] = {%s}\n", GetSkinsResource("v401", NULL, NULL, NULL));
test_task_new(__uvTestSkin, NULL);
#endif
#endif
}
#endif

View File

@ -1,554 +0,0 @@
/*
* A generic kernel FIFO implementation
*
* Copyright (C) 2009/2010 Stefani Seibold <stefani@seibold.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
#if 0
#include <linux/kernel.h>
#include <linux/export.h>
#include <linux/slab.h>
#include <linux/err.h>
#include <linux/log2.h>
#include <linux/uaccess.h>
#include <linux/kfifo.h>
#endif
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <stdlib.h>
#include "fifo.h"
#define is_power_of_2(x) ((x) != 0 && (((x) & ((x) - 1)) == 0))
#define DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
#define min(x,y) ({ \
typeof(x) _x = (x); \
typeof(y) _y = (y); \
(void) (&_x == &_y); \
_x < _y ? _x : _y; })
#define max(x,y) ({ \
typeof(x) _x = (x); \
typeof(y) _y = (y); \
(void) (&_x == &_y); \
_x > _y ? _x : _y; })
//#define EINVAL (1)
//#define ENOMEM (2)
static inline int fls(int x);
#if defined(PLATFORM_R16) || defined(PLATFORM_R311)
static inline int constant_fls(int x)
{
int r = 32;
if (!x)
return 0;
if (!(x & 0xffff0000u)) {
x <<= 16;
r -= 16;
}
if (!(x & 0xff000000u)) {
x <<= 8;
r -= 8;
}
if (!(x & 0xf0000000u)) {
x <<= 4;
r -= 4;
}
if (!(x & 0xc0000000u)) {
x <<= 2;
r -= 2;
}
if (!(x & 0x80000000u)) {
x <<= 1;
r -= 1;
}
return r;
}
static int fls64(unsigned long long x)
{
unsigned int h = x >> 32;
if (h)
return fls(h) + 32;
return fls(x);
}
static inline int fls(int x)
{
int ret;
if (__builtin_constant_p(x))
return constant_fls(x);
asm("clz\t%0, %1" : "=r" (ret) : "r" (x));
ret = 32 - ret;
return ret;
}
#endif
#ifdef PLATFORM_CPU
#define __fls(x) (fls(x) - 1)
static __always_inline int fls64(unsigned long x)
{
if (x == 0)
return 0;
return __fls(x) + 1;
}
static inline int fls(int x)
{
int r;
long tmp = -1;
asm("bsrl %1,%0"
: "=r" (r)
: "rm" (x), "0" (tmp));
#if 0
#ifdef CONFIG_X86_64
/*
* AMD64 says BSRL won't clobber the dest reg if x==0; Intel64 says the
* dest reg is undefined if x==0, but their CPU architect says its
* value is written to set it to the same as before, except that the
* top 32 bits will be cleared.
*
* We cannot do this on 32 bits because at the very least some
* 486 CPUs did not behave this way.
*/
long tmp = -1;
asm("bsrl %1,%0"
: "=r" (r)
: "rm" (x), "0" (tmp));
#elif defined(CONFIG_X86_CMOV)
asm("bsrl %1,%0\n\t"
"cmovzl %2,%0"
: "=&r" (r) : "rm" (x), "rm" (-1));
#else
asm("bsrl %1,%0\n\t"
"jnz 1f\n\t"
"movl $-1,%0\n"
"1:" : "=r" (r) : "rm" (x));
#endif
#endif
return r + 1;
}
#endif
/*
* internal helper to calculate the unused elements in a fifo
*/
static inline unsigned int kfifo_unused(struct __kfifo *fifo)
{
return (fifo->mask + 1) - (fifo->in - fifo->out);
}
static inline unsigned fls_long(unsigned long l)
{
if (sizeof(l) == 4)
return fls(l);
return fls64(l);
}
unsigned long roundup_pow_of_two(unsigned long n)
{
return 1UL << (fls_long(n));
}
int __kfifo_alloc(struct __kfifo *fifo, unsigned int size, unsigned int esize)
{
/*
* round down to the next power of 2, since our 'let the indices
* wrap' technique works only in this case.
*/
if (!is_power_of_2(size))
size = roundup_pow_of_two(size);
fprintf(stdout, "+++++++++++kfifo malloc size = %u\n", size);
fifo->in = 0;
fifo->out = 0;
fifo->esize = esize;
if (size < 2) {
fifo->data = NULL;
fifo->mask = 0;
return -EINVAL;
}
fifo->data = malloc(size * esize);
if (!fifo->data) {
fifo->mask = 0;
return -ENOMEM;
}
fifo->mask = size - 1;
uv_mutex_init(&fifo->lock);
return 0;
}
void __kfifo_free(struct __kfifo *fifo)
{
free(fifo->data);
fifo->in = 0;
fifo->out = 0;
fifo->esize = 0;
fifo->data = NULL;
fifo->mask = 0;
}
int __kfifo_init(struct __kfifo *fifo, void *buffer,
unsigned int size, unsigned int esize)
{
size /= esize;
if (!is_power_of_2(size))
size = roundup_pow_of_two(size);
fifo->in = 0;
fifo->out = 0;
fifo->esize = esize;
fifo->data = buffer;
if (size < 2) {
fifo->mask = 0;
return -EINVAL;
}
fifo->mask = size - 1;
uv_mutex_init(&fifo->lock);
return 0;
}
static void kfifo_copy_in(struct __kfifo *fifo, const void *src,
unsigned int len, unsigned int off)
{
unsigned int size = fifo->mask + 1;
unsigned int esize = fifo->esize;
unsigned int l;
off &= fifo->mask;
if (esize != 1) {
off *= esize;
size *= esize;
len *= esize;
}
l = min(len, size - off);
memcpy(fifo->data + off, src, l);
memcpy(fifo->data, src + l, len - l);
/*
* make sure that the data in the fifo is up to date before
* incrementing the fifo->in index counter
*/
// smp_wmb();
}
unsigned int __kfifo_in(struct __kfifo *fifo,
const void *buf, unsigned int len)
{
unsigned int l;
l = kfifo_unused(fifo);
if (len > l)
len = l;
kfifo_copy_in(fifo, buf, len, fifo->in);
fifo->in += len;
return len;
}
static void kfifo_copy_out(struct __kfifo *fifo, void *dst,
unsigned int len, unsigned int off)
{
unsigned int size = fifo->mask + 1;
unsigned int esize = fifo->esize;
unsigned int l;
off &= fifo->mask;
if (esize != 1) {
off *= esize;
size *= esize;
len *= esize;
}
l = min(len, size - off);
if (dst) {
memcpy(dst, fifo->data + off, l);
memcpy(dst + l, fifo->data, len - l);
}
/*
* make sure that the data is copied before
* incrementing the fifo->out index counter
*/
// smp_wmb();
}
unsigned int __kfifo_out_peek(struct __kfifo *fifo,
void *buf, unsigned int len)
{
unsigned int l;
l = fifo->in - fifo->out;
if (len > l)
len = l;
kfifo_copy_out(fifo, buf, len, fifo->out);
return len;
}
unsigned int __kfifo_out(struct __kfifo *fifo,
void *buf, unsigned int len)
{
len = __kfifo_out_peek(fifo, buf, len);
fifo->out += len;
return len;
}
#if 0
static unsigned long kfifo_copy_from_user(struct __kfifo *fifo,
const void *from, unsigned int len, unsigned int off,
unsigned int *copied)
{
unsigned int size = fifo->mask + 1;
unsigned int esize = fifo->esize;
unsigned int l;
unsigned long ret;
off &= fifo->mask;
if (esize != 1) {
off *= esize;
size *= esize;
len *= esize;
}
l = min(len, size - off);
ret = memcpy(fifo->data + off, from, l);
if (unlikely(ret))
ret = DIV_ROUND_UP(ret + len - l, esize);
else {
ret = memcpy(fifo->data, from + l, len - l);
if (unlikely(ret))
ret = DIV_ROUND_UP(ret, esize);
}
/*
* make sure that the data in the fifo is up to date before
* incrementing the fifo->in index counter
*/
// smp_wmb();
*copied = len - ret;
/* return the number of elements which are not copied */
return ret;
}
int __kfifo_from_user(struct __kfifo *fifo, const void __user *from,
unsigned long len, unsigned int *copied)
{
unsigned int l;
unsigned long ret;
unsigned int esize = fifo->esize;
int err;
if (esize != 1)
len /= esize;
l = kfifo_unused(fifo);
if (len > l)
len = l;
ret = kfifo_copy_from_user(fifo, from, len, fifo->in, copied);
if (unlikely(ret)) {
len -= ret;
err = -EFAULT;
} else
err = 0;
fifo->in += len;
return err;
}
static unsigned long kfifo_copy_to_user(struct __kfifo *fifo, void __user *to,
unsigned int len, unsigned int off, unsigned int *copied)
{
unsigned int l;
unsigned long ret;
unsigned int size = fifo->mask + 1;
unsigned int esize = fifo->esize;
off &= fifo->mask;
if (esize != 1) {
off *= esize;
size *= esize;
len *= esize;
}
l = min(len, size - off);
ret = memcpy(to, fifo->data + off, l);
if (unlikely(ret))
ret = DIV_ROUND_UP(ret + len - l, esize);
else {
ret = memcpy(to + l, fifo->data, len - l);
if (unlikely(ret))
ret = DIV_ROUND_UP(ret, esize);
}
/*
* make sure that the data is copied before
* incrementing the fifo->out index counter
*/
//smp_wmb();
*copied = len - ret;
/* return the number of elements which are not copied */
return ret;
}
int __kfifo_to_user(struct __kfifo *fifo, void __user *to,
unsigned long len, unsigned int *copied)
{
unsigned int l;
unsigned long ret;
unsigned int esize = fifo->esize;
int err;
if (esize != 1)
len /= esize;
l = fifo->in - fifo->out;
if (len > l)
len = l;
ret = kfifo_copy_to_user(fifo, to, len, fifo->out, copied);
if (unlikely(ret)) {
len -= ret;
err = -EFAULT;
} else
err = 0;
fifo->out += len;
return err;
}
#endif
unsigned int __kfifo_max_r(unsigned int len, unsigned int recsize)
{
unsigned int max = (1 << (recsize << 3)) - 1;
if (len > max)
return max;
return len;
}
#define __KFIFO_PEEK(data, out, mask) \
((data)[(out) & (mask)])
/*
* __kfifo_peek_n internal helper function for determinate the length of
* the next record in the fifo
*/
static unsigned int __kfifo_peek_n(struct __kfifo *fifo, unsigned int recsize)
{
unsigned int l;
unsigned int mask = fifo->mask;
unsigned char *data = fifo->data;
l = __KFIFO_PEEK(data, fifo->out, mask);
if (--recsize)
l |= __KFIFO_PEEK(data, fifo->out + 1, mask) << 8;
return l;
}
#define __KFIFO_POKE(data, in, mask, val) \
( \
(data)[(in) & (mask)] = (unsigned char)(val) \
)
/*
* __kfifo_poke_n internal helper function for storeing the length of
* the record into the fifo
*/
static void __kfifo_poke_n(struct __kfifo *fifo, unsigned int n, unsigned int recsize)
{
unsigned int mask = fifo->mask;
unsigned char *data = fifo->data;
__KFIFO_POKE(data, fifo->in, mask, n);
if (recsize > 1)
__KFIFO_POKE(data, fifo->in + 1, mask, n >> 8);
}
unsigned int __kfifo_len_r(struct __kfifo *fifo, unsigned int recsize)
{
return __kfifo_peek_n(fifo, recsize);
}
unsigned int __kfifo_in_r(struct __kfifo *fifo, const void *buf,
unsigned int len, unsigned int recsize)
{
if (len + recsize > kfifo_unused(fifo))
return 0;
__kfifo_poke_n(fifo, len, recsize);
kfifo_copy_in(fifo, buf, len, fifo->in + recsize);
fifo->in += len + recsize;
return len;
}
static unsigned int kfifo_out_copy_r(struct __kfifo *fifo,
void *buf, unsigned int len, unsigned int recsize, unsigned int *n)
{
*n = __kfifo_peek_n(fifo, recsize);
if (len > *n)
len = *n;
kfifo_copy_out(fifo, buf, len, fifo->out + recsize);
return len;
}
unsigned int __kfifo_out_peek_r(struct __kfifo *fifo, void *buf,
unsigned int len, unsigned int recsize)
{
unsigned int n;
if (fifo->in == fifo->out)
return 0;
return kfifo_out_copy_r(fifo, buf, len, recsize, &n);
}
unsigned int __kfifo_out_r(struct __kfifo *fifo, void *buf,
unsigned int len, unsigned int recsize)
{
unsigned int n;
if (fifo->in == fifo->out)
return 0;
len = kfifo_out_copy_r(fifo, buf, len, recsize, &n);
fifo->out += n + recsize;
return len;
}
void __kfifo_skip_r(struct __kfifo *fifo, unsigned int recsize)
{
unsigned int n;
n = __kfifo_peek_n(fifo, recsize);
fifo->out += n + recsize;
}

File diff suppressed because it is too large Load Diff

View File

@ -1,320 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <sys/file.h>
#include <unistd.h>
#include <errno.h>
#include <sqlite3.h>
#include <uthash/utstring.h>
#include "log.h"
#include "libuv_dbus.h"
#include "skins.h"
#include "log.h"
typedef struct
{
sqlite3_vtab vTable;
sqlite3 *pSqlDb;
char *pTblName;
} SKINRES_VTBL, *PSKINRES_VTBL;
typedef struct
{
sqlite3_vtab_cursor base;
int count;
int eof;
} SKINRES_CURSOR, *PSKINRES_CURSOR;
static int __skin_res_destructor(sqlite3_vtab *pVtab)
{
PSKINRES_VTBL p = (PSKINRES_VTBL)pVtab;
if(p->pTblName != NULL)
{
free(p->pTblName);
p->pTblName = NULL;
}
sqlite3_free(p);
return 0;
}
static int __skin_res_create(sqlite3 *pDb,
void *pAux,
int argc, const char * const *argv,
sqlite3_vtab **pp_vt,
char **pzErr)
{
UT_string *pSqlCmd;
int rc = SQLITE_OK;
PSKINRES_VTBL pVTbl;
/* Allocate the sqlite3_vtab/example_vtab structure itself */
pVTbl = (PSKINRES_VTBL)sqlite3_malloc(sizeof(SKINRES_VTBL));
if(pVTbl == NULL)
{
return SQLITE_NOMEM;
}
pVTbl->pSqlDb = pDb;
pVTbl->pTblName = strdup(argv[2]);
utstring_new(pSqlCmd);
if(strcmp(argv[0], RES_MODE_NAME) == 0)
{
utstring_printf(pSqlCmd, CREATE_RES_TBL_SQL, "");
}
else
{
utstring_printf(pSqlCmd, CREATE_SKIN_TBL_SQL, "");
}
/* Declare the vtable's structure */
rc = sqlite3_declare_vtab(pDb, utstring_body(pSqlCmd));
utstring_free(pSqlCmd);
if(rc != SQLITE_OK)
{
__skin_res_destructor((sqlite3_vtab*)pVTbl);
return SQLITE_ERROR;
}
/* Success. Set *pp_vt and return */
*pp_vt = &pVTbl->vTable;
return SQLITE_OK;
}
static int __skin_res_connect( sqlite3 *db, void *p_aux,
int argc, const char * const *argv,
sqlite3_vtab **pp_vt, char **pzErr )
{
return __skin_res_create(db, p_aux, argc, argv, pp_vt, pzErr);
}
static int __skin_res_disconnect(sqlite3_vtab *pVtab)
{
return __skin_res_destructor(pVtab);
}
static int __skin_res_destroy(sqlite3_vtab *pVtab)
{
int rc = SQLITE_OK;
//PSKINRES_VTBL p = (PSKINRES_VTBL)pVtab;
if(rc == SQLITE_OK)
{
rc = __skin_res_destructor(pVtab);
}
return rc;
}
static int __skin_res_open(sqlite3_vtab *pVTab, sqlite3_vtab_cursor **ppCursor)
{
PSKINRES_CURSOR pCur = (PSKINRES_CURSOR)sqlite3_malloc(sizeof(SKINRES_CURSOR));
*ppCursor = (sqlite3_vtab_cursor*)pCur;
return (pCur ? SQLITE_OK : SQLITE_NOMEM);
}
static int __skin_res_close(sqlite3_vtab_cursor *cur)
{
PSKINRES_CURSOR pCur = (PSKINRES_CURSOR)cur;
sqlite3_free(pCur);
return SQLITE_OK;
}
static int __skin_res_eof(sqlite3_vtab_cursor *cur)
{
return ((PSKINRES_CURSOR)cur)->eof;
}
static int __skin_res_next(sqlite3_vtab_cursor *pInCur)
{
PSKINRES_CURSOR pCur = (PSKINRES_CURSOR)pInCur;
//PSKINRES_VTBL pvTable = (PSKINRES_VTBL)pInCur->pVtab;
/* Increment the current row count. */
pCur->count += 1;
/* Arbitrary contstraint: when we get to 10 rows, then stop. */
if(pCur->count >= SkinsDefaultSize())
{
pCur->eof = 1;
}
return SQLITE_OK;
}
static int __skin_res_column(sqlite3_vtab_cursor *pInCur, sqlite3_context *ctx, int iCol)
{
PSKINRES_CURSOR pCur = (PSKINRES_CURSOR)pInCur;
PSKIN_RES_INFO pItem = SkinsItemById(pCur->count);
//PSKINRES_VTBL pvTable = (PSKINRES_VTBL)pInCur->pVtab;
/* Just return the ordinal of the column requested. */
switch(iCol)
{
case 0:
sqlite3_result_int(ctx, pCur->count);
break;
case 1:
sqlite3_result_text(ctx, pItem->pResVer, strlen(pItem->pResVer), SQLITE_STATIC);
break;
case 2:
sqlite3_result_text(ctx, pItem->pLocalPath, strlen(pItem->pLocalPath), SQLITE_STATIC);
break;
case 3:
sqlite3_result_text(ctx, pItem->pLocalPath, strlen(pItem->pLocalPath), SQLITE_STATIC);
break;
case 4:
sqlite3_result_text(ctx, pItem->pMD5Chksum, strlen(pItem->pMD5Chksum), SQLITE_STATIC);
break;
}
return SQLITE_OK;
}
static int __skin_cfg_column(sqlite3_vtab_cursor *pInCur, sqlite3_context *ctx, int iCol)
{
PSKINRES_CURSOR pCur = (PSKINRES_CURSOR)pInCur;
PSKIN_RES_INFO pItem = SkinsItemById(pCur->count);
//PSKINRES_VTBL pvTable = (PSKINRES_VTBL)pInCur->pVtab;
/* Just return the ordinal of the column requested. */
switch(iCol)
{
case 0:
sqlite3_result_int(ctx, pCur->count);
break;
case 1:
sqlite3_result_text(ctx, pItem->pKeyName, strlen(pItem->pKeyName), SQLITE_STATIC);
break;
case 2:
sqlite3_result_int(ctx, pItem->resType);
break;
case 3:
sqlite3_result_int(ctx, 0);
break;
case 4:
sqlite3_result_int(ctx, pCur->count);
break;
case 5:
sqlite3_result_text(ctx, "", 0, SQLITE_STATIC);
break;
}
return SQLITE_OK;
}
static int __skin_res_rowid(sqlite3_vtab_cursor *pInCur, sqlite_int64 *p_rowid)
{
PSKINRES_CURSOR pCur = (PSKINRES_CURSOR)pInCur;
/* Just use the current row count as the rowid. */
*p_rowid = pCur->count;
return SQLITE_OK;
}
static int __skin_res_filter( sqlite3_vtab_cursor *pVtc,
int idxNum, const char *idxStr,
int argc, sqlite3_value **argv )
{
//int rc;
//int i;
/* Initialize the cursor structure. */
PSKINRES_CURSOR pCur = (PSKINRES_CURSOR)pVtc;
/* Zero rows returned thus far. */
pCur->count = 0;
/* Have not reached end of set. */
pCur->eof = 0;
/* Move cursor to first row. */
return __skin_res_next(pVtc);
}
/* Pretty involved. We don't implement in this example. */
static int __skin_res_best_index(sqlite3_vtab *pVTbl, sqlite3_index_info *pIdxInfo)
{
return SQLITE_OK;
}
static sqlite3_module g_ResModule =
{
0, /* iVersion */
__skin_res_create, /* xCreate - create a vtable */
__skin_res_connect, /* xConnect - associate a vtable with a connection */
__skin_res_best_index, /* xBestIndex - best index */
__skin_res_disconnect, /* xDisconnect - disassociate a vtable with a connection */
__skin_res_destroy, /* xDestroy - destroy a vtable */
__skin_res_open, /* xOpen - open a cursor */
__skin_res_close, /* xClose - close a cursor */
__skin_res_filter, /* xFilter - configure scan constraints */
__skin_res_next, /* xNext - advance a cursor */
__skin_res_eof, /* xEof - inidicate end of result set*/
__skin_res_column, /* xColumn - read data */
__skin_res_rowid, /* xRowid - read data */
NULL, /* xUpdate - write data */
NULL, /* xBegin - begin transaction */
NULL, /* xSync - sync transaction */
NULL, /* xCommit - commit transaction */
NULL, /* xRollback - rollback transaction */
NULL, /* xFindFunction - function overloading */
};
static sqlite3_module g_SkinModule =
{
0, /* iVersion */
__skin_res_create, /* xCreate - create a vtable */
__skin_res_connect, /* xConnect - associate a vtable with a connection */
__skin_res_best_index, /* xBestIndex - best index */
__skin_res_disconnect, /* xDisconnect - disassociate a vtable with a connection */
__skin_res_destroy, /* xDestroy - destroy a vtable */
__skin_res_open, /* xOpen - open a cursor */
__skin_res_close, /* xClose - close a cursor */
__skin_res_filter, /* xFilter - configure scan constraints */
__skin_res_next, /* xNext - advance a cursor */
__skin_res_eof, /* xEof - inidicate end of result set*/
__skin_cfg_column, /* xColumn - read data */
__skin_res_rowid, /* xRowid - read data */
NULL, /* xUpdate - write data */
NULL, /* xBegin - begin transaction */
NULL, /* xSync - sync transaction */
NULL, /* xCommit - commit transaction */
NULL, /* xRollback - rollback transaction */
NULL, /* xFindFunction - function overloading */
};
int InitSkinRomDatabase(sqlite3 *pDataBase)
{
if((sqlite3_create_module(pDataBase, SKIN_MODE_NAME, &g_SkinModule, NULL) == SQLITE_OK)
&& (sqlite3_create_module(pDataBase, RES_MODE_NAME, &g_ResModule, NULL) == SQLITE_OK))
{
return 0;
}
else
{
return -ERR_SQL_REG_MODULE;
}
}

View File

@ -354,7 +354,7 @@ static int __skinCreateCfgFile(const char* pCfgFilePath)
int rc = 0;
static sqlite3* pSqlFileDB = NULL;
UT_string *pSqlCmd = NULL;
#if 0
rc = sqlite3_open(":memory:", &g_pMemDb);
if(rc != SQLITE_OK)
@ -377,8 +377,8 @@ static int __skinCreateCfgFile(const char* pCfgFilePath)
utstring_free(pSqlCmd);
return -ERR_SQLITE3_CREATE_TABLE;
}
rc = sqlite3_open_v2(pCfgFilePath, &pSqlFileDB, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE, NULL);
#endif
rc = sqlite3_open_v2(pCfgFilePath, &pSqlFileDB, SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE , NULL);
if(rc != SQLITE_OK)
{
@ -388,6 +388,8 @@ static int __skinCreateCfgFile(const char* pCfgFilePath)
return -ERR_OPEN_SQLITE3_DB;
}
LOG_EX(LOG_Debug, "Create Database: %s\n", pCfgFilePath);
#if 0
utstring_renew(pSqlCmd);
utstring_printf(pSqlCmd, CREATE_SKIN_TBL_SQL""CREATE_RES_TBL_SQL, "", "");
@ -395,7 +397,22 @@ static int __skinCreateCfgFile(const char* pCfgFilePath)
if(rc != SQLITE_OK)
{
LOG_EX(LOG_Error, "Create Tbl %s Error: %s\n", utstring_body(pSqlCmd), pErrMsg);
LOG_EX(LOG_Error, "Create Tbl \n[%s]\n Error: %s\n", utstring_body(pSqlCmd), pErrMsg);
sqlite3_free(pErrMsg);
unlink(pCfgFilePath);
sqlite3_close(g_pMemDb);
utstring_free(pSqlCmd);
return -ERR_SQLITE3_CREATE_TABLE;
}
#else
utstring_renew(pSqlCmd);
utstring_printf(pSqlCmd, CREATE_SKIN_TBL_SQL, "");
rc = sqlite3_exec(pSqlFileDB, utstring_body(pSqlCmd), NULL, 0, &pErrMsg);
if(rc != SQLITE_OK)
{
LOG_EX(LOG_Error, "Create Tbl \n[%s]\n Error(%d): %s\n", utstring_body(pSqlCmd), rc, pErrMsg);
sqlite3_free(pErrMsg);
unlink(pCfgFilePath);
sqlite3_close(g_pMemDb);
@ -403,6 +420,21 @@ static int __skinCreateCfgFile(const char* pCfgFilePath)
return -ERR_SQLITE3_CREATE_TABLE;
}
utstring_renew(pSqlCmd);
utstring_printf(pSqlCmd, CREATE_RES_TBL_SQL, "");
rc = sqlite3_exec(pSqlFileDB, utstring_body(pSqlCmd), NULL, 0, &pErrMsg);
if(rc != SQLITE_OK)
{
LOG_EX(LOG_Error, "Create Tbl \n[%s]\n Error: %s\n", utstring_body(pSqlCmd), pErrMsg);
sqlite3_free(pErrMsg);
unlink(pCfgFilePath);
sqlite3_close(g_pMemDb);
utstring_free(pSqlCmd);
return -ERR_SQLITE3_CREATE_TABLE;
}
#endif
utstring_renew(pSqlCmd);
utstring_printf(pSqlCmd, UPGRADE_TBL_SQL_CMD, "");
rc = sqlite3_exec(pSqlFileDB, utstring_body(pSqlCmd), NULL, 0, &pErrMsg);

View File

@ -1,772 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/time.h>
#include <uv.h>
#include <dbus/dbus.h>
#include <errno.h>
#include <time.h>
#include <uthash/uthash.h>
#include "log.h"
#include "libuv_dbus.h"
#define TIMER_TIMEOUT (200)
#define IS_LEAP_YEAR(year) ((year) % 4 == 0 && ((year) % 100 != 0 || (year) % 400 == 0))
static unsigned char g_DayOfMonth[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
typedef struct
{
void* pUserData;
OnAlarmTimer pOnAlarmCb;
unsigned int alarmId;
struct tm setDateTime;
int setWeekDay;
unsigned int repeatMode;
struct tm onDateTime;
time_t onTimestamp;
unsigned int timerPriority;
UT_hash_handle hh; ///< UT Hash handle
} ALARM_ITEM_DATA, *PALARM_ITEM_DATA;
static uv_timer_t g_uvTimer;
static unsigned int g_iAlarmId = 1;
static struct tm g_LocalTime;
static time_t g_TimeStamp;
static uv_loop_t* g_pMainLoop = NULL;
static uv_rwlock_t g_uvHashRwLock;
static PALARM_ITEM_DATA g_TimerTbl = NULL;
const char* DumpTimerRepeatModeString(int mode)
{
switch(mode & 0xFF)
{
case REPEAT_MODE_NONE: return "NONE";
case REPEAT_MODE_EVERY_DAY: return "EVERY_DAY";
case REPEAT_MODE_WORKDAY: return "WORKDAY";
case REPEAT_MODE_HOLIDAY: return ("REPEAT_MODE_HOLIDAY");
case REPEAT_MODE_WEEKEND: return "WEEKEND";
case REPEAT_MODE_WEEKDAY: return "WEEKDAY";
case REPEAT_MODE_EVERY_MONTH_DAY: return "EVERY_MONTH_DAY";
case REPEAT_MODE_EVERY_YEAR_DAY: return "EVERY_YEAR_DAY";
case REPEAT_MODE_EVERY_TIME: return ("EVERY_TIME");
case REPEAT_MODE_MONTH_LAST_DAY: return "REPEAT_MODE_MONTH_LAST_DAY";
default: return ("Unknown Mode");
}
}
static int __timestampSort(PALARM_ITEM_DATA p1, PALARM_ITEM_DATA p2)
{
if(p1->onTimestamp == p2->onTimestamp)
{
return (p2->timerPriority - p1->timerPriority);
}
else
{
return (p1->onTimestamp - p2->onTimestamp);
}
}
static int __getNextOnTimestamp(PALARM_ITEM_DATA pInfo)
{
int ret;
struct tm setTime;
time_t timestamp;
if(pInfo == NULL)
{
return (-ERR_INPUT_PARAMS);
}
if(pInfo->repeatMode == REPEAT_MODE_NONE)
{
pInfo->onTimestamp = 0;
return (-ERR_INPUT_PARAMS);
}
timestamp = pInfo->onTimestamp + 24 * 3600;
pInfo->onTimestamp = timestamp;
localtime_r(&timestamp, &setTime);
switch(pInfo->repeatMode)
{
case REPEAT_MODE_EVERY_DAY:
localtime_r(&timestamp, &pInfo->onDateTime);
break;
case REPEAT_MODE_WORKDAY:
do
{
ret = CurrentIsWorkDay(setTime.tm_year, setTime.tm_yday);
if(ret == 0)
{
timestamp = mktime(&setTime) + 24 * 3600;
localtime_r(&timestamp, &setTime);
}
} while(ret == 0);
if(ret < 0)
{
pInfo->onTimestamp = 0;
pInfo->onDateTime.tm_year = -1;
pInfo->onDateTime.tm_mon = -1;
pInfo->onDateTime.tm_mday = -1;
}
else
{
pInfo->onDateTime.tm_year = setTime.tm_year;
pInfo->onDateTime.tm_mon = setTime.tm_mon;
pInfo->onDateTime.tm_mday = setTime.tm_mday;
pInfo->onTimestamp = mktime(&pInfo->onDateTime);
}
break;
case REPEAT_MODE_HOLIDAY:
do
{
ret = CurrentIsWorkDay(setTime.tm_year, setTime.tm_yday);
if(ret == 0)
{
timestamp = mktime(&setTime) + 24 * 3600;
localtime_r(&timestamp, &setTime);
}
} while(ret == 1);
if(ret < 0)
{
pInfo->onTimestamp = 0;
pInfo->onDateTime.tm_year = -1;
pInfo->onDateTime.tm_mon = -1;
pInfo->onDateTime.tm_mday = -1;
}
else
{
pInfo->onDateTime.tm_year = setTime.tm_year;
pInfo->onDateTime.tm_mon = setTime.tm_mon;
pInfo->onDateTime.tm_mday = setTime.tm_mday;
pInfo->onTimestamp = mktime(&pInfo->onDateTime);
}
break;
case REPEAT_MODE_WEEKEND:
while(setTime.tm_wday != 0 && setTime.tm_wday != 6)
{
timestamp = mktime(&setTime) + 24 * 3600;
localtime_r(&timestamp, &setTime);
}
pInfo->onDateTime.tm_year = setTime.tm_year;
pInfo->onDateTime.tm_mon = setTime.tm_mon;
pInfo->onDateTime.tm_mday = setTime.tm_mday;
pInfo->onTimestamp = mktime(&pInfo->onDateTime);
break;
case REPEAT_MODE_WEEKDAY:
if(pInfo->setDateTime.tm_wday == 0)
{
pInfo->setDateTime.tm_wday = 1 << 0;
}
else if(pInfo->setDateTime.tm_wday & (1 << 7))
{
pInfo->setDateTime.tm_wday = 1 << 0;
}
while(((1 << setTime.tm_wday) & pInfo->setDateTime.tm_wday) == 0)
{
timestamp = mktime(&setTime) + 24 * 3600;
localtime_r(&timestamp, &setTime);
}
pInfo->onDateTime.tm_year = setTime.tm_year;
pInfo->onDateTime.tm_mon = setTime.tm_mon;
pInfo->onDateTime.tm_mday = setTime.tm_mday;
pInfo->onTimestamp = mktime(&pInfo->onDateTime);
break;
case REPEAT_MODE_EVERY_TIME:
timestamp = mktime(&g_LocalTime);
if(pInfo->setDateTime.tm_hour > 0)
{
timestamp += pInfo->setDateTime.tm_hour * 3600;
}
if(pInfo->setDateTime.tm_min > 0)
{
timestamp += pInfo->setDateTime.tm_min * 60;
}
if(pInfo->setDateTime.tm_sec > 0)
{
timestamp += pInfo->setDateTime.tm_sec;
}
localtime_r(&timestamp, &pInfo->onDateTime);
pInfo->onTimestamp = timestamp;
break;
case REPEAT_MODE_MONTH_LAST_DAY:
if(pInfo->onDateTime.tm_mon < 11)
{
pInfo->onDateTime.tm_mon++;
}
else
{
pInfo->onDateTime.tm_mon = 0;
pInfo->onDateTime.tm_year++;
}
pInfo->onDateTime.tm_mday = g_DayOfMonth[pInfo->onDateTime.tm_mon];
if(IS_LEAP_YEAR(pInfo->onDateTime.tm_year) && (pInfo->onDateTime.tm_mon == 1))
{
pInfo->onDateTime.tm_mday += 1;
}
pInfo->onTimestamp = mktime(&pInfo->onDateTime);
break;
}
return (0);
}
static int __getOnTimestamp(PALARM_ITEM_DATA pInfo)
{
int ret = 0;
struct tm setTime;
time_t timestamp;
if(pInfo == NULL)
{
return (-ERR_INPUT_PARAMS);
}
if(pInfo->setDateTime.tm_hour == -1)
{
pInfo->onDateTime.tm_hour = g_LocalTime.tm_hour;
}
else
{
pInfo->onDateTime.tm_hour = pInfo->setDateTime.tm_hour;
}
if(pInfo->setDateTime.tm_min == -1)
{
pInfo->onDateTime.tm_min = g_LocalTime.tm_min;
}
else
{
pInfo->onDateTime.tm_min = pInfo->setDateTime.tm_min;
}
if(pInfo->setDateTime.tm_sec == -1)
{
pInfo->onDateTime.tm_sec = g_LocalTime.tm_sec;
}
else
{
pInfo->onDateTime.tm_sec = pInfo->setDateTime.tm_sec;
}
switch(pInfo->repeatMode)
{
case REPEAT_MODE_EVERY_MONTH_DAY:
pInfo->setDateTime.tm_mon = -1;
pInfo->setDateTime.tm_year = -1;
case REPEAT_MODE_EVERY_YEAR_DAY:
pInfo->setDateTime.tm_year = -1;
case REPEAT_MODE_NONE:
if(pInfo->setDateTime.tm_year == -1)
{
pInfo->onDateTime.tm_year = g_LocalTime.tm_year;
}
else
{
pInfo->onDateTime.tm_year = pInfo->setDateTime.tm_year;
}
if(pInfo->setDateTime.tm_mon == -1)
{
pInfo->onDateTime.tm_mon = g_LocalTime.tm_mon;
}
else
{
pInfo->onDateTime.tm_mon = pInfo->setDateTime.tm_mon;
}
if(pInfo->setDateTime.tm_mday == -1)
{
pInfo->onDateTime.tm_mday = g_LocalTime.tm_mday;
}
else
{
pInfo->onDateTime.tm_mday = pInfo->setDateTime.tm_mday;
}
break;
case REPEAT_MODE_EVERY_DAY:
case REPEAT_MODE_WORKDAY:
case REPEAT_MODE_WEEKEND:
case REPEAT_MODE_WEEKDAY:
case REPEAT_MODE_EVERY_TIME:
case REPEAT_MODE_HOLIDAY:
pInfo->onDateTime.tm_year = g_LocalTime.tm_year;
pInfo->onDateTime.tm_mon = g_LocalTime.tm_mon;
pInfo->onDateTime.tm_mday = g_LocalTime.tm_mday;
break;
case REPEAT_MODE_MONTH_LAST_DAY:
pInfo->onDateTime.tm_year = g_LocalTime.tm_year;
pInfo->onDateTime.tm_mon = g_LocalTime.tm_mon;
pInfo->onDateTime.tm_mday = g_DayOfMonth[g_LocalTime.tm_mon];
if(IS_LEAP_YEAR(g_LocalTime.tm_year) && (g_LocalTime.tm_mon == 1))
{
pInfo->onDateTime.tm_mday += 1;
}
break;
}
pInfo->onDateTime.tm_wday = g_LocalTime.tm_wday;
pInfo->onDateTime.tm_yday = g_LocalTime.tm_yday;
pInfo->onTimestamp = mktime(&pInfo->onDateTime);
if(pInfo->repeatMode == REPEAT_MODE_NONE)
{
return (0);
}
memcpy(&setTime, &g_LocalTime, sizeof(struct tm));
if(mktime(&setTime) > (pInfo->onTimestamp + 1))
{
if(pInfo->repeatMode == REPEAT_MODE_EVERY_MONTH_DAY)
{
if(pInfo->onDateTime.tm_mon < 11)
{
pInfo->onDateTime.tm_mon++;
}
else
{
pInfo->onDateTime.tm_mon = 0;
pInfo->onDateTime.tm_year++;
}
pInfo->onTimestamp = mktime(&pInfo->onDateTime);
return (0);
}
else if(pInfo->repeatMode == REPEAT_MODE_EVERY_YEAR_DAY)
{
pInfo->onDateTime.tm_year++;
pInfo->onTimestamp = mktime(&pInfo->onDateTime);
return (0);
}
else if(pInfo->repeatMode == REPEAT_MODE_MONTH_LAST_DAY)
{
if(pInfo->onDateTime.tm_mon < 11)
{
pInfo->onDateTime.tm_mon++;
}
else
{
pInfo->onDateTime.tm_mon = 0;
pInfo->onDateTime.tm_year++;
}
pInfo->onDateTime.tm_mday = g_DayOfMonth[pInfo->onDateTime.tm_mon];
if(IS_LEAP_YEAR(pInfo->onDateTime.tm_year) && (pInfo->onDateTime.tm_mon == 1))
{
pInfo->onDateTime.tm_mday += 1;
}
pInfo->onTimestamp = mktime(&pInfo->onDateTime);
return (0);
}
else
{
timestamp = mktime(&setTime) + 24 * 3600;
localtime_r(&timestamp, &setTime);
}
}
switch(pInfo->repeatMode)
{
case REPEAT_MODE_EVERY_DAY:
pInfo->onDateTime.tm_year = setTime.tm_year;
pInfo->onDateTime.tm_mon = setTime.tm_mon;
pInfo->onDateTime.tm_mday = setTime.tm_mday;
pInfo->onTimestamp = mktime(&pInfo->onDateTime);
break;
case REPEAT_MODE_WORKDAY:
do
{
ret = CurrentIsWorkDay(setTime.tm_year, setTime.tm_yday);
if(ret == 0)
{
timestamp = mktime(&setTime) + 24 * 3600;
localtime_r(&timestamp, &setTime);
}
} while(ret == 0);
if(ret < 0)
{
pInfo->onTimestamp = 0;
pInfo->onDateTime.tm_year = -1;
pInfo->onDateTime.tm_mon = -1;
pInfo->onDateTime.tm_mday = -1;
}
else
{
pInfo->onDateTime.tm_year = setTime.tm_year;
pInfo->onDateTime.tm_mon = setTime.tm_mon;
pInfo->onDateTime.tm_mday = setTime.tm_mday;
pInfo->onTimestamp = mktime(&pInfo->onDateTime);
}
break;
case REPEAT_MODE_HOLIDAY:
do
{
ret = CurrentIsWorkDay(setTime.tm_year, setTime.tm_yday);
if(ret == 0)
{
timestamp = mktime(&setTime) + 24 * 3600;
localtime_r(&timestamp, &setTime);
}
} while(ret == 1);
if(ret < 0)
{
pInfo->onTimestamp = 0;
pInfo->onDateTime.tm_year = -1;
pInfo->onDateTime.tm_mon = -1;
pInfo->onDateTime.tm_mday = -1;
}
else
{
pInfo->onDateTime.tm_year = setTime.tm_year;
pInfo->onDateTime.tm_mon = setTime.tm_mon;
pInfo->onDateTime.tm_mday = setTime.tm_mday;
pInfo->onTimestamp = mktime(&pInfo->onDateTime);
}
break;
case REPEAT_MODE_WEEKEND:
while(setTime.tm_wday != 0 && setTime.tm_wday != 6)
{
timestamp = mktime(&setTime) + 24 * 3600;
localtime_r(&timestamp, &setTime);
}
pInfo->onDateTime.tm_year = setTime.tm_year;
pInfo->onDateTime.tm_mon = setTime.tm_mon;
pInfo->onDateTime.tm_mday = setTime.tm_mday;
pInfo->onTimestamp = mktime(&pInfo->onDateTime);
break;
case REPEAT_MODE_WEEKDAY:
if(pInfo->setDateTime.tm_wday == 0)
{
pInfo->setDateTime.tm_wday = 1 << 0;
}
else if(pInfo->setDateTime.tm_wday & (1 << 7))
{
pInfo->setDateTime.tm_wday = 1 << 0;
}
while(((1 << setTime.tm_wday) & pInfo->setDateTime.tm_wday) == 0)
{
timestamp = mktime(&setTime) + 24 * 3600;
localtime_r(&timestamp, &setTime);
}
pInfo->onDateTime.tm_year = setTime.tm_year;
pInfo->onDateTime.tm_mon = setTime.tm_mon;
pInfo->onDateTime.tm_mday = setTime.tm_mday;
pInfo->onTimestamp = mktime(&pInfo->onDateTime);
break;
case REPEAT_MODE_EVERY_TIME:
timestamp = mktime(&g_LocalTime);
if(pInfo->setDateTime.tm_hour > 0)
{
timestamp += pInfo->setDateTime.tm_hour * 3600;
}
if(pInfo->setDateTime.tm_min > 0)
{
timestamp += pInfo->setDateTime.tm_min * 60;
}
if(pInfo->setDateTime.tm_sec > 0)
{
timestamp += pInfo->setDateTime.tm_sec;
}
localtime_r(&timestamp, &pInfo->onDateTime);
pInfo->onTimestamp = timestamp;
break;
}
return (0);
}
static void __timerout200msCb(uv_timer_t *pTimer)
{
PALARM_ITEM_DATA pItem = NULL, pTemp = NULL;
// upgrade current time and timestamp
g_TimeStamp = time((time_t*)NULL);
localtime_r(&g_TimeStamp, &g_LocalTime);
uv_rwlock_wrlock(&g_uvHashRwLock);
HASH_ITER(hh, g_TimerTbl, pItem, pTemp)
{
// cleanup out of time more than 10s timer
if(g_TimeStamp - pItem->onTimestamp > 10)
{
LOG_EX(LOG_Warn, "Remove out of time timer: %u, %ld, %ld\n", pItem->alarmId, g_TimeStamp, pItem->onTimestamp);
HASH_DEL(g_TimerTbl, pItem);
free(pItem);
continue;
}
// timer not on time
if(pItem->onTimestamp != g_TimeStamp)
{
break;
}
// timer on time, call callback
if(pItem->pOnAlarmCb)
{
pItem->pOnAlarmCb(pItem->alarmId, g_TimeStamp, pItem->pUserData);
}
//LOG_EX(LOG_Debug, "Timer %d Alarming..................\n", pItem->alarmId);
// cleanup not repeat timer
if(pItem->repeatMode == REPEAT_MODE_NONE)
{
HASH_DEL(g_TimerTbl, pItem);
free(pItem);
}
else
{
// calc next on time
int ret = __getNextOnTimestamp(pItem);
if(ret != 0 || pItem->onTimestamp == 0)
{
// some error, remove it
LOG_EX(LOG_Error, "Timer %d repeat error: ret = %d, timestamp = %u\n", pItem->alarmId, ret, pItem->onTimestamp);
HASH_DEL(g_TimerTbl, pItem);
free(pItem);
}
else
{
// resort table by upgrade timestamp
HASH_SORT(g_TimerTbl, __timestampSort);
// show log
LOG_EX(LOG_Debug, "Readd Timer: %u at [%04u-%02u-%02u %02u:%02u:%02u], repMode = %s, Timestamp = %u\n",
pItem->alarmId,
pItem->onDateTime.tm_year + 1900,
pItem->onDateTime.tm_mon + 1,
pItem->onDateTime.tm_mday,
pItem->onDateTime.tm_hour,
pItem->onDateTime.tm_min,
pItem->onDateTime.tm_sec,
DumpTimerRepeatModeString(pItem->repeatMode),
pItem->onTimestamp);
}
}
}
uv_rwlock_wrunlock(&g_uvHashRwLock);
}
int AlarmTimerInit(uv_loop_t* pLoop)
{
g_pMainLoop = pLoop;
uv_rwlock_init(&g_uvHashRwLock);
uv_timer_init(g_pMainLoop, &g_uvTimer);
g_TimeStamp = time((time_t*)NULL);
localtime_r(&g_TimeStamp, &g_LocalTime);
g_iAlarmId = 1;
uv_timer_start(&g_uvTimer, __timerout200msCb, 0, TIMER_TIMEOUT);
}
int AlarmTimerCleanup(void)
{
uv_timer_stop(&g_uvTimer);
uv_rwlock_destroy(&g_uvHashRwLock);
if(g_pMainLoop != NULL)
{
AlarmTimerInit(g_pMainLoop);
}
}
int AlarmTimerRemove(unsigned int tmId)
{
PALARM_ITEM_DATA pItem = NULL;
uv_rwlock_rdlock(&g_uvHashRwLock);
HASH_FIND_INT(g_TimerTbl, &tmId, pItem);
uv_rwlock_rdunlock(&g_uvHashRwLock);
if(pItem == NULL)
{
LOG_EX(LOG_Error, "Can't find item: %u\n", tmId);
return (-ERR_NO_ITEMS);
}
uv_rwlock_wrlock(&g_uvHashRwLock);
HASH_DEL(g_TimerTbl, pItem);
uv_rwlock_wrunlock(&g_uvHashRwLock);
free(pItem);
return (tmId);
}
unsigned int AlarmTimerAdd(int year,
int month,
int day,
int hour,
int minute,
int second,
int weekDay,
int repMode,
OnAlarmTimer pOnTimerCb,
int priority,
void *pUserData,
int *pError)
{
int et;
PALARM_ITEM_DATA pAlarmData = NULL;
if(pOnTimerCb == NULL)
{
LOG_EX(LOG_Error, "Input Params Error: pOnTimerCb = %p\n", pOnTimerCb);
if(pError)
{
*pError = -ERR_INPUT_PARAMS;
}
return (0xFFFFFFFF);
}
g_TimeStamp = time((time_t*)NULL);
localtime_r(&g_TimeStamp, &g_LocalTime);
pAlarmData = (PALARM_ITEM_DATA)malloc(sizeof(ALARM_ITEM_DATA));
if(pAlarmData == NULL)
{
LOG_EX(LOG_Error, "Malloc Memory Error\n");
if(pError)
{
*pError = -ERR_MALLOC_MEMORY;
}
return (0xFFFFFFFF);
}
memset(pAlarmData, 0, sizeof(ALARM_ITEM_DATA));
// save input params
pAlarmData->setDateTime.tm_year = year;
pAlarmData->setDateTime.tm_mon = month;
pAlarmData->setDateTime.tm_mday = day;
pAlarmData->setDateTime.tm_hour = hour;
pAlarmData->setDateTime.tm_min = minute;
pAlarmData->setDateTime.tm_sec = second;
pAlarmData->setDateTime.tm_wday = weekDay;
pAlarmData->repeatMode = repMode;
pAlarmData->pOnAlarmCb = pOnTimerCb;
pAlarmData->pUserData = pUserData;
pAlarmData->timerPriority = priority;
// get timer on time
__getOnTimestamp(pAlarmData);
// check on time
et = pAlarmData->onTimestamp - mktime(&g_LocalTime);
if(et < -1 || pAlarmData->onTimestamp == 0)
{
LOG_EX(LOG_Debug, "Add Timer Error: [%04u-%02u-%02u %02u:%02u:%02u], repMode = %s(%u), %d, %u/%u\n",
pAlarmData->setDateTime.tm_year + 1900,
pAlarmData->setDateTime.tm_mon + 1,
pAlarmData->setDateTime.tm_mday,
pAlarmData->setDateTime.tm_hour,
pAlarmData->setDateTime.tm_min,
pAlarmData->setDateTime.tm_sec,
DumpTimerRepeatModeString(repMode), repMode,
et, pAlarmData->onTimestamp, mktime(&g_LocalTime));
if(pError)
{
*pError = -ERR_INPUT_PARAMS;
}
return (0xFFFFFFFF);
}
if(pError)
{
*pError = 0;
}
// upgrade time global id
pAlarmData->alarmId = __sync_fetch_and_add(&g_iAlarmId, 1);
// save new timer to hash table, and sort it by timestamp
uv_rwlock_wrlock(&g_uvHashRwLock);
HASH_ADD_INT(g_TimerTbl, alarmId, pAlarmData);
HASH_SORT(g_TimerTbl, __timestampSort);
uv_rwlock_wrunlock(&g_uvHashRwLock);
LOG_EX(LOG_Debug, "Add: %u [%04u-%02u-%02u %02u:%02u:%02u] at [%04u-%02u-%02u %02u:%02u:%02u], repMode = %s, priority = %d, Timestamp = %u\n",
pAlarmData->alarmId,
(pAlarmData->setDateTime.tm_year == -1) ? 1900 : pAlarmData->setDateTime.tm_year + 1900,
(pAlarmData->setDateTime.tm_mon == -1) ? 0 : pAlarmData->setDateTime.tm_mon + 1,
(pAlarmData->setDateTime.tm_mday == -1) ? 0 : pAlarmData->setDateTime.tm_mday,
(pAlarmData->setDateTime.tm_hour == -1) ? 0 : pAlarmData->setDateTime.tm_hour,
(pAlarmData->setDateTime.tm_min == -1) ? 0 : pAlarmData->setDateTime.tm_min,
(pAlarmData->setDateTime.tm_sec == -1) ? 0 : pAlarmData->setDateTime.tm_sec,
pAlarmData->onDateTime.tm_year + 1900,
pAlarmData->onDateTime.tm_mon + 1,
pAlarmData->onDateTime.tm_mday,
pAlarmData->onDateTime.tm_hour,
pAlarmData->onDateTime.tm_min,
pAlarmData->onDateTime.tm_sec,
DumpTimerRepeatModeString(repMode),
pAlarmData->timerPriority,
pAlarmData->onTimestamp);
return (pAlarmData->alarmId);
}

View File

@ -0,0 +1,505 @@
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/time.h>
#include <linux/input.h>
#include <sys/shm.h>
#include <sys/msg.h>
#include <sys/sendfile.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/vfs.h>
#include "log.h"
#include "libuv_dbus.h"
int CopyFile(const char *pSrc, const char *pDest)
{
int fdSrc, fdDest;
struct stat st;
ssize_t sz;
if(stat(pSrc, &st) != 0)
{
LOG_EX(LOG_Error, "Get File %s Size Error\n", pSrc);
return (-ERR_GET_FILE_SIZE);
}
fdSrc = open(pSrc, O_RDONLY);
if(fdSrc < 0)
{
LOG_EX(LOG_Error, "Open File %s Error\n", pSrc);
return (-ERR_OPEN_FILE);
}
fdDest = open(pDest, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
if(fdDest < 0)
{
close(fdSrc);
LOG_EX(LOG_Error, "Open File %s Error\n", pDest);
return (-ERR_OPEN_FILE);
}
sz = sendfile(fdDest, fdSrc, NULL, st.st_size);
if(sz != st.st_size)
{
LOG_EX(LOG_Error, "Copy File Size Error: %d, %d\n", sz, st.st_size);
close(fdSrc);
close(fdDest);
return (-ERR_COPY_FILE);
}
fsync(fdDest);
close(fdSrc);
close(fdDest);
return (0);
}
int CopyFileWithSize(const char *pSrc, const char *pDest, int iSize)
{
int fdSrc, fdDest;
struct stat st;
ssize_t sz;
size_t cpSize = iSize;
if(iSize <= 0)
{
if(stat(pSrc, &st) != 0)
{
LOG_EX(LOG_Error, "Get File %s Size Error\n", pSrc);
return (-ERR_GET_FILE_SIZE);
}
cpSize = st.st_size;
}
fdSrc = open(pSrc, O_RDONLY);
if(fdSrc < 0)
{
LOG_EX(LOG_Error, "Open File %s Error\n", pSrc);
return (-ERR_OPEN_FILE);
}
fdDest = open(pDest, O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH |S_IWOTH);
if(fdDest < 0)
{
close(fdSrc);
LOG_EX(LOG_Error, "Open File %s Error\n", pDest);
return (-ERR_OPEN_FILE);
}
sz = sendfile(fdDest, fdSrc, NULL, cpSize);
if(sz != cpSize)
{
LOG_EX(LOG_Error, "Copy File Size Error: %d, %d\n", sz, cpSize);
close(fdSrc);
close(fdDest);
return (-ERR_COPY_FILE);
}
close(fdSrc);
close(fdDest);
return (0);
}
int ReadFileToBuf(const char *pSrc, unsigned char *pBuf, int iSize)
{
int fdSrc;
struct stat st;
ssize_t sz;
size_t cpSize = iSize;
if(iSize < 0)
{
if(stat(pSrc, &st) != 0)
{
LOG_EX(LOG_Error, "Get File %s Size Error\n", pSrc);
return (-ERR_GET_FILE_SIZE);
}
cpSize = st.st_size;
}
fdSrc = open(pSrc, O_RDONLY);
if(fdSrc < 0)
{
LOG_EX(LOG_Error, "Open File %s Error\n", pSrc);
return (-ERR_OPEN_FILE);
}
sz = read(fdSrc, pBuf, cpSize);
if(sz != cpSize)
{
LOG_EX(LOG_Error, "Copy File Size Error: %d, %d\n", sz, cpSize);
close(fdSrc);
return (-ERR_COPY_FILE);
}
close(fdSrc);
return (sz);
}
int GetShellExecResult(const char *pCmd, char **pResult)
{
FILE *pFile = NULL;
unsigned int uRdSize = 0;
char *pCmdOut;
*pResult = NULL;
if(pCmd == NULL || strlen(pCmd) == 0)
{
return (-ERR_INPUT_PARAMS);
}
pFile = popen(pCmd, "r");
if(pFile == NULL)
{
return (-ERR_OPEN_FILE);
}
*pResult = (char *)malloc(4096);
pCmdOut = *pResult;
uRdSize = fread(pCmdOut, sizeof(char), 4096, pFile);
pCmdOut[uRdSize] = 0;
if(pCmdOut[strlen(pCmdOut) - 1] == '\n')
{
pCmdOut[strlen(pCmdOut) - 1] = 0;
}
pclose(pFile);
//fprintf(stdout, "%s --> [%s](%u)\n", pCmd, pCmdOut, uRdSize);
return (0);
}
void SystemSafeReboot(void)
{
int ret, reTry = 0;
#if 0
ret = system("sync");
ret = system("ubus call system watchdog \'{\"stop\" : true}\'");
reTry = 3;
do
{
sleep(1);
} while(reTry--);
reTry = 0;
LOG_EX(LOG_Debug, "Reboot System By Power Control Chips\n");
sleep(1);
ret = system("echo 3140 > /sys/bus/platform/devices/axp22_board/axp22_reg");
sleep(10);
#endif
while(TRUE)
{
LOG_EX(LOG_Debug, "Reboot System: %d times\n", reTry++);
sleep(1);
ret = system("reboot -f");
sleep(3);
}
}
char* GetCpuChipId(void)
{
char* pRet = NULL;
#ifdef PLATFORM_R16
char* pChipId = NULL;
GetShellExecResult("cat /proc/cpuinfo | grep Chipid | awk '{print $3}'", &pChipId);
if(pChipId == NULL)
{
return strdup("");
}
pRet = strdup(pChipId);
free(pChipId);
return pRet;
#else
return strdup("Unknown CPU Chip ID");
#endif
}
char* GetCpuSerial(void)
{
char* pRet = NULL;
#ifdef PLATFORM_R16
char* pSerial = NULL;
GetShellExecResult("cat /proc/cpuinfo | grep Serial | awk '{print $3}'", &pSerial);
if(pSerial == NULL)
{
return strdup("");
}
pRet = strdup(pSerial);
free(pSerial);
return pRet;
#else
return strdup("Unknown CPU Serial");
#endif
}
unsigned long long GetPartitionFreeSize(const char *pPartPath)
{
struct statfs myStatfs;
unsigned long long freeSize;
if(statfs(pPartPath, &myStatfs) == -1)
{
return 0;
}
freeSize = myStatfs.f_bsize * myStatfs.f_bfree;
//fprintf(stdout, "%s free = %llu bytes\n", pPartPath, freeSize);
return freeSize;
}
#ifdef CURRENT_VERSION
char* GetCurrentVersion(void)
{
return CURRENT_VERSION;
}
#else
char* GetCurrentVersion(void)
{
return "0.0.1";
}
#endif
const char* ErrcodeToString(int errCode)
{
switch(errCode)
{
case ERR_INPUT_PARAMS: return "ERR_INPUT_PARAMS";
case ERR_NO_ITEMS: return "ERR_NO_ITEMS";
case ERR_GET_BUS: return "ERR_GET_BUS";
case ERR_DBUS_CONNECTION: return "ERR_DBUS_CONNECTION";
case ERR_REQUEST_BUS_NAME: return "ERR_REQUEST_BUS_NAME";
case ERR_SET_WATCH_FUNCTION: return "ERR_SET_WATCH_FUNCTION";
case ERR_SET_TIMEOUT_FUNCTION: return "ERR_SET_TIMEOUT_FUNCTION";
case ERR_BUS_MATCH: return "ERR_BUS_MATCH";
case ERR_BUS_SET_MSG_CB: return "ERR_BUS_SET_MSG_CB";
case ERR_DBUS_CREATE_MSG: return "ERR_DBUS_CREATE_MSG";
case ERR_BUS_SEND_MSG: return "ERR_BUS_SEND_MSG";
case ERR_DBUS_MSG_TO_LARGE: return "ERR_DBUS_MSG_TO_LARGE";
case ERR_BUS_RCV_MSG: return "ERR_BUS_RCV_MSG";
case ERR_ADD_TASK: return "ERR_ADD_TASK";
case ERR_UNSUP_EVP_TYPE: return "ERR_UNSUP_EVP_TYPE";
case ERR_CREATE_MQ: return "ERR_CREATE_MQ";
case ERR_MQ_SENDMSG: return "ERR_MQ_SENDMSG";
case ERR_CREATE_SHM: return "ERR_CREATE_SHM";
case ERR_MAP_SHM: return "ERR_MAP_SHM";
case ERR_MALLOC_MEMORY: return "ERR_MALLOC_MEMORY";
case ERR_EVP_INIT_KEY: return "ERR_EVP_INIT_KEY";
case ERR_EVP_UPDATE: return "ERR_EVP_UPDATE";
case ERR_EVP_FINALE: return "ERR_EVP_FINALE";
case ERR_EVP_KEY_SIZE: return "ERR_EVP_KEY_SIZE";
case ERR_OPEN_FILE: return "ERR_OPEN_FILE";
case ERR_READ_FILE: return "ERR_READ_FILE";
case ERR_WRITE_FILE: return "ERR_WRITE_FILE";
case ERR_COPY_FILE: return "ERR_COPY_FILE";
case ERR_FILE_NOT_EXISTS: return "ERR_FILE_NOT_EXISTS";
case ERR_GET_FILE_SIZE: return "ERR_GET_FILE_SIZE";
case ERR_UNINIT_ITEM: return "ERR_UNINIT_ITEM";
case ERR_FILE_EMPTY: return "ERR_FILE_EMPTY";
case ERR_SEND_MAIL: return "ERR_SEND_MAIL";
case ERR_NETWORK_SEND: return "ERR_NETWORK_SEND";
case ERR_NETWORK_NOT_CONNECTED: return "ERR_NETWORK_NOT_CONNECTED";
case ERR_UNSUPPORT: return "ERR_UNSUPPORT";
case ERR_NO_INIT_IPL3: return "ERR_NO_INIT_IPL3";
case ERR_BAD_IPL3: return "ERR_BAD_IPL3";
case ERR_BAD_FILE_SIZE: return "ERR_BAD_FILE_SIZE";
case ERR_MD5_FILE: return "ERR_MD5_FILE";
case ERR_MD5_CHECK_SUM: return "ERR_MD5_CHECK_SUM";
case ERR_OTA_WRITE_BOOT: return "ERR_OTA_WRITE_BOOT";
case ERR_OTA_WRITE_ROOTFS: return "ERR_OTA_WRITE_ROOTFS";
case ERR_OTA_WRITE_IPL3: return "ERR_OTA_WRITE_IPL3";
case ERR_OTA_WRITE_PARAMS: return "ERR_OTA_WRITE_PARAMS";
case ERR_OTA_DOWNLOAD_FILE: return "ERR_OTA_DOWNLOAD_FILE";
case ERR_VERIFY_PARTITION_MD5: return "ERR_VERIFY_PARTITION_MD5";
case ERR_OTA_PRE_STATR: return "ERR_OTA_PRE_STATR";
case ERR_OTA_YET_CUR_VER: return "ERR_OTA_YET_CUR_VER";
case ERR_OTA_NOT_READY: return "ERR_OTA_NOT_READY";
case ERR_CREATE_CFG_FILE: return "ERR_CREATE_CFG_FILE";
case ERR_CREATE_SQLITE3_DB: return "ERR_CREATE_SQLITE3_DB";
case ERR_OPEN_SQLITE3_DB: return "ERR_OPEN_SQLITE3_DB";
case ERR_SQLITE3_CREATE_TABLE: return "ERR_SQLITE3_CREATE_TABLE";
case ERR_SYNC_DATABASE: return "ERR_SYNC_DATABASE";
case ERR_SQL_QUERY: return "ERR_SQL_QUERY";
case ERR_SQL_DELETE: return "ERR_SQL_DELETE";
case ERR_UNKNOWN_TYPE: return "ERR_UNKNOWN_TYPE";
case ERR_PERMISSION_DENIED: return "ERR_PERMISSION_DENIED";
case ERR_CFG_NOITEM: return "ERR_CFG_NOITEM";
case ERR_CFG_ITEM_EXIST: return "ERR_CFG_ITEM_EXIST";
case ERR_CFG_WAIT_RSP: return "ERR_CFG_WAIT_RSP";
case ERR_CFG_BUSY: return "ERR_CFG_BUSY";
case ERR_STR_CONVERT: return "ERR_STR_CONVERT";
case ERR_SQL_REG_MODULE: return "ERR_SQL_REG_MODULE";
default: return "Unknown Error";
}
}
const char* DBusCmdToString(DBUS_CMD cmd)
{
switch(cmd)
{
case CMD_MISC_PING: return "CMD_MISC_PING";
case CMD_MISC_OTA: return "CMD_MISC_OTA";
case CMD_MISC_WEATHER: return "CMD_MISC_WEATHER";
case CMD_MISC_NOWTIME: return "CMD_MISC_NOWTIME";
case CMD_MISC_UPGRADE: return "CMD_MISC_UPGRADE";
case CMD_SYSTEM_STANDBY: return "CMD_SYSTEM_STANDBY";
case CMD_MISC_QUERY_OTA_STATUS: return "CMD_MISC_QUERY_OTA_STATUS";
case CMD_MISC_QUERY_DL_STATUS: return "CMD_MISC_QUERY_DL_STATUS";
case CMD_CALL_DIAL: return "CMD_CALL_DIAL";
case CMD_CALL_ACCEPI: return "CMD_CALL_ACCEPI";
case CMD_CALL_HANGUP: return "CMD_CALL_HANGUP";
case CMD_CALL_MESSAGE: return "CMD_CALL_MESSAGE";
case CMD_PLAY_MODECHANGE: return "CMD_PLAY_MODECHANGE";
case CMD_PLAY_PLAY: return "CMD_PLAY_PLAY";
case CMD_PLAY_PAUSE: return "CMD_PLAY_PAUSE";
case CMD_PLAY_STOP: return "CMD_PLAY_STOP";
case CMD_PLAY_SEEKTO: return "CMD_PLAY_SEEKTO";
case CMD_PLAY_SHOWMODE: return "CMD_PLAY_SHOWMODE";
case CMD_PLAY_NEXT: return "CMD_PLAY_NEXT";
case CMD_PLAY_PRE: return "CMD_PLAY_PRE";
case CMD_PLAY_SHOWLIST: return "CMD_PLAY_SHOWLIST";
case CMD_PLAY_UPDATELIST: return "CMD_PLAY_UPDATELIST";
case CMD_PLAY_PREPARE_NEXT: return "CMD_PLAY_PREPARE_NEXT";
case CMD_PLAY_ADDTOLIST: return "CMD_PLAY_ADDTOLIST";
case CMD_PLAY_DELETEFROMLIST: return "CMD_PLAY_DELETEFROMLIST";
case CMD_PLAY_RESETLIST: return "CMD_PLAY_RESETLIST";
case CMD_PLAY_AUDIO_STOP: return "CMD_PLAY_AUDIO_STOP";
case CMD_PLAY_AUDIO_PLAY: return "CMD_PLAY_AUDIO_PLAY";
case CMD_SE_PLAY: return "CMD_SE_PLAY";
case CMD_PLAY_RET_STATUS: return "CMD_PLAY_RET_STATUS";
case CMD_CFG_ADD_REQ: return "CMD_CFG_ADD_REQ";
case CMD_CFG_ADD_RSP: return "CMD_CFG_ADD_RSP";
case CMD_CFG_CHANGE_REQ: return "CMD_CFG_CHANGE_REQ";
case CMD_CFG_CHANGE_RSP: return "CMD_CFG_CHANGE_RSP";
case CMD_CFG_GET_REQ: return "CMD_CFG_GET_REQ";
case CMD_CFG_GET_RSP: return "CMD_CFG_GET_RSP";
case CMD_CFG_UPG_NOTIFY: return "CMD_CFG_UPG_NOTIFY";
case CMD_MSC_MSG_CONTROLLER_RECOG_SUCCESS: return "CMD_MSC_MSG_CONTROLLER_RECOG_SUCCESS";
case CMD_MSC_MSG_CONTROLLER_RECOG_ERROR: return "CMD_MSC_MSG_CONTROLLER_RECOG_ERROR";
case CMD_MSC_MSG_CONTROLLER_WAKEUP: return "CMD_MSC_MSG_CONTROLLER_WAKEUP";
case CMD_MSC_MSG_CONTROLLER_RECOGING: return "CMD_MSC_MSG_CONTROLLER_RECOGING";
case CMD_CONTROLLER_REQMSG_INITARGS: return "CMD_CONTROLLER_REQMSG_INITARGS";
case CMD_CONTROLLER_RSPMSG_INITARGS: return "CMD_CONTROLLER_RSPMSG_INITARGS";
case CMD_CONTROLLER_REQMSG_PLAYERSTATUS: return "CMD_CONTROLLER_REQMSG_PLAYERSTATUS";
case CMD_CONTROLLER_RSPMSG_PLAYERSTATUS: return "CMD_CONTROLLER_RSPMSG_PLAYERSTATUS";
case CMD_MSC_REQMSG_MIC_CONTROL: return "CMD_MSC_REQMSG_MIC_CONTROL";
case CMD_MSC_RSPMSG_MIC_CONTROL: return "CMD_MSC_RSPMSG_MIC_CONTROL";
case CMD_YUNXIN_RECVMSG: return "CMD_YUNXIN_RECVMSG";
case CMD_YUNXIN_SENDMSG: return "CMD_YUNXIN_SENDMSG";
case CMD_YUNXIN_SENDMSG_BYPASS: return "CMD_YUNXIN_SENDMSG_BYPASS";
case CMD_YUNXIN_SENDMSGCB: return "CMD_YUNXIN_SENDMSGCB";
case CMD_CONTROLLER_MSG_YUNXIN: return "CMD_CONTROLLER_MSG_YUNXIN";
case CMD_YUNXIN_STATUS: return "CMD_YUNXIN_STATUS";
case CMD_YUNXIN_SYSMSG: return "CMD_YUNXIN_SYSMSG";
case CMD_WIFI_CONF: return "CMD_WIFI_CONF";
case CMD_WIFI_CONF_RESP: return "CMD_WIFI_CONF_RESP";
case CMD_WIFI_AUTO_CONN: return "CMD_WIFI_AUTO_CONN";
case CMD_WIFI_AUTO_CONN_RESP: return "CMD_WIFI_AUTO_CONN_RESP";
case CMD_WIFI_STATE_REQ: return "CMD_WIFI_STATE_REQ";
case CMD_WIFI_STATE_RESP: return "CMD_WIFI_STATE_RESP";
case CMD_WIFI_STATE_NTF: return "CMD_WIFI_STATE_NTF";
case CMD_BT_NAME_GET_REQ: return "CMD_BT_NAME_GET_REQ";
case CMD_BT_NAME_GET_RESP: return "CMD_BT_NAME_GET_RESP";
case CMD_BT_EVT_NTF: return "CMD_BT_EVT_NTF";
case CMD_KPLAYER_START: return "CMD_KPLAYER_START";
case CMD_KPLAYER_STOP: return "CMD_KPLAYER_STOP";
case CMD_KPLAYER_NOTIF_DUR: return "CMD_KPLAYER_NOTIF_DUR";
case CMD_KPLAYER_HOST_ACTION: return "CMD_KPLAYER_HOST_ACTION";
case CMD_KPLAYER_CTR_NTF_BASE: return "CMD_KPLAYER_CTR_NTF_BASE";
case CMD_KPLAYER_CTR_CREATED: return "CMD_KPLAYER_CTR_CREATED";
case CMD_KPLAYER_CTR_DELED: return "CMD_KPLAYER_CTR_DELED";
case CMD_KPLAYER_CTR_PLAY: return "CMD_KPLAYER_CTR_PLAY";
case CMD_KPLAYER_CTR_STOP: return "CMD_KPLAYER_CTR_STOP";
case CMD_KPLAYER_CTR_PAUSE: return "CMD_KPLAYER_CTR_PAUSE";
case CMD_KPLAYER_CTR_SEEK: return "CMD_KPLAYER_CTR_SEEK";
case CMD_KPLAYER_CTR_SET_URL: return "CMD_KPLAYER_CTR_SET_URL";
case CMD_KPLAYER_CTR_SET_VOLUME: return "CMD_KPLAYER_CTR_SET_VOLUME";
case CMD_KPLAYER_CTR_SET_MUTE: return "CMD_KPLAYER_CTR_SET_MUTE";
case CMD_KPLAYER_CTR_SET_NXT_URL: return "CMD_KPLAYER_CTR_SET_NXT_URL";
case CMD_KPLAYER_CTR_SET_NEXT: return "CMD_KPLAYER_CTR_SET_NEXT";
case CMD_KPLAYER_CTR_SET_PREV: return "CMD_KPLAYER_CTR_SET_PREV";
case CMD_ALARM_SYNC_REQ: return "CMD_ALARM_SYNC_REQ";
case CMD_ALARM_SYNC_RSP: return "CMD_ALARM_SYNC_RSP";
case CMD_ALARM_ADD: return "CMD_ALARM_ADD";
case CMD_ALARM_REMOVE: return "CMD_ALARM_REMOVE";
case CMD_ALARM_REMOVEALL: return "CMD_ALARM_REMOVEALL";
case CMD_REMAIND_SYNC_REQ: return "CMD_REMAIND_SYNC_REQ";
case CMD_REMAIND_SYNC_RSP: return "CMD_REMAIND_SYNC_RSP";
case CMD_REMAIND_ADD: return "CMD_REMAIND_ADD";
case CMD_REMAIND_REMOVE: return "CMD_REMAIND_REMOVE";
case CMD_REMAIND_REMOVEALL: return "CMD_REMAIND_REMOVEALL";
case CMD_ASSISTANT_STATUS: return "CMD_ASSISTANT_STATUS";
case CMD_ASSISTANT_RUNNING: return "CMD_ASSISTANT_RUNNING";
case CMD_ASSISTANT_NOTIFY: return "CMD_ASSISTANT_NOTIFY";
case CMD_SESSION_ALARM_SYNC: return "CMD_SESSION_ALARM_SYNC";
case CMD_WORKDAY_DB_REQ: return "CMD_WORKDAY_DB_REQ";
case CMD_WORKDAY_DB_RSP: return "CMD_WORKDAY_DB_RSP";
case CMD_OTA_NOTIFY: return "CMD_OTA_NOTIFY";
case CMD_OTA_STATUS: return "CMD_OTA_STATUS";
case CMD_OTA_RUNNOW: return "CMD_OTA_RUNNOW";
case CMD_LOG_CONFIG: return "CMD_LOG_CONFIG";
default: return "Unknown CMD";
}
}
const char* ModuleNameToString(MODULE_NAME modName)
{
switch(modName)
{
case MODULE_CONTROLLER: return "MODULE_CONTROLLER";
case MODULE_ALARM: return "MODULE_ALARM";
case MODULE_CALL: return "MODULE_CALL";
case MODULE_VOICEENGINE: return "MODULE_VOICEENGINE";
case MODULE_PLAYER: return "MODULE_PLAYER";
case MODULE_CONFIGURE: return "MODULE_CONFIGURE";
case MODULE_OTA: return "MODULE_OTA";
case MODULE_WIFI: return "MODULE_WIFI";
case MODULE_BT: return "MODULE_BT";
case MODULE_KPLAYER: return "MODULE_KPLAYER";
case MODULE_KPLAYER_TEST: return "MODULE_KPLAYER_TEST";
case MODULE_SPLAYER: return "MODULE_SPLAYER";
case MODULE_SPLAYER_TEST: return "MODULE_SPLAYER_TEST";
case MODULE_LIGHT_MCU: return "MODULE_LIGHT_MCU";
case MODULE_BLUEKC: return "MODULE_BLUEKC";
case MODULE_BLUEKC_TEST: return "MODULE_BLUEKC_TEST";
case MODULE_MANUFACTURE: return "MODULE_MANUFACTURE";
case MODULE_BT_DEMO: return "MODULE_BT_DEMO";
case MODULE_LOG_CTRL: return "MODULE_LOG_CTRL";
}
return "Unknown Module Name";
}

File diff suppressed because it is too large Load Diff

View File

@ -43,7 +43,7 @@ PLAT_LINUX_CFLAGS += -I../linux32/inc/ -I../linux32/inc/cjson/ -I../linux32/inc
R16_LIBS := $(COMMON_R16_LIBS) -lreadline -lcurses
R16_LIBS += ./libuvdbus-r16.so
R311_LIBS := $(COMMON_R16_LIBS) -lreadline -lcurses
R311_LIBS := $(COMMON_R311_LIBS) -lreadline -lcurses
R311_LIBS += ./libuvdbus-r311.so
LINUX_LIBS := $(COMMON_LINUX_LIBS) -lreadline -lnghttp2

View File

@ -1,2 +1,6 @@
COMMON_R16_LIBS := -ldbus-1 -luv -lcrypto -lcjson -ls2json -lsqlite3 -lnghttp2 -lquickmail -lz -luuid -lconfig -lcurl -lssl -lpthread ../3partys/boardlink/libfastcon.a
COMMON_R16_LIBS := -ldbus-1 -luv -lcrypto -lcjson -ls2json -lsqlite3 -lnghttp2 -lquickmail -lz -luuid -lconfig -lcurl -lssl -lpthread
COMMON_R16_LIBS += ../3partys/boardlink/libfastcon.a ./libpv1comm-r16.so
COMMON_R311_LIBS := -ldbus-1 -luv -lcrypto -lcjson -ls2json -lsqlite3 -lnghttp2 -lquickmail -lz -luuid -lconfig -lcurl -lssl -lpthread
COMMON_R311_LIBS += ../3partys/boardlink/libfastcon.a ./libpv1comm-r311.so
COMMON_LINUX_LIBS := -ldbus-1 -luv -lcrypto -lcurl -lm -lnghttp2 -lsqlite3 -lquickmail -lz -luuid -lconfig -lssl -lpthread
COMMON_LINUX_LIBS += ./libpv1comm-linux.so

View File

@ -32,7 +32,7 @@ VPATH = ../Framework ../log ../Modules ../linux32
# set the source file, don't used .o because of ...
# MRS Board Source Files
PLAT_R16_SRCS = \
libuvEngine/libuv_dbus.c \
libuvEngine/libcomm.c \
HeartDaemon/heart_daemon.c \
JsonUtils/json_struct.c \
Configure/config_engine.c \
@ -42,20 +42,13 @@ PLAT_R16_SRCS = \
Crypto/md5.c \
Crypto/crypto.c \
Compress/zlib.c \
Network/inet_api.c \
Timer/timer.c \
Fifo/fifo.c \
Skins/skins.c \
Skins/skin_res_vtbl.c \
IoT/Boardlink/boardlink_iot.c \
Monitor/monitor.c \
log.c \
SvrManager/svr_manager.c \
hexdump.c
SvrManager/svr_manager.c \
mark_point.c
PLAT_LINUX_SRCS := $(PLAT_R16_SRCS) \
src/cJSON.c \
src/s2j.c
PLAT_LINUX_SRCS := $(PLAT_R16_SRCS)
PLAT_R311_SRCS := $(PLAT_R16_SRCS)
# gcc CFLAGS
@ -70,12 +63,35 @@ PLAT_R311_LDFLAGS := $(PLAT_R16_LDFLAGS)
PLAT_LINUX_LDFLAGS := $(PLAT_R16_LDFLAGS)
R16_LIBS := $(COMMON_R16_LIBS)
R311_LIBS := $(COMMON_R16_LIBS)
R311_LIBS := $(COMMON_R311_LIBS)
LINUX_LIBS := $(COMMON_LINUX_LIBS)
ifeq ($(PLAT_R16), TRUE)
DEPEND_LIB := ../3partys/allwinner/libpv1comm-r16.so
USER_CLEAN_ITEMS += ./libpv1comm-r16.so
endif
ifeq ($(PLAT_R311), TRUE)
DEPEND_LIB += ../3partys/allwinner/libpv1comm-r311.so
USER_CLEAN_ITEMS += ./libpv1comm-r311.so
endif
ifeq ($(PLAT_LINUX), TRUE)
DEPEND_LIB += ../3partys/allwinner/libpv1comm-linux.so
USER_CLEAN_ITEMS += ./libpv1comm-linux.so
endif
# this line must be at below of thus, because of...
include /opt/common/Makefile.cross
ifneq ($(MAKECMDGOALS), clean)
ifneq ($(MAKECMDGOALS), cleanall)
ifneq ($(notdir $(DEPEND_LIB)), $(wildcard $(DEPEND_LIB)))
$(shell $(CP) $(DEPEND_LIB) ./)
endif
endif
endif
ifeq ($(MAKECMDGOALS), )
$(shell find ./ -name $(TARGET)-*.exe -delete)
else

View File

@ -84,18 +84,18 @@ const SKIN_RES_INFO g_SkinDefaultResTable[] = {
{VOICE_RES, "0", "v309", DEF_SKINS_ROOT_PATH"voice/S009.mp3", "f9039012752b3ed2a00f173aa305acf1"},
{VOICE_RES, "0", "v310", DEF_SKINS_ROOT_PATH"voice/S010.mp3", "446ec757495bdf7aee31a41a9efe8bab"},
{VOICE_RES, "0", "v311", DEF_SKINS_ROOT_PATH"voice/S011.mp3", "e9fa92d8929dcb2e134f42c1cedf4827"},
{VOICE_RES, "0", "v400", DEF_SKINS_ROOT_PATH"voice/B-h-60.mp3", "61b24ec25307072464866da912d38287"},
{VOICE_RES, "0", "v400", DEF_SKINS_ROOT_PATH"voice/B-h-61.mp3", "a231dc24277e25e6d762269efa9a1e07"},
{VOICE_RES, "0", "v400", DEF_SKINS_ROOT_PATH"voice/B-h-62.mp3", "27402531c6aff9a9cfb5e418267fb41e"},
{VOICE_RES, "0", "v400", DEF_SKINS_ROOT_PATH"voice/B-h-63.mp3", "f9487a6bf86f82961011920509ae0704"},
{VOICE_RES, "0", "v400", DEF_SKINS_ROOT_PATH"voice/B-h-64.mp3", "1e67f62e7d8f38dbd8535355cb50fd81"},
{VOICE_RES, "0", "v400", DEF_SKINS_ROOT_PATH"voice/B-h-65.mp3", "d2e6c99c68e981e6126306cfe8a8058e"},
{VOICE_RES, "0", "v401", DEF_SKINS_ROOT_PATH"voice/B-h-66.mp3", "cb64153aef2ea8d5d9baeb0fc683fd54"},
{VOICE_RES, "0", "v401", DEF_SKINS_ROOT_PATH"voice/B-h-67.mp3", "6661a903cd05fdab1ecd5193fb789e51"},
{VOICE_RES, "0", "v401", DEF_SKINS_ROOT_PATH"voice/B-h-68.mp3", "db32f17dc439c25255d934bbeaec6275"},
{VOICE_RES, "0", "v401", DEF_SKINS_ROOT_PATH"voice/B-h-69.mp3", "a93fea8d57e37a519f3ee0388cbd6e9a"},
{VOICE_RES, "0", "v401", DEF_SKINS_ROOT_PATH"voice/B-h-70.mp3", "f91f277864c927fedfee53fb1e9d964a"},
{VOICE_RES, "0", "v401", DEF_SKINS_ROOT_PATH"voice/B-h-71.mp3", "a4a4ff36d63fa47072c9eb181712e5cb"},
{VOICE_RES, "0", "v400", DEF_SKINS_ROOT_PATH"voice/B-h-60.mp3", "9828d1ab422bc917bc6aeb1b3e87be78"},
{VOICE_RES, "0", "v400", DEF_SKINS_ROOT_PATH"voice/B-h-61.mp3", "26afdbca771abb35ae30be251211245c"},
{VOICE_RES, "0", "v400", DEF_SKINS_ROOT_PATH"voice/B-h-62.mp3", "56bda2a05dee06eb64271d69df16a5f7"},
{VOICE_RES, "0", "v400", DEF_SKINS_ROOT_PATH"voice/B-h-63.mp3", "bfa246ebc08235208b01d251279c3c3a"},
{VOICE_RES, "0", "v400", DEF_SKINS_ROOT_PATH"voice/B-h-64.mp3", "4a18af279fce82af357a4d8061f76608"},
{VOICE_RES, "0", "v400", DEF_SKINS_ROOT_PATH"voice/B-h-65.mp3", "ec06ed18a96a28a5c2a8335f8c94af22"},
{VOICE_RES, "0", "v401", DEF_SKINS_ROOT_PATH"voice/B-h-66.mp3", "014233835f5b9996adb572c7ba7b2cfa"},
{VOICE_RES, "0", "v401", DEF_SKINS_ROOT_PATH"voice/B-h-67.mp3", "29a476772a85097a5fe31d2147234110"},
{VOICE_RES, "0", "v401", DEF_SKINS_ROOT_PATH"voice/B-h-68.mp3", "5a746e5a466c2beee159174b08049221"},
{VOICE_RES, "0", "v401", DEF_SKINS_ROOT_PATH"voice/B-h-69.mp3", "986d49e19cef9e19ed059112ed8ebbdf"},
{VOICE_RES, "0", "v401", DEF_SKINS_ROOT_PATH"voice/B-h-70.mp3", "666c2d4f6de83dfaf7a8b0ead3db7231"},
{VOICE_RES, "0", "v401", DEF_SKINS_ROOT_PATH"voice/B-h-71.mp3", "d39d5b43690f01bfb5746cadf1d98b17"},
{VOICE_RES, "0", "v402", DEF_SKINS_ROOT_PATH"voice/b-h-50.mp3", "017b53f7610f6dd99e21b546e6b35605"},
{VOICE_RES, "0", "v403", DEF_SKINS_ROOT_PATH"voice/b-h-51.mp3", "422b4550253780343b7a9805ca7b629a"},
{VOICE_RES, "0", "v5011", DEF_SKINS_ROOT_PATH"voice/a-a-01.mp3", "5d9d186ef50b603ab84a9abbfd348630"},

View File

@ -1,326 +0,0 @@
#ifndef __KERNEL__
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <uthash/utstring.h>
#include "log.h"
static const char hex_asc[] = "0123456789abcdef";
#define hex_asc_lo(x) hex_asc[((x) & 0x0f)]
#define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4]
char* IHW_bin2hex(char *p, const unsigned char *cp, int count)
{
while (count) {
unsigned char c = *cp++;
/* put lowercase hex digits */
*p++ = 0x20 | hex_asc[c >> 4];
*p++ = 0x20 | hex_asc[c & 0xf];
count--;
}
return p;
}
/**
* hex_to_bin - convert a hex digit to its real value
* @ch: ascii character represents hex digit
*
* hex_to_bin() converts one hex digit to its actual value or -1 in case of bad
* input.
*/
int hex_to_bin(char ch)
{
if((ch >= '0') && (ch <= '9'))
{
return ch - '0';
}
ch = tolower(ch);
if((ch >= 'a') && (ch <= 'f'))
{
return ch - 'a' + 10;
}
return -1;
}
/**
* hex_dump_to_buffer - convert a blob of data to "hex ASCII" in memory
* @buf: data blob to dump
* @len: number of bytes in the @buf
* @rowsize: number of bytes to print per line; must be 16 or 32
* @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1)
* @linebuf: where to put the converted data
* @linebuflen: total size of @linebuf, including space for terminating NUL
* @ascii: include ASCII after the hex output
*
* hex_dump_to_buffer() works on one "line" of output at a time, i.e.,
* 16 or 32 bytes of input data converted to hex + ASCII output.
*
* Given a buffer of u8 data, hex_dump_to_buffer() converts the input data
* to a hex + ASCII dump at the supplied memory location.
* The converted output is always NUL-terminated.
*
* E.g.:
* hex_dump_to_buffer(frame->data, frame->len, 16, 1,
* linebuf, sizeof(linebuf), true);
*
* example output buffer:
* 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO
*/
void hex_dump_to_buffer(const void* buf, int len, int rowsize,
int groupsize, char* linebuf, size_t linebuflen,
int ascii)
{
const unsigned char* ptr = (const unsigned char *)buf;
unsigned char ch;
int j, lx = 0;
int ascii_column;
if(rowsize != 16 && rowsize != 32)
{
rowsize = 16;
}
if(!len)
{
goto nil;
}
if(len > rowsize) /* limit to one line at a time */
{
len = rowsize;
}
if((len % groupsize) != 0) /* no mixed size output */
{
groupsize = 1;
}
switch(groupsize)
{
case 8:
{
const unsigned long long* ptr8 = (const unsigned long long *)buf;
int ngroups = len / groupsize;
for(j = 0; j < ngroups; j++)
lx += snprintf(linebuf + lx, linebuflen - lx,
"%s%16.16llx", j ? " " : "",
(unsigned long long) * (ptr8 + j));
ascii_column = 17 * ngroups + 2;
break;
}
case 4:
{
const unsigned int* ptr4 = (const unsigned int *)buf;
int ngroups = len / groupsize;
for(j = 0; j < ngroups; j++)
lx += snprintf(linebuf + lx, linebuflen - lx,
"%s%8.8x", j ? " " : "", *(ptr4 + j));
ascii_column = 9 * ngroups + 2;
break;
}
case 2:
{
const unsigned short* ptr2 = (const unsigned short *)buf;
int ngroups = len / groupsize;
for(j = 0; j < ngroups; j++)
lx += snprintf(linebuf + lx, linebuflen - lx,
"%s%4.4x", j ? " " : "", *(ptr2 + j));
ascii_column = 5 * ngroups + 2;
break;
}
default:
for(j = 0; (j < len) && (lx + 3) <= linebuflen; j++)
{
ch = ptr[j];
linebuf[lx++] = hex_asc_hi(ch);
linebuf[lx++] = hex_asc_lo(ch);
linebuf[lx++] = ' ';
}
if(j)
{
lx--;
}
ascii_column = 3 * rowsize + 2;
break;
}
if(!ascii)
{
goto nil;
}
while(lx < (linebuflen - 1) && lx < (ascii_column - 1))
{
linebuf[lx++] = ' ';
}
for(j = 0; (j < len) && (lx + 2) < linebuflen; j++)
{
ch = ptr[j];
linebuf[lx++] = (isascii(ch) && isprint(ch)) ? ch : '.';
}
nil:
linebuf[lx++] = '\0';
}
/**
* print_hex_dump - print a text hex dump to syslog for a binary blob of data
* @level: kernel log level (e.g. KERN_DEBUG)
* @prefix_str: string to prefix each line with;
* caller supplies trailing spaces for alignment if desired
* @prefix_type: controls whether prefix of an offset, address, or none
* is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE)
* @rowsize: number of bytes to print per line; must be 16 or 32
* @groupsize: number of bytes to print at a time (1, 2, 4, 8; default = 1)
* @buf: data blob to dump
* @len: number of bytes in the @buf
* @ascii: include ASCII after the hex output
*
* Given a buffer of u8 data, print_hex_dump() prints a hex + ASCII dump
* to the kernel log at the specified kernel log level, with an optional
* leading prefix.
*
* print_hex_dump() works on one "line" of output at a time, i.e.,
* 16 or 32 bytes of input data converted to hex + ASCII output.
* print_hex_dump() iterates over the entire input @buf, breaking it into
* "line size" chunks to format and print.
*
* E.g.:
* print_hex_dump(KERN_DEBUG, "raw data: ", DUMP_PREFIX_ADDRESS,
* 16, 1, frame->data, frame->len, true);
*
* Example output using %DUMP_PREFIX_OFFSET and 1-byte mode:
* 0009ab42: 40 41 42 43 44 45 46 47 48 49 4a 4b 4c 4d 4e 4f @ABCDEFGHIJKLMNO
* Example output using %DUMP_PREFIX_ADDRESS and 4-byte mode:
* ffffffff88089af0: 73727170 77767574 7b7a7978 7f7e7d7c pqrstuvwxyz{|}~.
*/
void print_hex_dump(const char* prefix_str, int prefix_type,
int rowsize, int groupsize,
const void* buf, int len, int ascii)
{
const unsigned char* ptr = (const unsigned char *)buf;
int i, remaining = len;
unsigned char linebuf[32 * 3 + 2 + 32 + 1];
if(rowsize != 16 && rowsize != 32)
{
rowsize = 16;
}
for(i = 0; i < len; i += rowsize)
{
int linelen = MIN(remaining, rowsize);
remaining -= rowsize;
hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize,
(char *)linebuf, sizeof(linebuf), ascii);
switch(prefix_type)
{
case DUMP_PREFIX_ADDRESS:
print("%s%p: %s\n",
prefix_str, ptr + i, linebuf);
break;
case DUMP_PREFIX_OFFSET:
print("%s%.8x: %s\n", prefix_str, i, linebuf);
break;
default:
print("%s%.8x: %s\n", prefix_str, i, linebuf);
break;
}
}
print("%s", "\n");
}
/**
* print_hex_dump_bytes - shorthand form of print_hex_dump() with default params
* @prefix_str: string to prefix each line with;
* caller supplies trailing spaces for alignment if desired
* @prefix_type: controls whether prefix of an offset, address, or none
* is printed (%DUMP_PREFIX_OFFSET, %DUMP_PREFIX_ADDRESS, %DUMP_PREFIX_NONE)
* @buf: data blob to dump
* @len: number of bytes in the @buf
*
* Calls print_hex_dump(), with log level of KERN_DEBUG,
* rowsize of 16, groupsize of 1, and ASCII output included.
*/
void print_hex_dump_bytes(const char* prefix_str, int prefix_type,
const void* buf, int len)
{
print_hex_dump(prefix_str, prefix_type, 16, 1,
buf, len, 1);
}
const char* format_hex_buf(const char* prefix_str, int prefix_type,
int rowsize, int groupsize,
const void* buf, int len, int ascii)
{
UT_string* pLogStr = NULL;
const char* pFormatStr;
const unsigned char* ptr = (const unsigned char *)buf;
int i, remaining = len;
unsigned char linebuf[32 * 3 + 2 + 32 + 1];
if(rowsize != 16 && rowsize != 32)
{
rowsize = 16;
}
utstring_new(pLogStr);
for(i = 0; i < len; i += rowsize)
{
int linelen = MIN(remaining, rowsize);
remaining -= rowsize;
hex_dump_to_buffer(ptr + i, linelen, rowsize, groupsize,
(char *)linebuf, sizeof(linebuf), ascii);
switch(prefix_type)
{
case DUMP_PREFIX_ADDRESS:
utstring_printf(pLogStr, "%s%p: %s\n",
prefix_str, ptr + i, linebuf);
break;
case DUMP_PREFIX_OFFSET:
utstring_printf(pLogStr, "%s%.8x: %s\n",
prefix_str, i, linebuf);
break;
default:
utstring_printf(pLogStr, "%s%.8x: %s\n",
prefix_str, i, linebuf);
break;
}
}
pFormatStr = strdup(utstring_body(pLogStr));
utstring_free(pLogStr);
return pFormatStr;
}
#endif

1332
log/log.c

File diff suppressed because it is too large Load Diff

270
log/mark_point.c Normal file
View File

@ -0,0 +1,270 @@
/** @file log.c
@brief
@version 1.0.0
*/
#include <sys/time.h>
#include <fcntl.h>
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <pthread.h>
#include <uthash/utlist.h>
#include <uv.h>
#include "log.h"
#include "smart_sound.h"
#include "inet_api.h"
#include "libuv_dbus.h"
#include "server_addr.h"
#ifdef PLATFORM_CPU
#define LOG_FILE_BASEDIR (".")
#else
#define LOG_FILE_BASEDIR ("/tmp")
#endif
#define SYS_POINT_UPLOAD_TIME (600)
typedef struct
{
char* pDeviceId;
char savePath[MAX_PATH];
int iMaxCacheSize;
int iEveryUploadTime;
time_t lastPostTime;
time_t lastMarkTime;
FILE* pMarkFile;
uv_rwlock_t uvRwLock;
uv_thread_t uvIOThread;
} SYSPOINT_INFO, *PSYSPOINT_INFO;
typedef struct SYSPOINT_ITEM
{
char* pContent;
struct SYSPOINT_ITEM *next, *prev;
} *PSYSPOINT_ITEM;
static SYSPOINT_INFO g_SysPonitInfo;
static PSYSPOINT_ITEM g_pSysPointArray = NULL;
static PHTTP_POST_ATTACH g_pLogParamsArray = NULL;
static void __uvSysPointIOProc(void *pParams)
{
while(TRUE)
{
PSYSPOINT_ITEM pItem = NULL, pTmp = NULL;
int iFileSize;
time_t tmNow = time(NULL);
if(g_SysPonitInfo.pMarkFile)
{
uv_rwlock_wrlock(&g_SysPonitInfo.uvRwLock);
LL_FOREACH_SAFE(g_pSysPointArray, pItem, pTmp)
{
fwrite(pItem->pContent, 1, strlen(pItem->pContent), g_SysPonitInfo.pMarkFile);
free(pItem->pContent);
LL_DELETE(g_pSysPointArray, pItem);
free(pItem);
}
uv_rwlock_wrunlock(&g_SysPonitInfo.uvRwLock);
}
GET_FILE_SIZE(g_SysPonitInfo.savePath, iFileSize);
if(g_SysPonitInfo.lastPostTime == 0 || tmNow < g_SysPonitInfo.lastPostTime)
{
g_SysPonitInfo.lastPostTime = g_SysPonitInfo.lastMarkTime = tmNow;
tmNow = 0;
}
#if 0
LOG_EX(LOG_Debug, "iFile = %d, MaxSize = %d, upTime = %d\n",
iFileSize, g_SysPonitInfo.iMaxCacheSize, g_SysPonitInfo.iEveryUploadTime);
LOG_EX(LOG_Debug, "tm = %d, last = %d\n", tmNow, g_SysPonitInfo.lastPostTime);
#endif
if(iFileSize > g_SysPonitInfo.iMaxCacheSize
|| tmNow - g_SysPonitInfo.lastPostTime > g_SysPonitInfo.iEveryUploadTime)
{
int fileSize = 0;
GET_FILE_SIZE(g_SysPonitInfo.savePath, fileSize);
if(fileSize > 0)
{
SysPointMarkUpload();
g_SysPonitInfo.lastPostTime = tmNow;
}
if(tmNow - g_SysPonitInfo.lastPostTime > g_SysPonitInfo.iEveryUploadTime)
{
SysPointMarkUpload();
g_SysPonitInfo.lastPostTime = tmNow;
}
}
if(g_SysPonitInfo.pMarkFile)
{
fflush(g_SysPonitInfo.pMarkFile);
}
sleep(1);
}
pthread_detach(pthread_self());
}
int SysPointMarkInit(char* pDevId, int iMaxSize, int iPostTime)
{
LOG_EX(LOG_Debug, "pDevId = %s, iMaxSize = %d, iPostTime = %d\n", pDevId, iMaxSize, iPostTime);
if(g_SysPonitInfo.pDeviceId != NULL)
{
if(pDevId && strlen(pDevId) > 0)
{
free(g_SysPonitInfo.pDeviceId);
g_SysPonitInfo.pDeviceId = strdup(pDevId);
}
if(iMaxSize > 0)
{
g_SysPonitInfo.iMaxCacheSize = iMaxSize;
}
else
{
g_SysPonitInfo.iMaxCacheSize = 1024 * 10;
}
if(iPostTime > 0)
{
g_SysPonitInfo.iEveryUploadTime = iPostTime;
}
else
{
g_SysPonitInfo.iEveryUploadTime = SYS_POINT_UPLOAD_TIME;
}
}
else
{
memset(&g_SysPonitInfo, 0, sizeof(SYSPOINT_INFO));
if(pDevId && strlen(pDevId) > 0)
{
g_SysPonitInfo.pDeviceId = strdup(pDevId);
}
if(iMaxSize > 0)
{
g_SysPonitInfo.iMaxCacheSize = iMaxSize;
}
else
{
g_SysPonitInfo.iMaxCacheSize = 1024 * 1024;
}
if(iPostTime > 0)
{
g_SysPonitInfo.iEveryUploadTime = iPostTime;
}
else
{
g_SysPonitInfo.iEveryUploadTime = SYS_POINT_UPLOAD_TIME;
}
sprintf(g_SysPonitInfo.savePath, "%s/sys_point_mark.log", LOG_FILE_BASEDIR);
g_SysPonitInfo.pMarkFile = fopen(g_SysPonitInfo.savePath, "w+");
if(g_SysPonitInfo.pMarkFile == NULL)
{
LOG_EX(LOG_Error, "Create File: %s Error\n", g_SysPonitInfo.savePath);
return -ERR_OPEN_FILE;
}
uv_rwlock_init(&g_SysPonitInfo.uvRwLock);
uv_thread_create(&g_SysPonitInfo.uvIOThread, __uvSysPointIOProc, NULL);
}
return 0;
}
int SysPointMark(char* pMarkInfo)
{
PSYSPOINT_ITEM pItem;
if(pMarkInfo == NULL || strlen(pMarkInfo) == 0)
{
return -ERR_INPUT_PARAMS;
}
if(g_SysPonitInfo.iMaxCacheSize <= 0)
{
return -ERR_UNSUPPORT;
}
pItem = (PSYSPOINT_ITEM)malloc(sizeof(struct SYSPOINT_ITEM));
if(pItem == NULL)
{
return -ERR_MALLOC_MEMORY;
}
pItem->pContent = strdup(pMarkInfo);
g_SysPonitInfo.lastMarkTime = time(NULL);
uv_rwlock_wrlock(&g_SysPonitInfo.uvRwLock);
LL_APPEND(g_pSysPointArray, pItem);
uv_rwlock_wrunlock(&g_SysPonitInfo.uvRwLock);
//LOG_EX(LOG_Debug, "SysMark: %s\n", pItem->pContent);
return 0;
}
int SysPointMarkUpload(void)
{
int ret, size = 0;
char path[MAX_PATH];
memset(path, 0, MAX_PATH);
sprintf(path, "%s.txt", g_SysPonitInfo.savePath);
if(access(path, F_OK) == 0)
{
unlink(path);
}
GET_FILE_SIZE(g_SysPonitInfo.savePath, size);
if(size <= 0)
{
LOG_EX(LOG_Debug, "Upload System Mark Data [%s] Is Empty, Skip......\n", g_SysPonitInfo.savePath);
return 0;
}
rename(g_SysPonitInfo.savePath, path);
fclose(g_SysPonitInfo.pMarkFile);
g_SysPonitInfo.pMarkFile = fopen(g_SysPonitInfo.savePath, "w+");
size = 0;
do
{
ret = InetHttpUploadFileSync(GetCurServerAddr(MARK_POINT_MODULE), path, NULL);
sleep(1);
} while(ret != 0 && ++size < 3);
LOG_EX(LOG_Debug, "Upload System Mark Data [%s] To Server [%s]\n", path, GetCurServerAddr(MARK_POINT_MODULE));
unlink(path);
return 0;
}