/*
* date 20120510
* last author: baojinyu
* usage: successful as socket server
* successful as dlna media file server
* */
#include "Neptune.h"
#include "Platinum.h"
#include <sys/ioctl.h>
#include <sys/select.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <netinet/in.h> /* definations of sa_family structre,htons,INADDR_ANY,... */
#include <arpa/inet.h> /* name ip format */
#include <sys/types.h> /*give the defination of pid_t*/
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#include <ctype.h> /* isspace() */
#define BUFFER_MAX 1024 /* input buffer for commands */
#define TOKEN_MAX 8 /* max number of arguments in buffer */
#define REPLY_MAX 256 /* largest reply allowed */
#define MAX_QUE_CONN_NM 10
NPT_SET_LOCAL_LOGGER("platinum.media.server.file")
//example:NPT_Debug("ERROR: failed to load entity (%d)\n", result);
int sockfd;
static NPT_Flags deviceStartFlag = 0; //服务启动状态为1,服务停止则状态为0
PLT_UPnP upnp;
PLT_DeviceHostReference device;
int init_sock()
{
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if (sockfd == -1)
{
NPT_LOG_INFO("baojinyu---------------create socket error! \n");
exit(1);
}
NPT_LOG_INFO("baojinyu---------------create socket successfully .\n");
return 0;
}
int init_device()
{
device = new PLT_FileMediaServer(
"/data/local/1.3gp",//"/data/local/if.mp3",
"Platinum UPnP Media Server",
false,
"SAMEDEVICEGUID", // NULL for random ID
(NPT_UInt16)1194);
NPT_List<NPT_IpAddress> list;
NPT_CHECK_SEVERE(PLT_UPnPMessageHelper::GetIPAddresses(list));
NPT_String ip = list.GetFirstItem()->ToString();
device->m_ModelDescription = "Platinum File Media Server";
device->m_ModelURL = "http://www.plutinosoft.com/";
device->m_ModelNumber = "1.0";
device->m_ModelName = "Platinum File Media Server";
device->m_Manufacturer = "Plutinosoft";
device->m_ManufacturerURL = "http://www.plutinosoft.com/";
upnp.AddDevice(device);
NPT_CHECK_SEVERE(upnp.Start());//Just for test.
return 0;
}
int init()
{
init_sock();
init_device();
return 0;
}
//the following are commands.
static int HandleCmd_dmsStartStop(char **arg, char reply[REPLY_MAX])
{
if (!deviceStartFlag){
//start service
NPT_LOG_INFO("baojinyu------------socket cmd Start。");
NPT_CHECK_SEVERE(upnp.Start());
NPT_LOG_INFO("baojinyu------------upnp Start success!");
deviceStartFlag = 1;
}
else{
//stop service
NPT_LOG_INFO("baojinyu------------socket cmd stop。");
upnp.Stop();
NPT_LOG_INFO("baojinyu------------upnp stop success!");
deviceStartFlag = 0;
}
return deviceStartFlag;
}
struct cmdinfo {
const char *name;
unsigned numargs;
int (*func)(char **arg, char reply[REPLY_MAX]);
};
struct cmdinfo cmds[] = {
//{ "isMouse", 1, isMouse },
dms代码
最新推荐文章于 2021-05-15 11:55:49 发布
