86 lines
2.2 KiB
C
86 lines
2.2 KiB
C
/*
|
|||
|
|
* SPDX-License-Identifier: LicenseRef-Unisoc-General-1.0
|
||
|
|
*
|
||
|
|
* Copyright 2022-2023 Unisoc (Shanghai) Technologies Co., Ltd
|
||
|
|
*
|
||
|
|
* Licensed under the Unisoc General Software License, version 1.0 (the License);
|
||
|
|
* you may not use this file except in compliance with the License. You may obtain a copy of the License at
|
||
|
|
*
|
||
|
|
* https://www.unisoc.com/en_us/license/UNISOC_GENERAL_LICENSE_V1.0-EN_US
|
||
|
|
*
|
||
|
|
* Software distributed under the License is distributed on an "AS IS" BASIS,
|
||
|
|
* WITHOUT WARRANTIES OF ANY KIND, either express or implied.
|
||
|
|
* See the Unisoc General Software License, version 1.0 for more details.
|
||
|
|
*/
|
||
|
|
|
||
|
|
#include <signal.h>
|
||
|
|
#include <unistd.h>
|
||
|
|
#include <string.h>
|
||
|
|
#include <sys/stat.h>
|
||
|
|
#include <errno.h>
|
||
|
|
#include <fcntl.h>
|
||
|
|
#include <pthread.h>
|
||
|
|
#include <dbus/dbus.h>
|
||
|
|
#include "pty_con.h"
|
||
|
|
#include "gnss_adapter.h"
|
||
|
|
#include "dbushelper/dbushelper.h"
|
||
|
|
|
||
|
|
bool loop = true;
|
||
|
|
|
||
|
|
void sig_handler(int sig_number) {
|
||
|
|
if((SIGTERM == sig_number) || (SIGKILL == sig_number))
|
||
|
|
{
|
||
|
|
loop = false;
|
||
|
|
ALOGD("%s received signal %d, loop be set false.", __func__, sig_number);
|
||
|
|
}else{
|
||
|
|
ALOGD("%s received signal %d.", __func__, sig_number);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
void* dbus_thread_routine()
|
||
|
|
{
|
||
|
|
init_method_call_funcs();
|
||
|
|
dh_listenmethod(DBUS_BUS_SYSTEM, GNSS_ADAPTER_BUS_NAME, dbus_handler, 500);
|
||
|
|
}
|
||
|
|
|
||
|
|
int main(int argc, char* argv[])
|
||
|
|
{
|
||
|
|
ALOGD("gnss-adapter booting...");
|
||
|
|
|
||
|
|
if (signal(SIGINT, sig_handler) == SIG_ERR)
|
||
|
|
{
|
||
|
|
ALOGE("%s can not catch signal", __func__);
|
||
|
|
}
|
||
|
|
|
||
|
|
pthread_mutex_t main_mutex;
|
||
|
|
pthread_cond_t main_cond;
|
||
|
|
|
||
|
|
pthread_mutex_init(&main_mutex, NULL);
|
||
|
|
pthread_cond_init(&main_cond, NULL);
|
||
|
|
|
||
|
|
touch_device("/dev/gnsspty0");/* Can only implement single read and write? */
|
||
|
|
|
||
|
|
//TODO create dbus handler
|
||
|
|
pthread_t dbus_thread;
|
||
|
|
|
||
|
|
pthread_create(&dbus_thread,
|
||
|
|
NULL,
|
||
|
|
dbus_thread_routine,
|
||
|
|
NULL);
|
||
|
|
ALOGD("dbus_thread established.");
|
||
|
|
|
||
|
|
pthread_detach(dbus_thread);
|
||
|
|
|
||
|
|
while(loop){//TODO shutdown/restart let it quit?
|
||
|
|
pthread_mutex_lock(&main_mutex);
|
||
|
|
ALOGD("gnss-adapter pthread_cond_wait here");
|
||
|
|
pthread_cond_wait(&main_cond, &main_mutex);
|
||
|
|
pthread_mutex_unlock(&main_mutex);
|
||
|
|
}
|
||
|
|
|
||
|
|
ALOGD("gnss-adapter exiting...");
|
||
|
|
free_method_call_funcs();
|
||
|
|
|
||
|
|
return 0;
|
||
|
|
}
|