Exemple #1
0
void ZVisitor_Expr_Bool_ToStrim::Visit_Expr_Bool_Not(const ZRef<ZExpr_Bool_Not>& iRep)
	{
	this->pStrimW() << "~(";
	this->pToStrim(iRep->GetOp0());
	this->pStrimW() << ")";
	}
Exemple #2
0
ZStreamerR_Boundary::ZStreamerR_Boundary(const string& iBoundary, ZRef<ZStreamerR> iStreamerSource)
:	fStreamerSource(iStreamerSource),
	fStream(iBoundary, iStreamerSource->GetStreamR())
	{}
Exemple #3
0
static ZTuple sTupleFromNode(const ZRef<ZTBQueryNode>& iNode)
	{
	if (iNode)
		return iNode->AsTuple();
	return ZTuple();
	}
Exemple #4
0
void ZVisitor_Expr_Bool_ValPred_Any_ToStrim::Visit_Expr_Bool_ValPred(
	const ZRef<ZExpr_Bool_ValPred>& iRep)
	{ ZUtil_Strim_ValPred_Any::sToStrim(iRep->GetValPred(), pStrimW()); }
Exemple #5
0
ZDCInk ZUIInk_UIColor::GetInk()
	{
	if (fUIColor)
		return ZDCInk(fUIColor->GetColor());
	return ZDCInk();
	}
void ZBlackBerryServer::HandleRequest(ZRef<ZStreamerRWCon> iSRWCon)
	{
	const ZStreamR& r = iSRWCon->GetStreamR();
	const ZStreamW& w = iSRWCon->GetStreamW();

	const int req = r.ReadUInt8();
	if (req == 0)
		{
		// Async changed notifications
		ZGuardRMtxR locker(fMutex);
		ZRef<Handler_ManagerChanged> theHandler = new Handler_ManagerChanged(iSRWCon, iSRWCon, this);
		fHandlers_ManagerChanged.push_back(theHandler);
		locker.Release();

		sStartCommerRunners(theHandler);
		}
	else if (req == 1)
		{
		// Synchronous get device IDs
		ZGuardRMtxR locker(fMutex);

		vector<uint64> theIDs;
		for (vector<Entry_t>::iterator i = fEntries.begin(); i != fEntries.end(); ++i)
			{
			if (i->fLive)
				theIDs.push_back(i->fID);
			}
		locker.Release();

		w.WriteCount(theIDs.size());
		for (vector<uint64>::iterator i = theIDs.begin(); i != theIDs.end(); ++i)
			w.WriteUInt64(*i);
		}
	else if (req == 2)
		{
		// Async device finished notifications
		const uint64 deviceID = r.ReadUInt64();

		ZGuardRMtxR locker(fMutex);

		bool gotIt = false;
		for (vector<Entry_t>::iterator i = fEntries.begin(); !gotIt && i != fEntries.end(); ++i)
			{
			if (i->fLive && i->fID == deviceID)
				{
				ZRef<Handler_DeviceFinished> theHandler =
					new Handler_DeviceFinished(iSRWCon, iSRWCon, this);
				i->fHandlers.push_back(theHandler);
				locker.Release();

				w.WriteBool(true);
				sStartCommerRunners(theHandler);
				gotIt = true;
				}
			}

		if (!gotIt)
			{
			locker.Release();
			w.WriteBool(false);
			}
		}
	else if (req == 4)
		{
		// Synchronous get attribute
		const uint64 deviceID = r.ReadUInt64();
		const uint16 object = r.ReadUInt16();
		const uint16 attribute = r.ReadUInt16();
		if (ZRef<ZBlackBerry::Device> theDevice = this->pGetDevice(deviceID))
			{
			if (ZQ<ZBlackBerry::Data> theQ = theDevice->GetAttribute(object, attribute))
				{
				ZBlackBerry::Data theMB = theQ.Get();
				w.WriteBool(true);
				w.WriteCount(theMB.GetSize());
				w.Write(theMB.GetPtr(), theMB.GetSize());
				return;
				}
			}
		w.WriteBool(false);
		}
	else if (req == 5)
		{
		// Synchronous get PIN
		const uint64 deviceID = r.ReadUInt64();
		if (ZRef<ZBlackBerry::Device> theDevice = this->pGetDevice(deviceID))
			{
			uint32 thePIN = theDevice->GetPIN();
			w.WriteBool(true);
			w.WriteUInt32(thePIN);
			}
		else
			{
			w.WriteBool(false);
			}
		}
	else if (req == 6)
		{
		// Open channel
		const uint64 deviceID = r.ReadUInt64();

		const bool preserveBoundaries = r.ReadBool();

		const bool gotHash = r.ReadBool();
		ZBlackBerry::PasswordHash thePasswordHash;
		if (gotHash)
			r.Read(&thePasswordHash, sizeof(thePasswordHash));

		const string channelName = spReadString(r);

		ZBlackBerry::Device::Error theError = ZBlackBerry::Device::error_DeviceClosed;

		if (ZRef<ZBlackBerry::Device> theDevice = this->pGetDevice(deviceID))
			{
			if (ZRef<ZBlackBerry::Channel> deviceCon = theDevice->Open(preserveBoundaries,
				channelName, gotHash ? &thePasswordHash : nullptr, &theError))
				{
				const size_t readSize = deviceCon->GetIdealSize_Read();
				const size_t writeSize = deviceCon->GetIdealSize_Write();
				w.WriteUInt32(ZBlackBerry::Device::error_None);
				w.WriteUInt32(readSize);
				w.WriteUInt32(writeSize);
				w.Flush();

				// Use a standard copier for the device-->client direction
				sCallOnNewThread(
					sBindR(sCallable(&spCopyAllCon), deviceCon, iSRWCon, readSize));

				// And our specialized copier for the client-->device direction.
				sCallOnNewThread(
					sBindR(sCallable(&spCopyChunked), iSRWCon, deviceCon));
				return;
				}
			}

		if (theError == ZBlackBerry::Device::error_None)
			{
			if (ZLOG(s, eDebug + 1, "ZBlackBerryServer::HandleRequest"))
				{
				s << "Open failed, but got error_None";
				}
			theError = ZBlackBerry::Device::error_Generic;
			}
		w.WriteUInt32(theError);
		}
	}
