RDK Documentation (Open Sourced RDK Components)
dsMgrMain.c
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 iarmmgrs
24 * @{
25 * @defgroup dsmgr
26 * @{
27 **/
28 
29 
30 #include "dsMgrInternal.h"
31 #include "dsserverregisterlog.h"
32 #include "dshalregisterlog.h"
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 #include <stdio.h>
37 #include <sys/types.h>
38 #include <unistd.h>
39 #include "libIBus.h"
40 #ifdef __cplusplus
41 }
42 #endif
43 #ifdef ENABLE_SD_NOTIFY
44 #include <systemd/sd-daemon.h>
45 #endif
46 #ifdef RDK_LOGGER_ENABLED
47 
48 int b_rdk_logger_enabled = 0;
49 
50 void logCallback(const char *buff)
51 {
52  INT_DEBUG("%s",buff);
53 }
54 void dslogCallback(int priority,const char *buff)
55 {
56  if(priority == 0)
57  {
58  INT_INFO("%s",buff);
59  }
60  else if(priority == 1)
61  {
62  INT_WARN("%s",buff);
63  }
64  else if(priority == 2)
65  {
66  INT_ERROR("%s",buff);
67  }
68  else if(priority == 3)
69  {
70  INT_DEBUG("%s",buff);
71  }
72 }
73 
74 #endif
75 
76 int main(int argc, char *argv[])
77 {
78  const char* debugConfigFile = NULL;
79  int itr=0;
80 
81  while (itr < argc)
82  {
83  if(strcmp(argv[itr],"--debugconfig")==0)
84  {
85  itr++;
86  if (itr < argc)
87  {
88  debugConfigFile = argv[itr];
89  }
90  else
91  {
92  break;
93  }
94  }
95  itr++;
96  }
97 
98 #ifdef RDK_LOGGER_ENABLED
99 
100  if(rdk_logger_init(debugConfigFile) == 0) b_rdk_logger_enabled = 1;
101  IARM_Bus_RegisterForLog(logCallback);
102  DSServer_RegisterForLog(dslogCallback);
103 
104 // TODO: This could be enabled only after ensuring that all platforms have DSHal_RegisterForLog implemented
105 // in devicesettings/hal
106 //
107 // DSHal_RegisterForLog(dslogCallback);
108 
109 #endif
110  DSMgr_Start();
111  #ifdef ENABLE_SD_NOTIFY
112  sd_notifyf(0, "READY=1\n"
113  "STATUS=DsMgr is Successfully Initialized\n"
114  "MAINPID=%lu", (unsigned long) getpid());
115  #endif
116 
117 #ifdef PID_FILE_PATH
118 #define xstr(s) str(s)
119 #define str(s) #s
120  // write pidfile because sd_notify() does not work inside container
121  IARM_Bus_WritePIDFile(xstr(PID_FILE_PATH) "/dsmgr.pid");
122 #endif
123  DSMgr_Loop();
124  DSMgr_Stop();
125  return 0;
126 }
127 
128 
129 
130 
131 /** @} */
132 /** @} */
IARM_Bus_WritePIDFile
void IARM_Bus_WritePIDFile(const char *path)
Write PID file.
libIBus.h
RDK IARM-Bus API Declarations.
rdk_logger_init
rdk_Error rdk_logger_init(const char *debugConfigFile)
Initialize the logger. Sets up the environment variable storage by parsing debug configuration file t...
Definition: rdk_logger_init.c:57
dsMgrInternal.h