📄 basic_device.c
字号:
/*** Copyright (c) 2004 Axis Communications AB.** All rights reserved.** ** Redistribution and use in source and binary forms, with or without** modification, are permitted provided that the following conditions are met:** ** * Redistributions of source code must retain the above copyright notice,** this list of conditions and the following disclaimer.** * Redistributions in binary form must reproduce the above copyright notice,** this list of conditions and the following disclaimer in the documentation** and/or other materials provided with the distribution.** * Neither name of Axis Communications AB nor the names of its contributors** may be used to endorse or promote products derived from this software** without specific prior written permission.** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS** ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL OR** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,** EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,** PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR** PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY** OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING** NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS** SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.*/#define _GNU_SOURCE#include <stdio.h>#include <stdlib.h>#include <string.h>#include <errno.h>#include <unistd.h>#include <syslog.h>#include <upnp/upnp.h>#include <upnp/upnptools.h>#include "../main/global.h"#include "../main/debug.h"#include "basic_device.h"static int deviceHandle;static struct GlobalData *globalData;static inteventHandler(Upnp_EventType event_type, void *event, void *cookie);static voidmyInit(void){ int rc; char *tmp; struct GlobalConfig config; readConfig(&config); createRootDescDoc(&config); createSCPDBasicDescDoc(&config); /* Init web server. */ TRACE(syslog(LOG_DEBUG, "%s:%s", __FILE__, __FUNCTION__)); rc = UpnpSetWebServerRootDir(WEB_SERVER_ROOT); if (rc != 0) { syslog(LOG_CRIT, "UpnpSetWebServerRootDir(%s) failed: %d", WEB_SERVER_ROOT, rc); exit(EXIT_FAILURE); } DBG1(syslog(LOG_DEBUG, "Web root dir : %s", WEB_SERVER_ROOT)); /* Register root device description document. */ asprintf(&tmp, "http://%s:%d/%s", UpnpGetServerIpAddress(), UpnpGetServerPort(), ROOT_DESC_DOC); rc = UpnpRegisterRootDevice(tmp, eventHandler, &deviceHandle, &deviceHandle); if (rc != 0) { syslog(LOG_CRIT, "UpnpRegisterRootDevice(%s) failed: %d", tmp, rc); exit(EXIT_FAILURE); } DBG1(syslog(LOG_DEBUG, "Root desc doc: %s", tmp)); free(tmp); freeConfig(&config); TRACE(syslog(LOG_DEBUG, "%s:%s exit", __FILE__, __FUNCTION__));}static voidmyStart(void){ int rc; TRACE(syslog(LOG_DEBUG, "%s:%s", __FILE__, __FUNCTION__)); rc = UpnpSendAdvertisement(deviceHandle, 100); if (rc != 0) { syslog(LOG_ERR, "UpnpSendAdvertisement failed: %d", rc); } TRACE(syslog(LOG_DEBUG, "%s:%s exit", __FILE__, __FUNCTION__));}static voidmyFinish(void){}static voidmyCleanup(void){ TRACE(syslog(LOG_DEBUG, "%s:%s", __FILE__, __FUNCTION__)); UpnpUnRegisterRootDevice(deviceHandle); removeRootDescDoc(); removeSCPDBasicDescDoc(); TRACE(syslog(LOG_DEBUG, "%s:%s exit", __FILE__, __FUNCTION__));}static voidmyTimeout(void){}static voidmyReconfigure(void){}voidinitLib(struct LibraryDef *libdef, struct GlobalData *gdata){ TRACE(syslog(LOG_DEBUG, "%s:%s", __FILE__, __FUNCTION__)); libdef->init = myInit; libdef->start = myStart; libdef->finish = myFinish; libdef->cleanup = myCleanup; libdef->timeout = myTimeout; libdef->reconfigure = myReconfigure; globalData = gdata; TRACE(syslog(LOG_DEBUG, "%s:%s exit", __FILE__, __FUNCTION__));}static inteventHandler(Upnp_EventType event_type, void *event, void *cookie){ TRACE(syslog(LOG_DEBUG, "%s:%s", __FILE__, __FUNCTION__)); switch (event_type) { /* * SSDP Stuff */ case UPNP_DISCOVERY_SEARCH_RESULT: case UPNP_DISCOVERY_ADVERTISEMENT_ALIVE: case UPNP_DISCOVERY_SEARCH_TIMEOUT: case UPNP_DISCOVERY_ADVERTISEMENT_BYEBYE: { break; } /* * SOAP Stuff */ case UPNP_CONTROL_ACTION_COMPLETE: case UPNP_CONTROL_GET_VAR_COMPLETE: case UPNP_CONTROL_GET_VAR_REQUEST: case UPNP_CONTROL_ACTION_REQUEST: { break; } /* * GENA Stuff */ case UPNP_EVENT_RECEIVED: case UPNP_EVENT_SUBSCRIBE_COMPLETE: case UPNP_EVENT_UNSUBSCRIBE_COMPLETE: case UPNP_EVENT_RENEWAL_COMPLETE: case UPNP_EVENT_AUTORENEWAL_FAILED: case UPNP_EVENT_SUBSCRIPTION_EXPIRED: case UPNP_EVENT_SUBSCRIPTION_REQUEST: { break; } } TRACE(syslog(LOG_DEBUG, "%s:%s exit", __FILE__, __FUNCTION__)); return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -