Example #1
0
	void NetworkBinding::SetProxy(const ValueList& args, SharedValue result)
	{
		std::string hostname = args.at(0)->ToString();
		std::string port = args.at(1)->ToString();
		std::string username = args.at(2)->ToString();
		std::string password = args.at(3)->ToString();
		if(proxy)
		{
			delete proxy;
			proxy = NULL;
		}

#if defined(OS_WIN32)
		std::string http_proxy = "http://";
		http_proxy += username + ":" + password + "@";
		http_proxy += hostname + ":" + port;
		int i = ::_putenv_s("HTTP_PROXY", http_proxy.c_str());
		if(i != 0)
		{
			result->SetBool(false);
		}
#endif

		proxy = new ti::Proxy(hostname, port, username,password);
		result->SetBool(true);
  	}
Example #2
0
	void ResultSetBinding::IsValidRow(const ValueList& args, SharedValue result)
	{
		if (rs.isNull())
		{
			result->SetBool(false);
		}
		else
		{
			result->SetBool(!eof);
		}
	}
Example #3
0
	void FileStream::Ready(const ValueList& args, SharedValue result)
	{
		Poco::FileInputStream* fis = dynamic_cast<Poco::FileInputStream*>(this->stream);
		if(!fis)
		{
			result->SetBool(false);
		}
		else
		{
			result->SetBool(fis->eof()==false);
		}
	}
Example #4
0
	void FileStream::Write(const ValueList& args, SharedValue result)
	{
		char *text = NULL;
		int size = 0;
		if (args.at(0)->IsObject())
		{
			SharedKObject b = args.at(0)->ToObject();
			SharedPtr<Blob> blob = b.cast<Blob>();
			if (!blob.isNull())
			{
				text = (char*)blob->Get();
				size = (int)blob->Length();
			}
		}
		else if (args.at(0)->IsString())
		{
			text = (char*)args.at(0)->ToString();
		}
		else if (args.at(0)->IsInt())
		{
			std::stringstream ostr;
			ostr << args.at(0)->ToInt();
			text = (char*)ostr.str().c_str();
			size = ostr.str().length();
		}
		else if (args.at(0)->IsDouble())
		{
			std::stringstream ostr;
			ostr << args.at(0)->ToDouble();
			text = (char*)ostr.str().c_str();
			size = ostr.str().length();
		}

		if (size==0)
		{
			size = strlen(text);
		}

		if (text == NULL)
		{
			result->SetBool(false);
			return;
		}
		if (size <= 0)
		{
			result->SetBool(false);
			return;
		}
		Write(text,size);
		result->SetBool(true);
	}
	void TCPSocketBinding::Close(const ValueList& args, SharedValue result)
	{
		if (this->opened)
		{
			this->opened = false;
			this->reactor.stop();
			this->socket.close();
			result->SetBool(true);
		}
		else
		{
			result->SetBool(false);
		}
	}
	void TCPSocketBinding::Connect(const ValueList& args, SharedValue result)
	{
		std::string eprefix = "Connect exception: ";
		if (this->opened)
		{
			throw ValueException::FromString(eprefix + "Socket is already open");
		}
		try
		{
			SocketAddress a(this->host.c_str(),this->port);
			this->socket.connectNB(a);
			this->thread.start(this->reactor);
			this->opened = true;
			result->SetBool(true);
		}
		catch(Poco::IOException &e)
		{
			throw ValueException::FromString(eprefix + e.displayText());
		}
		catch(std::exception &e)
		{
			throw ValueException::FromString(eprefix + e.what());
		}
		catch(...)
		{
			throw ValueException::FromString(eprefix + "Unknown exception");
		}
	}
Example #7
0
	void DesktopBinding::OpenURL(const ValueList& args, SharedValue result)
	{
		if (args.size()!=1)
		{
			throw ValueException::FromString("openURL takes 1 parameter");
		}
		std::string url = args.at(0)->ToString();
		result->SetBool(TI_DESKTOP::OpenURL(url));
	}
