RDK Documentation (Open Sourced RDK Components)
dcautils.h
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 
20 
21 
22 /**
23  * @defgroup dca
24  * @{
25  **/
26 
27 
28 
29 
30 /**
31  * @defgroup dca
32  * @{
33  * @defgroup src
34  * @{
35  **/
36 
37 #include <stdio.h>
38 #include <stdlib.h>
39 #include <string.h>
40 #include <unistd.h>
41 
42 #include "cJSON.h"
43 
44 #define MAXLINE 4096
45 #define MAXLEN 512
46 #define LEN 14
47 
48 #define USLEEP_SEC 100
49 #define MAX_PROCESS 10
50 #define RDK_EC_MAXLEN 5 /* RDK Error code maximum length */
51 
52 #define RTL_FILENAME "/.rtl_temp.log"
53 #define EXEC_COUNTER_FILENAME "/tmp/.dcaCounter.txt"
54 
55 #define INCLUDE_PROPERTIES "/etc/include.properties"
56 #define DEVICE_PROPERTIES "/etc/device.properties"
57 #define DELIMITER "<#=#>"
58 
59 #define DEFAULT_SEEK_PREFIX "/opt/.telemetry/tmp/rtl_"
60 #define DEFAULT_LOG_PATH "/opt/logs/"
61 
62 
63 extern char *PERSISTENT_PATH;
64 extern char *LOG_PATH;
65 extern char *DEVICE_TYPE;
66 
67 extern char *RTL_TEMP_LOG_FILE;
68 extern char *OUTPUT_FILE;
69 
70 extern cJSON *SEARCH_RESULT_JSON;
71 extern cJSON *ROOT_JSON;
72 
73 extern int CUR_EXEC_COUNT;
74 extern long LAST_SEEK_VALUE;
75 
76 //#define LOG(fmt,__etc...) fprintf(stderr, "%s(%s:%d) "fmt"\n", __FUNCTION__, __FILE__, (int)__LINE__, ##__etc);fflush(stdout);
77 #define LOG(fmt,__etc...) \
78 { \
79  fprintf(stderr, fmt"\n", ##__etc); \
80  fflush(stdout); \
81 }
82 
83 #ifndef UNREFERENCED_PARAMETER
84 #define UNREFERENCED_PARAMETER(_p_) (void)(_p_)
85 #endif
86 
87 /* utility functions */
88 int getLoadAvg(void);
89 char *getsRotatedLog(char *buf, int buflen, char *name);
90 void clearConfVal(void);
91 void updateIncludeConfVal(char *logpath, char *perspath);
92 void updateConfVal(char *logpath, char *perspath);
93 int readLogSeek(char *name, long *seek_value);
94 void writeLogSeek(char *name, long seek_value);
95 int checkLogSeek(char *name, long prevSeekVal);
96 int isSkipParam(int skipInterval);
97 void updateExecCounter(void);
98 void saveExecCounter(void);
99 
100 /* JSON functions */
101 void initSearchResultJson(cJSON **root, cJSON **sr);
102 void addToSearchResult(char *key, char *value);
103 void clearSearchResultJson(cJSON **root);
104 void printJson(cJSON *root);
105 
106 int getProcUsage(char *processName);
107 
108 /** @} */
109 
110 
111 /** @} */
112 /** @} */
113 /** @} */
114 
115 
116 /** @} */
117 /** @} */
initSearchResultJson
void initSearchResultJson(cJSON **root, cJSON **sr)
This API creates "searchResult" JSON array.
Definition: dcajson.c:57
clearSearchResultJson
void clearSearchResultJson(cJSON **root)
This API deletes the result JSON object.
Definition: dcajson.c:87
updateExecCounter
void updateExecCounter(void)
To update current dca execution count.
Definition: dcautils.c:116
printJson
void printJson(cJSON *root)
This API is to print Json result.
Definition: dcajson.c:99
getProcUsage
int getProcUsage(char *processName)
To get process usage.
Definition: dcaproc.c:106
getsRotatedLog
char * getsRotatedLog(char *buf, int buflen, char *name)
Function to return rotated log file.
Definition: dcautils.c:190
writeLogSeek
void writeLogSeek(char *name, long seek_value)
Function to write the rotated Log file.
Definition: dcautils.c:678
getLoadAvg
int getLoadAvg(void)
This API is to find the load average of system and add it to the SearchResult JSON.
Definition: dcautils.c:57
isSkipParam
int isSkipParam(int skipInterval)
This API is to verify whether to skip this telemetry marker.
Definition: dcautils.c:163
readLogSeek
int readLogSeek(char *name, long *seek_value)
Function to read the rotated Log file.
Definition: dcautils.c:635
addToSearchResult
void addToSearchResult(char *key, char *value)
This API is to append the key/value pair to the SearchResult JSON array .
Definition: dcajson.c:71
clearConfVal
void clearConfVal(void)
This function is to clear/free the global paths.
Definition: dcautils.c:101
updateIncludeConfVal
void updateIncludeConfVal(char *logpath, char *perspath)
Function to update the global paths like PERSISTENT_PATH,LOG_PATH from include.properties file.
Definition: dcautils.c:397
updateConfVal
void updateConfVal(char *logpath, char *perspath)
Function to update the configuration values from device.properties file.
Definition: dcautils.c:491