RDK Documentation (Open Sourced RDK Components)
btrMgr_main.c
Go to the documentation of this file.
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  * @file btrMgr_main.c
21  *
22  * @description This file defines bluetooth manager's Controller functionality
23  *
24  */
25 #include <stdio.h>
26 #include <stdbool.h>
27 
28 #include <signal.h>
29 #include <string.h>
30 
31 #include <time.h>
32 #include <unistd.h>
33 
34 #if defined(ENABLE_SD_NOTIFY)
35 #include <systemd/sd-daemon.h>
36 #endif
37 
38 #include "btmgr.h"
40 
41 #ifdef INCLUDE_BREAKPAD
42 #include "breakpad_wrapper.h"
43 #endif
44 
45 static bool gbExitBTRMgr = false;
46 
47 
48 static void
49 btrMgr_SignalHandler (
50  int i32SignalNumber
51 ) {
52  time_t curr = 0;
53 
54  time(&curr);
55  printf ("Received SIGNAL %d = %s - %s\n", i32SignalNumber, strsignal(i32SignalNumber), ctime(&curr));
56  fflush(stdout);
57 
58  if (i32SignalNumber == SIGTERM)
59  gbExitBTRMgr = true;
60 }
61 
62 
63 int
64 main (
65  void
66 ) {
67  time_t curr = 0;
68  BTRMGR_Result_t lenBtrMgrResult = BTRMGR_RESULT_SUCCESS;
69  BTRMGR_Result_t lenBtrMgrSoResult = BTRMGR_RESULT_SUCCESS;
70 
71 
72  if ((lenBtrMgrResult = BTRMGR_Init()) == BTRMGR_RESULT_SUCCESS) {
73 
74  signal(SIGTERM, btrMgr_SignalHandler);
75 
76 #if defined(ENABLE_SD_NOTIFY)
77  sd_notify(0, "READY=1");
78 #endif
79 
80  time(&curr);
81  printf ("I-ARM BTMgr Bus: BTRMgr_BeginIARMMode %s\n", ctime(&curr));
82  fflush(stdout);
83 
84  BTRMgr_BeginIARMMode();
85 
86 #ifdef INCLUDE_BREAKPAD
87  breakpad_ExceptionHandler();
88 #endif
89 
90  lenBtrMgrSoResult = BTRMGR_StartAudioStreamingOut_StartUp(0, BTRMGR_DEVICE_OP_TYPE_AUDIO_OUTPUT);
91  printf ("BTRMGR_StartAudioStreamingOut_StartUp - %d\n", lenBtrMgrSoResult);
92  fflush(stdout);
93 
94 #if defined(ENABLE_SD_NOTIFY)
95  sd_notifyf(0, "READY=1\n"
96  "STATUS=BTRMgr Successfully Initialized - Processing requests…\n"
97  "MAINPID=%lu", (unsigned long) getpid());
98 #endif
99 
100  while (gbExitBTRMgr == false) {
101  time(&curr);
102  printf ("I-ARM BTMgr Bus: HeartBeat at %s\n", ctime(&curr));
103  fflush(stdout);
104  sleep(10);
105  }
106 
107 #if defined(ENABLE_SD_NOTIFY)
108  sd_notify(0, "STOPPING=1");
109 #endif
110 
111  BTRMgr_TermIARMMode();
112 
113  time(&curr);
114  printf ("I-ARM BTMgr Bus: BTRMgr_TermIARMMode %s\n", ctime(&curr));
115  fflush(stdout);
116 
117  }
118 
119 
120  if (lenBtrMgrResult != BTRMGR_RESULT_SUCCESS) {
121 #if defined(ENABLE_SD_NOTIFY)
122  sd_notifyf(0, SD_EMERG "STATUS=BTRMgr Init Failed %d\n", lenBtrMgrResult);
123 #endif
124  printf ("BTRMGR_Init Failed\n");
125  fflush(stdout);
126  }
127 
128 
129  lenBtrMgrResult = BTRMGR_DeInit();
130 
131  time(&curr);
132  printf ("BTRMGR_DeInit %d - %s\n", lenBtrMgrResult, ctime(&curr));
133  fflush(stdout);
134 
135 #if defined(ENABLE_SD_NOTIFY)
136  sd_notifyf(0, "STOPPING=1\n"
137  "STATUS=BTRMgr Successfully DeInitialized\n"
138  "MAINPID=%lu", (unsigned long) getpid());
139 #endif
140 
141  return lenBtrMgrResult;
142 }
btrMgr_IarmInternalIfce.h
BTRMGR_DeInit
BTRMGR_Result_t BTRMGR_DeInit(void)
This API invokes the deinit function of bluetooth core and persistant interface module.
Definition: btrMgr.c:2455
BTRMGR_Result_t
enum _BTRMGR_Result_t BTRMGR_Result_t
Represents the status of the operation.
btmgr.h
BTRMGR_StartAudioStreamingOut_StartUp
BTRMGR_Result_t BTRMGR_StartAudioStreamingOut_StartUp(unsigned char aui8AdapterIdx, BTRMGR_DeviceOperationType_t aenBTRMgrDevConT)
This API initates the streaming from the device with default operation type.
Definition: btrMgr.c:4100
BTRMGR_Init
BTRMGR_Result_t BTRMGR_Init(void)
This API initializes the bluetooth manager.
Definition: btrMgr.c:2295