コード例 #1
0
ファイル: cdms_filesys_main.c プロジェクト: Coramo/mupnp
int main(int argc, char* argv[])
{
    mUpnpMediaServer* dms;
    char* pubDir;
    int programNameIdx;
    int key;
#if defined(WIN32)
    TCHAR myDocumentPath[MAX_PATH];
#if defined(UNICODE)
    char myDocumentPathUtf8[MAX_PATH];
#endif
#endif

    pubDir = NULL;

    if (1 < argc) {
        pubDir = argv[argc - 1];
    }
    else {
#if defined(WIN32)
        SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, myDocumentPath);
#if defined(UNICODE)
        WideCharToMultiByte(CP_UTF8, 0, myDocumentPath, -1, myDocumentPathUtf8, (MAX_PATH - 1), NULL, NULL);
        pubDir = myDocumentPathUtf8;
#else
        pubDir = myDocumentPath;
#endif
#endif
    }

    if (!pubDir) {
#if defined(WIN32)
        programNameIdx = mupnp_strrchr(argv[0], "\\", 1);
#else
        programNameIdx = mupnp_strrchr(argv[0], "/", 1);
#endif
        printf("Usage : %s <publication directory>\n", (argv[0] + programNameIdx + 1));
        exit(1);
    }

    dms = mupnp_upnpav_dms_filesys_new();
    mupnp_upnpav_dms_filesys_setpublicationdirectory(dms, pubDir);

    // Demonstrate how to use mUpnpAvProtocolInfo to register protocolinfo.
    // Which is required for some devices to work, like Sony Bravia TV.
    // (Bravia actually also needs additionalinfo set to "DLNA.ORG_PN=MP3" etc)
    {
        char* protocols[] = { "*", "video/*", "audio/*", "image/*", NULL };
        int i;
        mUpnpAvProtocolInfo* info;
        for (i = 0; protocols[i]; i++) {
            if ((info = mupnp_upnpav_protocolinfo_new())) {
                mupnp_upnpav_protocolinfo_setprotocol(info, "http-get");
                mupnp_upnpav_protocolinfo_setnetwork(info, "*");
                mupnp_upnpav_protocolinfo_setmimetype(info, protocols[i]);
                mupnp_upnpav_protocolinfo_setadditionalinfo(info, "*");
                mupnp_upnpav_dms_addprotocolinfo(dms, info);
            }
        }
    }

    mupnp_upnpav_dms_filesys_start(dms);

#if !defined(WIN32) || defined(__CYGWIN__)
    mupnp_kb_init();
#endif

    PrintKeyMessage();

    do {
#if defined(WIN32) && !defined(__CYGWIN__)
        key = _getch();
#else
        key = getchar();
#endif
        key = toupper(key);
        switch (key) {
        case 'X':
            break;
        default:
            PrintKeyMessage();
        }
    } while (key != 'X');

#if !defined(WIN32) || defined(__CYGWIN__)
    mupnp_kb_exit();
#endif

    mupnp_upnpav_dms_filesys_stop(dms);
    mupnp_upnpav_dms_filesys_delete(dms);

    return 0;
}
コード例 #2
0
ファイル: upnpdump.c プロジェクト: WilliamRen/mupnpc
MBEG
#else
int main( int argc, char* argv[] )
#endif
{
	mUpnpControlPoint *ctrlPoint;
	int key;
	
	ctrlPoint = mupnp_controlpoint_new();
	mupnp_controlpoint_setssdplistener(ctrlPoint, SSDPNotifyListner);
	mupnp_controlpoint_seteventlistener(ctrlPoint, EventListener);
	if (mupnp_controlpoint_start(ctrlPoint) == false) {
		printf("Couldn't start this control point !!");
		exit(1);
	}
	
	PrintKeyMessage();

#if (!defined(WIN32) || defined(__CYGWIN__)) && !defined(TENGINE)
	kbinit();
#endif
	
	key = 0;
	do
	{
#if !defined(TENGINE)
		key = kbgetkey();
		key = toupper(key);
		switch (key) {
		case 'P':
			PrintControlPointDevice(ctrlPoint);
			break;
#if !defined(MUPNP_NOUSE_ACTIONCTRL)
		case 'C':
			ControlDeviceAlter(ctrlPoint, CMD_NO_ALTERATIONS);
			break;

		case 'O':
			ControlDeviceAlter(ctrlPoint, CMD_LOOP_ACTION_CALLS);
			break;
#endif
#if !defined(MUPNP_NOUSE_QUERYCTRL)
		case 'Q':
			QueryDevice(ctrlPoint);
			break;
#endif
#if !defined(MUPNP_NOUSE_SUBSCRIPTION)
		case 'S':
			SubscribeService(ctrlPoint);
			break;
		case 'U':
			UnsubscribeService(ctrlPoint);
			break;
#endif
                case 'M':
                        SetMXValue(ctrlPoint);
                        break;
		case 'R':
	          printf("M-Search upnp::rootdevice\n");
		  mupnp_controlpoint_search(ctrlPoint, MUPNP_ST_ROOT_DEVICE);
		  break;
		case 'H':
	          printf("M-Search ssdp:all\n");
		  mupnp_controlpoint_search(ctrlPoint, "ssdp:all");
		  break;
		case 'V':
	          printf("M-Search device type\n");
		  mupnp_controlpoint_search(ctrlPoint, "urn:schemas-upnp-org:device:clock:1");
		  break;
		case 'T':
	          printf("M-Search service type\n");
		  mupnp_controlpoint_search(ctrlPoint, "urn:schemas-upnp-org:service:timer:1");
		  break;
		case 'A':
		  {
			  int i;

			  printf("Doing all searches four times...\n");
			  
			  for (i=0; i<4; i++)
			  {
				  mupnp_controlpoint_search(ctrlPoint, MUPNP_ST_ROOT_DEVICE);
				  mupnp_controlpoint_search(ctrlPoint, "ssdp:all");
				  mupnp_controlpoint_search(ctrlPoint, "urn:schemas-upnp-org:device:clock:1");
				  mupnp_controlpoint_search(ctrlPoint, "urn:schemas-upnp-org:service:timer:1");
			  }
			  
			  printf("Done (doing all searches four times).\n");
		  }
		  break;
		case 'X':
			break;
		default:
			PrintKeyMessage();
		}
#else
		mupnp_wait(1000);
#endif
	} while( key != 'X');

#if (!defined(WIN32) || defined(__CYGWIN__)) && !defined(TENGINE)
	kbexit();
#endif
	
	mupnp_controlpoint_stop(ctrlPoint);
	mupnp_controlpoint_delete(ctrlPoint);
	
	return(0);
}