ZRef<ZNodeRep> ZNodeIterRep_Wrapper::Current()
	{
	if (ZRef<ZNodeRep> theRep = fIterRep->Current())
		return new ZNodeRep_Wrapper(fParent, fName, fDepth, theRep);
	return ZRef<ZNodeRep>();
	}
Exemple #8
0
ZStreamerR_ZLibDecode::ZStreamerR_ZLibDecode(ZRef<ZStreamerR> iStreamer)
:	fStreamer(iStreamer),
	fStream(iStreamer->GetStreamR())
	{}
bool ZNodeIterRep_Wrapper::HasValue()
	{ return fIterRep->HasValue(); }
void ZNodeIterRep_Wrapper::Advance()
	{ fIterRep->Advance(); }
Exemple #11
0
ZStreamerRWPos_PageBuffered::ZStreamerRWPos_PageBuffered(
	size_t iBufferCount, size_t iBufferSize, ZRef<ZStreamerRWPos> iStreamerReal)
:	fStreamerReal(iStreamerReal),
	fStream(iBufferCount, iBufferSize, iStreamerReal->GetStreamRWPos())
	{}
Exemple #12
0
ZStreamerRPos_PageBuffered::ZStreamerRPos_PageBuffered(
	size_t iBufferCount, size_t iBufferSize, ZRef<ZStreamerRPos> iStreamerSource)
:	fStreamerSource(iStreamerSource),
	fStream(iBufferCount, iBufferSize, iStreamerSource->GetStreamRPos())
	{}
Exemple #13
0
ZStreamerRPos_StreamR::ZStreamerRPos_StreamR(
	ZRef<ZStreamerR> iStreamerR, ZRef<ZStreamerRWPos> iStreamerRWPos)
:	fStreamerR(iStreamerR),
	fStreamerRWPos(iStreamerRWPos),
	fStreamRPos_StreamR(iStreamerR->GetStreamR(), iStreamerRWPos->GetStreamRWPos())
	{}
Exemple #14
0
ZStreamerR_Boundary::ZStreamerR_Boundary(const void* iBoundary, size_t iBoundarySize,
	ZRef<ZStreamerR> iStreamerSource)
:	fStreamerSource(iStreamerSource),
	fStream(iBoundary, iBoundarySize, iStreamerSource->GetStreamR())
	{}
std::string ZNodeIterRep_Wrapper::CurrentName()
	{ return fIterRep->CurrentName(); }
