void ServiceRegistryWrapper::findByName(const v8::FunctionCallbackInfo<v8::Value>& args)
{
	Poco::OSP::ServiceRegistry* pServiceRegistry = Poco::JS::Core::Wrapper::unwrapNative<Poco::OSP::ServiceRegistry>(args);

	try
	{
		if (args.Length() == 1)
		{
			std::string serviceName = toString(args[0]);
			Poco::OSP::ServiceRef::Ptr pServiceRef = pServiceRegistry->findByName(serviceName);
			if (pServiceRef)
			{
				ServiceRefWrapper wrapper;
				v8::Persistent<v8::Object> serviceRefObject(args.GetIsolate(), wrapper.wrapNativePersistent(args.GetIsolate(), pServiceRef));
				args.GetReturnValue().Set(serviceRefObject);
				return;
			}
			args.GetReturnValue().Set(v8::Null(args.GetIsolate()));
		}
		else
		{
			returnException(args, std::string("bad arguments - service name required"));
		}
	}
	catch (Poco::Exception& exc)
	{
		returnException(args, exc);
	}
}
void ServiceRegistryWrapper::find(const v8::FunctionCallbackInfo<v8::Value>& args)
{
	Poco::OSP::ServiceRegistry* pServiceRegistry = Poco::JS::Core::Wrapper::unwrapNative<Poco::OSP::ServiceRegistry>(args);

	try
	{
		if (args.Length() == 1)
		{
			ServiceRefWrapper wrapper;
			std::string serviceQuery = toString(args[0]);
			std::vector<Poco::OSP::ServiceRef::Ptr> services;
			v8::Local<v8::Array> result = v8::Array::New(args.GetIsolate());
			int i = 0;
			if (pServiceRegistry->find(serviceQuery, services))
			{
				for (std::vector<Poco::OSP::ServiceRef::Ptr>::iterator it = services.begin(); it != services.end(); ++it)
				{
					v8::Persistent<v8::Object>& serviceRefObject(wrapper.wrapNativePersistent(args.GetIsolate(), *it));
					v8::Local<v8::Object> localServiceRefObject = v8::Local<v8::Object>::New(args.GetIsolate(), serviceRefObject);
					result->Set(i++, localServiceRefObject);
				}
			}
			args.GetReturnValue().Set(result);
		}
		else
		{
			returnException(args, std::string("bad arguments - service query required"));
		}
	}
	catch (Poco::Exception& exc)
	{
		returnException(args, exc);
	}
}
void ServiceRegistryWrapper::createListener(const v8::FunctionCallbackInfo<v8::Value>& args)
{
	v8::HandleScope handleScope(args.GetIsolate());
	Poco::OSP::ServiceRegistry* pServiceRegistry = Poco::JS::Core::Wrapper::unwrapNative<Poco::OSP::ServiceRegistry>(args);

	try
	{
		if (args.Length() == 3 && args[1]->IsFunction() && args[2]->IsFunction())
		{
			std::string query = toString(args[0]);

			ServiceListenerWrapper wrapper;
			ServiceListenerHolder::Ptr pHolder = new ServiceListenerHolder(
				args.GetIsolate(),
				Poco::JS::Core::JSExecutor::current(),
				*pServiceRegistry,
				query,
				args[1].As<v8::Function>(),
				args[2].As<v8::Function>());

			v8::Persistent<v8::Object>& serviceListenerObject(wrapper.wrapNativePersistent(args.GetIsolate(), pHolder));
			v8::Local<v8::Object> localListenerObject = v8::Local<v8::Object>::New(args.GetIsolate(), serviceListenerObject);
			args.GetReturnValue().Set(localListenerObject);
		}
		else
		{
			returnException(args, std::string("bad arguments - service query, registered callback and unregistered callback required"));
		}
	}
	catch (Poco::Exception& exc)
	{
		returnException(args, exc);
	}
}
示例#4
0
void SessionWrapper::construct(const v8::FunctionCallbackInfo<v8::Value>& args)
{
	std::string connector;
	std::string connectionString;
	
	if (args.Length() == 2)
	{
		connector = toString(args[0]);
		connectionString = toString(args[1]);
	}
	else
	{
		returnException(args, std::string("bad arguments: connector and connection string required"));
		return;
	}
	
	SessionHolder* pSessionHolder = 0;
	try
	{
		pSessionHolder = new SessionHolder(connector, connectionString);
		SessionWrapper wrapper;
		v8::Persistent<v8::Object>& sessionObject(wrapper.wrapNativePersistent(args.GetIsolate(), pSessionHolder));
		args.GetReturnValue().Set(sessionObject);
	}
	catch (Poco::Exception& exc)
	{
		delete pSessionHolder;
		returnException(args, exc);
	}
}
示例#5
0
void TimerWrapper::cancel(const v8::FunctionCallbackInfo<v8::Value>& args)
{
    Poco::Util::TimerTask* pTimerTask = Poco::JS::Core::Wrapper::unwrapNative<Poco::Util::TimerTask>(args);
    try
    {
        pTimerTask->cancel();
    }
    catch (Poco::Exception& exc)
    {
        returnException(args, exc);
    }
}
示例#6
0
void SessionWrapper::close(const v8::FunctionCallbackInfo<v8::Value>& args)
{
	SessionHolder* pSessionHolder = Wrapper::unwrapNative<SessionHolder>(args);
	try
	{
		pSessionHolder->session().close();
	}
	catch (Poco::Exception& exc)
	{
		returnException(args, exc);
	}
}
示例#7
0
void SessionWrapper::setPageSize(v8::Local<v8::String> name, v8::Local<v8::Value> value, const v8::PropertyCallbackInfo<void>& info)
{
	SessionHolder* pSessionHolder = Wrapper::unwrapNative<SessionHolder>(info);
	if (value->IsNumber())
	{
		pSessionHolder->setPageSize(value->Uint32Value());
	}
	else
	{
		returnException(info, std::string("invalid pageSize argument"));
	}
}
示例#8
0
void SessionWrapper::execute(const v8::FunctionCallbackInfo<v8::Value>& args)
{
	SessionHolder* pSessionHolder = Wrapper::unwrapNative<SessionHolder>(args);
	Poco::Data::Session& session = pSessionHolder->session();
	if (args.Length() > 0)
	{
		RecordSetHolder* pRecordSetHolder = new RecordSetHolder;
		pRecordSetHolder->reserveBindings(static_cast<std::size_t>(args.Length() - 1));
		try
		{
			Poco::Data::Statement statement = (session << toString(args[0]));
			for (int i = 1; i < args.Length(); i++)
			{
				if (args[i]->IsString())
				{
					statement , use(pRecordSetHolder->bindValue(toString(args[i])));
				}
				else if (args[i]->IsBoolean())
				{
					statement , use(pRecordSetHolder->bindValue(args[i]->BooleanValue()));
				}
				else if (args[i]->IsInt32())
				{
					statement , use(pRecordSetHolder->bindValue(args[i]->Int32Value()));
				}
				else if (args[i]->IsUint32())
				{
					statement , use(pRecordSetHolder->bindValue(args[i]->Uint32Value()));
				}
				else if (args[i]->IsNumber())
				{
					statement , use(pRecordSetHolder->bindValue(args[i]->NumberValue()));
				}
#if POCO_VERSION > 0x01050000
				else if (args[i]->IsDate())
				{
					v8::Local<v8::Date> jsDate = v8::Local<v8::Date>::Cast(args[i]);
					double millis = jsDate->ValueOf();
					Poco::Timestamp ts(static_cast<Poco::Timestamp::TimeVal>(millis*1000));
					Poco::DateTime dateTime(ts);
					statement , use(pRecordSetHolder->bindValue(dateTime));
				}
#endif
				else
				{
					throw Poco::InvalidArgumentException(Poco::format("cannot convert argument %d to native type", i));
				}
			}
			if (pSessionHolder->getPageSize() > 0)
			{
				statement , limit(pSessionHolder->getPageSize());
			}
			statement.execute();
			pRecordSetHolder->assignStatement(statement);
			pRecordSetHolder->updateRecordSet();
			RecordSetWrapper wrapper;
			v8::Persistent<v8::Object>& recordSetObject(wrapper.wrapNativePersistent(args.GetIsolate(), pRecordSetHolder));
			args.GetReturnValue().Set(recordSetObject);
		}
		catch (Poco::Exception& exc)
		{
			delete pRecordSetHolder;
			returnException(args, exc);
		}
	}
}