|
@@ -12,7 +12,7 @@
|
|
|
#include <string.h>
|
|
|
#include <pthread.h>
|
|
|
#include <unistd.h> /*Unix 標準函數定義*/
|
|
|
-
|
|
|
+#include "SystemLogMessage.h"
|
|
|
|
|
|
typedef enum boolean { FALSE, TRUE } BOOL;
|
|
|
static pthread_mutex_t m;
|
|
@@ -213,7 +213,7 @@ unsigned int hashmap_hash_int(hashmap_map * m, char* keystring){
|
|
|
|
|
|
/* Knuth's Multiplicative Method */
|
|
|
key = (key >> 3) * 2654435761;
|
|
|
- printf("table_size=%d\n",hashMap[0].table_size);
|
|
|
+ DEBUG_INFO("table_size=%d\n",hashMap[0].table_size);
|
|
|
|
|
|
return key % hashMap[0].table_size;//key % m->table_size;
|
|
|
}
|
|
@@ -227,7 +227,7 @@ int hashmap_hash(map_t in, char* key){
|
|
|
int i;
|
|
|
|
|
|
/* If full, return immediately */
|
|
|
- printf("hashMap[0].table_size=%d\n",hashMap[0].table_size);
|
|
|
+ DEBUG_INFO("hashMap[0].table_size=%d\n",hashMap[0].table_size);
|
|
|
if(hashMap[0].size >= (hashMap[0].table_size/2)) return MAP_FULL;
|
|
|
|
|
|
/* Find the best index */
|
|
@@ -237,14 +237,14 @@ int hashmap_hash(map_t in, char* key){
|
|
|
for(i = 0; i< MAX_CHAIN_LENGTH; i++){
|
|
|
if(hashMap[0].data[curr].in_use == 0)
|
|
|
{
|
|
|
- printf(" no in_use \n");
|
|
|
+ DEBUG_INFO(" no in_use \n");
|
|
|
return curr;
|
|
|
}
|
|
|
|
|
|
|
|
|
if(hashMap[0].data[curr].in_use == 1 && (strcmp(hashMap[0].data[curr].key,key)==0))
|
|
|
{
|
|
|
- printf("key use, key exist!!!!\n");
|
|
|
+ DEBUG_INFO("key use, key exist!!!!\n");
|
|
|
return curr;
|
|
|
}
|
|
|
|
|
@@ -354,7 +354,7 @@ int hashmap_put(map_t in, char* key, any_t value){
|
|
|
index = hashmap_hash(in, key);
|
|
|
}
|
|
|
|
|
|
- printf("hash index=%d\n",index);
|
|
|
+ DEBUG_INFO("hash index=%d\n",index);
|
|
|
/* Set the data */
|
|
|
strcpy(hashMap[0].data[index].data, value);
|
|
|
strcpy(hashMap[0].data[index].key, key);
|
|
@@ -363,9 +363,9 @@ int hashmap_put(map_t in, char* key, any_t value){
|
|
|
hashMap[0].data[index].in_use = 1;
|
|
|
hashMap[0].size++;
|
|
|
|
|
|
- printf("hash m->data[index].data=%s\n",hashMap[0].data[index].data);
|
|
|
- printf("hash m->data[index].key=%s\n",hashMap[0].data[index].key);
|
|
|
- printf("hash m->data[index].in_use=%d\n",hashMap[0].data[index].in_use);
|
|
|
+ DEBUG_INFO("hash m->data[index].data=%s\n",hashMap[0].data[index].data);
|
|
|
+ DEBUG_INFO("hash m->data[index].key=%s\n",hashMap[0].data[index].key);
|
|
|
+ DEBUG_INFO("hash m->data[index].in_use=%d\n",hashMap[0].data[index].in_use);
|
|
|
|
|
|
return MAP_OK;
|
|
|
|
|
@@ -410,26 +410,26 @@ int hashmap_get(map_t in, char* key, any_t *arg){
|
|
|
|
|
|
/* Find data location */
|
|
|
curr = hashmap_hash_int(hashMap, key);
|
|
|
- printf("MAP_get curr=%d\n",curr);
|
|
|
+ DEBUG_INFO("MAP_get curr=%d\n",curr);
|
|
|
|
|
|
/* Linear probing, if necessary */
|
|
|
for(i = 0; i<MAX_CHAIN_LENGTH; i++){
|
|
|
|
|
|
int in_use = hashMap[0].data[curr].in_use;
|
|
|
- printf("MAP_get in use=%d\n",in_use);
|
|
|
+ DEBUG_INFO("MAP_get in use=%d\n",in_use);
|
|
|
if (in_use == 1){
|
|
|
- printf("MAP_get hashMap.data[curr].key=%s\n", hashMap[0].data[curr].key);
|
|
|
- printf("MAP_get hashMap.data[curr].data=%s\n", hashMap[0].data[curr].data);
|
|
|
+ DEBUG_INFO("MAP_get hashMap.data[curr].key=%s\n", hashMap[0].data[curr].key);
|
|
|
+ DEBUG_INFO("MAP_get hashMap.data[curr].data=%s\n", hashMap[0].data[curr].data);
|
|
|
if (strcmp(hashMap[0].data[curr].key,key)==0){
|
|
|
strcpy(arg, hashMap[0].data[curr].data);
|
|
|
//*arg = (m->data[curr].data);
|
|
|
- printf("MAP_OK curr=%d\n",curr);
|
|
|
+ DEBUG_INFO("MAP_OK curr=%d\n",curr);
|
|
|
return MAP_OK;
|
|
|
}
|
|
|
}
|
|
|
|
|
|
curr = (curr + 1) % hashMap[0].table_size;
|
|
|
- printf("MAP_MISSING curr=%d\n",curr);
|
|
|
+ DEBUG_INFO("MAP_MISSING curr=%d\n",curr);
|
|
|
}
|
|
|
|
|
|
memset(arg, 0, sizeof arg);
|
|
@@ -530,11 +530,11 @@ int hashmap_remove(map_t in, char* key){
|
|
|
// m->data[curr].data = NULL;
|
|
|
// m->data[curr].key = NULL;
|
|
|
|
|
|
- printf("remove m->size=%d \n",hashMap[0].size);
|
|
|
+ DEBUG_INFO("remove m->size=%d \n",hashMap[0].size);
|
|
|
/* Reduce the size */
|
|
|
hashMap[0].size--;
|
|
|
|
|
|
- printf("remove ok!\n");
|
|
|
+ DEBUG_INFO("remove ok!\n");
|
|
|
return MAP_OK;
|
|
|
}
|
|
|
}
|
|
@@ -618,11 +618,11 @@ stat("../Storage/OCPP", &stats);
|
|
|
// Check for directory existence
|
|
|
if (S_ISDIR(stats.st_mode) == 1)
|
|
|
{
|
|
|
- //printf("\n directory exist \n");
|
|
|
+ //printf("directory exist \n");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- printf("\n directory not exist, create dir \n");
|
|
|
+ DEBUG_INFO("directory not exist, create dir \n");
|
|
|
sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
|
|
|
system(rmFileCmd);
|
|
|
}
|
|
@@ -635,12 +635,12 @@ if((access("../Storage/OCPP/MessageSent",F_OK))!=-1)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- printf("MessageSent not exist\n");
|
|
|
+ DEBUG_INFO("MessageSent not exist\n");
|
|
|
FILE *log = fopen("../Storage/OCPP/MessageSent", "w+");
|
|
|
|
|
|
if(log == NULL)
|
|
|
{
|
|
|
- printf("Can't Create File MessageSent \n");
|
|
|
+ DEBUG_ERROR("Can't Create File MessageSent \n");
|
|
|
return 0;
|
|
|
}
|
|
|
else
|
|
@@ -654,7 +654,7 @@ outfile = fopen ("../Storage/OCPP/MessageSent", "a");
|
|
|
sprintf(tempstring,"%s,%s\n", uuid,data);
|
|
|
fputs(tempstring, outfile);
|
|
|
fclose (outfile);
|
|
|
-printf("MessageSent add\n");
|
|
|
+DEBUG_INFO("MessageSent add\n");
|
|
|
return 1;
|
|
|
}
|
|
|
|
|
@@ -674,11 +674,11 @@ int MessageSent_get(char *uuid, char *data)
|
|
|
// Check for directory existence
|
|
|
if (S_ISDIR(stats.st_mode) == 1)
|
|
|
{
|
|
|
- //printf("\n directory exist \n");
|
|
|
+ //printf("directory exist \n");
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- printf("\n directory not exist, create dir \n");
|
|
|
+ DEBUG_INFO("directory not exist, create dir \n");
|
|
|
sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
|
|
|
system(rmFileCmd);
|
|
|
}
|
|
@@ -691,12 +691,12 @@ int MessageSent_get(char *uuid, char *data)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- printf("MessageSent not exist\n");
|
|
|
+ DEBUG_INFO("MessageSent not exist\n");
|
|
|
FILE *log = fopen("../Storage/OCPP/MessageSent", "w+");
|
|
|
|
|
|
if(log == NULL)
|
|
|
{
|
|
|
- printf("Can't Create File MessageSent \n");
|
|
|
+ DEBUG_ERROR("Can't Create File MessageSent \n");
|
|
|
return 0;
|
|
|
}
|
|
|
else
|
|
@@ -709,7 +709,7 @@ int MessageSent_get(char *uuid, char *data)
|
|
|
/* opening file for reading */
|
|
|
fp = fopen("../Storage/OCPP/MessageSent" , "r");
|
|
|
if(fp == NULL) {
|
|
|
- printf("Error opening file");
|
|
|
+ DEBUG_ERROR("Error opening file");
|
|
|
return FALSE;
|
|
|
}
|
|
|
|
|
@@ -719,7 +719,7 @@ int MessageSent_get(char *uuid, char *data)
|
|
|
|
|
|
if(c == EOF)
|
|
|
{
|
|
|
- printf("MessageSent is null\n");
|
|
|
+ DEBUG_INFO("MessageSent is null\n");
|
|
|
//strcpy(uuid,"");
|
|
|
strcpy(data,"");
|
|
|
result = FALSE;
|
|
@@ -750,7 +750,7 @@ int MessageSent_get(char *uuid, char *data)
|
|
|
|
|
|
if(strcmp(sstr, uuid) == 0)
|
|
|
{
|
|
|
- printf("\n uuid:%s compare all right!!! ", sstr);
|
|
|
+ DEBUG_INFO("uuid:%s compare all right!!!\n", sstr);
|
|
|
|
|
|
loc = strstr(str, ",");
|
|
|
memset(sstr ,0, sizeof(sstr) );
|
|
@@ -762,7 +762,7 @@ int MessageSent_get(char *uuid, char *data)
|
|
|
}
|
|
|
datastr[e] = '\0';
|
|
|
|
|
|
- printf("\n data:%s", datastr);
|
|
|
+ DEBUG_INFO("data:%s\n", datastr);
|
|
|
//strcpy(uuid,sstr);
|
|
|
strcpy(data,datastr);
|
|
|
result = TRUE;
|
|
@@ -798,7 +798,7 @@ if (S_ISDIR(stats.st_mode) == 1)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- printf("\n directory not exist, create dir \n");
|
|
|
+ DEBUG_INFO("\n directory not exist, create dir \n");
|
|
|
sprintf(rmFileCmd,"mkdir -p %s","../Storage/OCPP");
|
|
|
system(rmFileCmd);
|
|
|
}
|
|
@@ -811,12 +811,12 @@ if((access("../Storage/OCPP/MessageSent",F_OK))!=-1)
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- printf("MessageSent not exist\n");
|
|
|
+ DEBUG_INFO("MessageSent not exist\n");
|
|
|
FILE *log = fopen("../Storage/OCPP/MessageSent", "w+");
|
|
|
|
|
|
if(log == NULL)
|
|
|
{
|
|
|
- printf("log is NULL\n");
|
|
|
+ DEBUG_ERROR("log is NULL\n");
|
|
|
return 0;
|
|
|
}
|
|
|
else
|
|
@@ -842,7 +842,7 @@ rewind(infile);
|
|
|
|
|
|
if(c == EOF)
|
|
|
{
|
|
|
- printf("MessageSent is NULL\n");
|
|
|
+ DEBUG_INFO("MessageSent is NULL\n");
|
|
|
|
|
|
fclose(infile);
|
|
|
fclose(outfile);
|
|
@@ -890,7 +890,7 @@ else
|
|
|
}
|
|
|
else
|
|
|
{
|
|
|
- printf("Error: unable to rename the file");
|
|
|
+ DEBUG_ERROR("Error: unable to rename the file");
|
|
|
}
|
|
|
}
|
|
|
|