Example #8
0
	void ComponentBinding::_IsLoaded(const ValueList& args, SharedValue result)
	{
		SharedApplication app = Host::GetInstance()->GetApplication();
		result->SetBool(false);

		if (this->component.get() == app->runtime.get())
		{
			result->SetBool(true);
		}

		std::vector<SharedComponent>::iterator i = app->modules.begin();
		while (i != app->modules.end())
		{
			SharedComponent c = *i++;
			if (c.get() == this->component.get())
			{
				result->SetBool(true);
			}
		}
	}
Example #9
0
	void NetworkBinding::RemoveConnectivityListener(
		const ValueList& args,
		SharedValue result)
	{
		args.VerifyException("removeConnectivityListener", "n");
		int id = args.at(0)->ToInt();

		std::vector<Listener>::iterator it = this->listeners.begin();
		while (it != this->listeners.end())
		{
			if ((*it).id == id)
			{
				this->listeners.erase(it);
				result->SetBool(true);
				return;
			}
			it++;
		}
		result->SetBool(false);
	}
Example #10
0
	void FileStream::Open(const ValueList& args, SharedValue result)
	{
		FileStreamMode mode = MODE_READ;
		bool binary = false;
		bool append = false;
		if (args.size()>=1) mode = (FileStreamMode)args.at(0)->ToInt();
		if (args.size()>=2) binary = args.at(1)->ToBool();
		if (args.size()>=3) append = args.at(2)->ToBool();
		bool opened = this->Open(mode,binary,append);
		result->SetBool(opened);
	}
Example #11
0
void UserWindow::_RemoveEventListener(const ValueList& args, SharedValue result)
{
	if (args.size() != 1 || !args.at(0)->IsNumber())
	{
		throw ValueException::FromString("invalid argument");
	}
	int id = args.at(0)->ToInt();

	std::vector<Listener>::iterator it = this->listeners.begin();
	while (it != this->listeners.end())
	{
		if ((*it).id == id)
		{
			this->listeners.erase(it);
			result->SetBool(true);
			return;
		}
		it++;
	}
	result->SetBool(false);
}
Example #12
0
	void ResultSetBinding::TransformValue(size_t index, SharedValue result)
	{
		MetaColumn::ColumnDataType type = rs->columnType(index);
		Poco::DynamicAny value = rs->value(index);
		
		if (value.isEmpty())
		{
			result->SetNull();
		}
		else if (type == MetaColumn::FDT_STRING)
		{
			std::string str;
			value.convert(str);
			result->SetString(str);
		}
		else if (type == MetaColumn::FDT_BOOL)
		{
			bool v = false;
			value.convert(v);
			result->SetBool(v);
		}
		else if (type == MetaColumn::FDT_FLOAT || type == MetaColumn::FDT_DOUBLE)
		{
			float f = 0;
			value.convert(f);
			result->SetDouble(f);
		}
		else if (type == MetaColumn::FDT_BLOB || type == MetaColumn::FDT_UNKNOWN)
		{
			std::string str;
			value.convert(str);
			result->SetString(str);
		}
		else
		{
			// the rest of these are ints:
			// FDT_INT8,
			// FDT_UINT8,
			// FDT_INT16,
			// FDT_UINT16,
			// FDT_INT32,
			// FDT_UINT32,
			// FDT_INT64,
			// FDT_UINT64,
			int i;
			value.convert(i);
			result->SetInt(i);
		}
	}
	void TCPSocketBinding::Write(const ValueList& args, SharedValue result)
	{
		std::string eprefix = "TCPSocketBinding::Write: ";
		if (!this->opened)
		{
			throw ValueException::FromString(eprefix +  "Socket is not open");
		}

		try
		{
			Poco::Mutex::ScopedLock lock(bufferMutex);
			buffer += args.at(0)->ToString();
			result->SetBool(true);
		}
		catch(Poco::Exception &e)
		{
			throw ValueException::FromString(eprefix + e.displayText());
		}

	}
	void MenuItem::_IsSeparator(const ValueList& args, SharedValue result)
	{
		result->SetBool(this->type == SEPARATOR);
	}