Exemple #16
0
static bool spGetAssetTreeInfoFromExecutable(const string& iName, int& oFD, size_t& oStart, size_t& oLength)
	{
	ZRef<ZFileLoc_POSIX> theFileLoc = ZFileLoc_POSIX::sGet_App();
	if (!theFileLoc)
		return false;

	string thePath = theFileLoc->pGetPath();

	oFD = ::open(thePath.c_str(), O_RDONLY);

	if (oFD < 0)
		return false;

	try
		{
		// We don't want theStream to adopt the file descriptor \a oFD.
		ZStreamRPos_File_POSIX theStream(oFD, false);

		size_t theSize = theStream.GetSize();
		const size_t trailerSize = spMagicTextSize + sizeof(int32) + sizeof(int32);

		// Check for there being at least enough room for an empty trailer.
		if (theSize >= trailerSize)
			{
			// There's enough space for our trailer, consisting of the magic text
			// and the two 32 bit offsets to asset data and the table of contents.
			theStream.SetPosition(theSize - trailerSize);
			size_t offsetOfData = theStream.ReadInt32();
			size_t offsetOfTOC = theStream.ReadInt32();
			if (theSize >= trailerSize + offsetOfData)
				{
				// The data offset is within the file.
				char checkedText[spMagicTextSize];
				theStream.Read(checkedText, spMagicTextSize);
				if (0 == memcmp(checkedText, spMagicText, spMagicTextSize))
					{
					// The magic text matches.
					if (theSize >= trailerSize + offsetOfTOC)
						{
						// The table of contents is also within the file.
						theStream.SetPosition(theSize - trailerSize - offsetOfTOC);
						size_t countOfChunks = theStream.ReadInt32();
						for (size_t x = 0; x < countOfChunks; ++x)
							{
							oStart = theStream.ReadInt32() + theSize - trailerSize - offsetOfData;
							oLength = theStream.ReadInt32();
							string currentName;
							if (size_t nameLength = theStream.ReadInt32())
								{
								currentName.resize(nameLength);
								theStream.Read(&currentName[0], nameLength);
								}
							if (iName == currentName)
								return true;
							}
						}
					}
				}
			}
		}
	catch (...)
		{}
	::close(oFD);
	return false;
	}
ZRef<ZNodeIterRep> ZNodeIterRep_Wrapper::Clone()
	{ return new ZNodeIterRep_Wrapper(fParent, fName, fDepth, fIterRep->Clone()); }
Exemple #18
0
ZStreamerR_ZLibDecode::ZStreamerR_ZLibDecode(
	ZStream_ZLib::EFormatR iFormatR, size_t iBufferSize,
	ZRef<ZStreamerR> iStreamer)
:	fStreamer(iStreamer),
	fStream(iFormatR, iBufferSize, iStreamer->GetStreamR())
	{}
Exemple #19
0
static ZDCRgn sCalcFloodFillRgn(const ZRef<ZDCCanvas>& inCanvas,
	ZDCState& ioState, ZPoint inSeedLocation)
	{
	ZDCRgn theMaskRgn;

	ZRGBColor theSeedColor = inCanvas->GetPixel(ioState, inSeedLocation.h, inSeedLocation.v);
	ZRect theBounds = ioState.fClip.Bounds() + (ioState.fClipOrigin - ioState.fOrigin);

	vector<ZPoint> theStack;
	theStack.push_back(inSeedLocation);

	while (theStack.size())
		{
		ZPoint theLocation = theStack.back();
		theStack.pop_back();
		if (::sCheckPixel(inCanvas, ioState, theLocation.h, theLocation.v, theSeedColor, theMaskRgn))
			{
			// Find left and right boundaries
			ZCoord left = theLocation.h;
			while ((left > theBounds.left)
				&& ::sCheckPixel(inCanvas, ioState,
				left - 1, theLocation.v, theSeedColor, theMaskRgn))
				{
				--left;
				}

			ZCoord right = theLocation.h;
			while ((right < theBounds.right)
				&& ::sCheckPixel(inCanvas, ioState,
				right, theLocation.v, theSeedColor, theMaskRgn))
				{
				++right;
				}

			theMaskRgn |= ZRect(left, theLocation.v, right, theLocation.v + 1);

			// Do the line above
			ZCoord currentY = theLocation.v - 1;
			ZCoord currentX;
			if (currentY >= theBounds.top)
				{
				currentX = left;
				while (currentX < right)
					{
					while ((currentX < right)
						&& !sCheckPixel(inCanvas, ioState,
						currentX, currentY, theSeedColor, theMaskRgn))
						{
						++currentX;
						}

					if (currentX < right)
						{
						while ((currentX < right)
							&& sCheckPixel(inCanvas, ioState,
							currentX, currentY, theSeedColor, theMaskRgn))
							{
							++currentX;
							}

						theStack.push_back(ZPoint(currentX - 1, currentY));
						}
					}
				}

			// Do the line below
			currentY = theLocation.v + 1;
			if (currentY < theBounds.bottom)
				{
				currentX = left;
				while (currentX < right)
					{
					while ((currentX < right)
						&& !sCheckPixel(inCanvas, ioState,
						currentX, currentY, theSeedColor, theMaskRgn))
						{
						++currentX;
						}

					if (currentX < right)
						{
						while ((currentX < right)
							&& sCheckPixel(inCanvas, ioState,
							currentX, currentY, theSeedColor, theMaskRgn))
							{
							++currentX;
							}

						theStack.push_back(ZPoint(currentX - 1, currentY));
						}
					}
				}
			}
		}
	return theMaskRgn;
	}