Node.js Addon 返回数组

void GetDisplayedContent(const FunctionCallbackInfo<Value>& args) {
	Isolate* isolate = args.GetIsolate();

	// Check the number of arguments passed.
	if (args.Length() < 2) {
		// Throw an Error that is passed back to JavaScript
		isolate->ThrowException(Exception::TypeError(
			String::NewFromUtf8(isolate, "Wrong number of arguments:this function takes 2 arguments!")));
		return;
	}

	// Check the argument types
	if (!args[0]->IsString() || !args[1]->IsFunction()) {
		isolate->ThrowException(Exception::TypeError(
			String::NewFromUtf8(isolate, "Wrong argument types")));
		return;
	}
	
	//Perform the operation
	/*
	PlayInfo[0]:当前播放的节目表的驱动器编号;(SD or Flash or RAM)
	PlayInfo[1]:当前播放的第00套-第99套节目的索引号,从0开始编号;P00~P99
	PlayInfo[2]:当前播放的PLAYLIST.LY文件中的第几个节目,从0开始编号;
	PlayInfo[3]:区域1正在播放的节目项索引,从0开始编号
	PlayInfo[4]:区域2正在播放的节目项索引,从0开始编号
	PlayInfo[5]:区域3正在播放的节目项索引,从0开始编号
	PlayInfo[6]:区域4正在播放的节目项索引,从0开始编号
	*/
	char playInfo[7];
	int retVal =  SCL_GetPlayInfo(mDevID, (BYTE*)playInfo);
	if (!retVal) {
		SCL_Close(mDevID);
		printf("%c:\\P%02d\\PLAYLIST.LY\n", 1 + 65, 3);
		Local<Function> cb = Local<Function>::Cast(args[1]);
		const int argc = 1;
		Local<Value> argv[argc] = { String::NewFromUtf8(isolate,"SCL_GetPlayInfo failed") };
		
		cb->Call(Null(isolate), argc, argv);
		return;
	}
	//根据 PlayInfo 获取到正在显示得播放列表路径
	//驱动器编号
	int driveNo = playInfo[0];

	printf("%c:\\P%02d\\PLAYLIST.LY\n", playInfo[0] + 65, playInfo[1]);

	//文件名称
	char dir[30];
	sprintf(dir, "P%02d\\PLAYLIST.LY", playInfo[1]);
	
	//当前正在播放节目的编号
	int playIndex = playInfo[2];
	
	//下载播放列表
	retVal = SCL_ReceiveFile(mDevID, driveNo, dir, "PLAYLIST.LY");
	if (!retVal) {
		SCL_Close(mDevID);

		Local<Function> cb = Local<Function>::Cast(args[1]);
		const int argc = 1;
		Local<Value> argv[argc] = { String::NewFromUtf8(isolate,"SCL_ReceiveFile failed") };

		cb->Call(Null(isolate), argc, argv);
		return;
	}

	SCL_Close(mDevID);
	//读取PLAYLIST.LY,取到第playIndex项

	//解析显示内容
	
	//将读取到的项返回到javascript

	//创建数组
	Local<Array> arr = Array::New(isolate, 7);
	for (int i = 0; i != 7; i++) {
		arr->Set(i, v8::Int32::New(isolate, i));
	}

	Local<Function> cb = Local<Function>::Cast(args[1]);
	const int argc = 2;
	Local<Value> argv[argc] = { Null(isolate),arr };

	cb->Call(Null(isolate), argc, argv);
	return;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值