Example #15
0
	void FileStream::IsOpen(const ValueList& args, SharedValue result)
	{
		Poco::FileInputStream* fis = dynamic_cast<Poco::FileInputStream*>(this->stream);
		result->SetBool(fis!=NULL);
	}
	void MenuItem::_IsCheck(const ValueList& args, SharedValue result)
	{
		result->SetBool(this->type == CHECK);
	}
Example #17
0
	void FileStream::WriteLine(const ValueList& args, SharedValue result)
	{
		if(! this->stream)
		{
			throw ValueException::FromString("FileStream must be opened before calling readLine");
		}
		char *text = NULL;
		int size = 0;
		if (args.at(0)->IsObject())
		{
			SharedKObject b = args.at(0)->ToObject();
			SharedPtr<Blob> blob = b.cast<Blob>();
			if (!blob.isNull())
			{
				text = (char*)blob->Get();
				size = (int)blob->Length();
			}
		}
		else if (args.at(0)->IsString())
		{
			text = (char*)args.at(0)->ToString();
		}
		else if (args.at(0)->IsInt())
		{
			std::stringstream ostr;
			ostr << args.at(0)->ToInt();
			text = (char*)ostr.str().c_str();
			size = ostr.str().length();
		}
		else if (args.at(0)->IsDouble())
		{
			std::stringstream ostr;
			ostr << args.at(0)->ToDouble();
			text = (char*)ostr.str().c_str();
			size = ostr.str().length();
		}

		if (size==0)
		{
			size = strlen(text);
		}

		if (text == NULL)
		{
			result->SetBool(false);
			return;
		}
		if (size <= 0)
		{
			result->SetBool(false);
			return;
		}
		std::string astr = text;
#ifdef OS_WIN32
		astr += "\r\n";
#else
		astr += "\n";
#endif
		Write((char*)astr.c_str(),astr.length());
		result->SetBool(true);
	}
Example #18
0
	void MenuItem::_IsSubMenu(const ValueList& args, SharedValue result)
	{
		result->SetBool(this->IsSubMenu());
	}
Example #19
0
	void FileStream::Close(const ValueList& args, SharedValue result)
	{
		bool closed = this->Close();
		result->SetBool(closed);
	}
Example #20
0
	void IPAddressBinding::IsNodeLocalMC(const ValueList& args, SharedValue result)
	{
		result->SetBool(!this->invalid && this->address->isNodeLocalMC());
	}
	void MenuItem::_IsEnabled(const ValueList& args, SharedValue result)
	{
		result->SetBool(this->enabled);
	}
Example #22
0
	void IPAddressBinding::IsIPV6(const ValueList& args, SharedValue result)
	{
		result->SetBool(!this->invalid && this->address->family() == IPAddress::IPv6);
	}
Example #23
0
	void IPAddressBinding::IsUnicast(const ValueList& args, SharedValue result)
	{
		result->SetBool(!this->invalid && this->address->isUnicast());
	}
	void MenuItem::_GetState(const ValueList& args, SharedValue result)
	{
		result->SetBool(this->state);
	}
Example #25
0
	void ComponentBinding::_IsBundled(const ValueList& args, SharedValue result)
	{
		result->SetBool(this->component->bundled);
	}
	void MenuItem::_IsAutoCheck(const ValueList& args, SharedValue result)
	{
		result->SetBool(this->autoCheck);
	}
Example #27
0
	void Sound::IsPaused(const ValueList& args, SharedValue result)
	{
		result->SetBool(this->IsPaused());
	}
	void HttpServerRequest::HasHeader(const ValueList& args, SharedValue result)
	{
		std::string name = args.at(0)->ToString();
		result->SetBool(request.has(name));
	}
Example #29
0
	void HostBinding::IsInvalid(const ValueList& args, SharedValue result)
	{
		result->SetBool(this->invalid);
	}
	void TCPSocketBinding::IsClosed(const ValueList& args, SharedValue result)
	{
		return result->SetBool(!this->opened);
	}