⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 httpoperation_nonblock.c

📁 一个在Linux下开发的IP摄像头的驱动程序及控制软件
💻 C
字号:
/*
 * This sample code is written by nonblock mode. If you want to use block mode,
 * please reference the HttpOperation sample.
 *
 * The corresponding URL commands can be found in appendix of user manual.
 *
 */

#include "Utility.h"

int g_iWaitCount = 0;

void __stdcall SrvMgrStatusCallback(TSVRCTRL_NOTIFY_CONT *ptContent);


int main(int argc, char* argv[])
{
	SCODE scRet = S_OK;
	HANDLE hServerMgr = NULL;
	HANDLE hDevice = NULL;
	TCHAR szModelName[MAX_PATH] = {0};
	TSERVER_INFO tServerInfo;

	// Http operation parameters
	DWORD dwBufLength = MAX_PATH;
	HANDLE hOperation;
	TSVRCTRL_NOTIFY tNotify;

	// example HTTP Write command input: -I192.168.0.1 -H80 -Uroot -Proot -T30000 -C/cgi-bin/admin/setparam.cgi?system_hostname=test
	if (ParseInputArgument(argc, argv, &tServerInfo, eSrvMgrHTTPOperation) != S_OK)
	{
		return 0;
	}

	// 1. Initialization
	scRet = ServerManagerInitBlock(&hServerMgr, &hDevice, szModelName, tServerInfo);
	if (S_OK != scRet)
	{
		printf("ServerManagerInitBlock failed...\n");
		return 0;
	}

	// 2. Send HTTP Write command in nonblock mode
	memset(&tNotify, 0, sizeof(tNotify));
	tNotify.pfCB = (SVRCTRL_STATUS_CALLBACK)&SrvMgrStatusCallback;
	scRet = ServerManager_SendHttpCommand(hDevice, tServerInfo.tHttpOperation.szUrlCommand, tServerInfo.tHttpOperation.bPost, &tNotify, &hOperation);
	if (S_OK != scRet)
	{
		printf("ServerManager_SendHttpCommand failed: %X\n", scRet);
		goto Lab_Exit;
	}

	// 3. wait callback function 30 sec
	while (g_iWaitCount < 30)
	{
#ifdef _WIN32
		Sleep(1000);
#else
		sleep(1);
#endif  //_WIN32
		g_iWaitCount++;
		printf(".");
	}

Lab_Exit:
	// 4. Release all resource
	ServerManagerRelease(&hServerMgr, &hDevice);

	return 0;
}

void __stdcall SrvMgrStatusCallback(TSVRCTRL_NOTIFY_CONT *ptContent)
{
	if (ptContent->scStatusCode == S_OK)
	{
		printf("Callback function success.");
	}
	else
	{
		printf("Callback function failed :%X\n", ptContent->scStatusCode);
	}
	g_iWaitCount = 30;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -