Ejemplo n.º 1
0
void PainterTest_App::ReceivedMessage(const ZMessage& inMessage)
	{
	bool handledIt = false;
	if (inMessage.Has("what"))
		{
		string theWhat = inMessage.GetString("what");
		if (theWhat == "zoolib:Menu")
			{
			switch (inMessage.GetInt32("menuCommand"))
				{
				case mcNew:
					{
					handledIt = true;
					PainterTest_Window* theWindow = new PainterTest_Window(this, fAsset.GetChild("Windows").GetChild("Painter"), fPaintState, ZRef<NPaintDataRep>(), ZFileSpec(), string());
					theWindow->Center();
					theWindow->BringFront();
					theWindow->GetWindowLock().Release();
					break;
					}
				}
			}
		}
	if (!handledIt)
		ZApp::ReceivedMessage(inMessage);
	}
Ejemplo n.º 2
0
void ZWindow::CloseAndDispose()
	{
	fOSWindow->SetShownState(eZShownStateHidden);
	ZMessage theMessage;
	theMessage.SetString("what", "Dispose");
	this->QueueMessage(theMessage);
	}
Ejemplo n.º 3
0
void ZWindow::InvokeFunctionFromMessageLoop(MessageProc inProc, const ZTupleValue& inTV)
	{
	ZMessage wrapperMessage;
	wrapperMessage.SetString("what", "zoolib:InvokeFunction");
	wrapperMessage.SetPointer("function", reinterpret_cast<void*>(inProc));
	wrapperMessage.SetValue("param", inTV);
	this->QueueMessage(wrapperMessage);
	}
Ejemplo n.º 4
0
bool ZUITextEngine::MenuMessage(const ZMessage& inMessage)
	{
	switch (inMessage.GetInt32("menuCommand"))
		{
		case mcCopy:
		case mcCut:
			{
			size_t selectStart, selectLength;
			this->GetSelection(selectStart, selectLength);
			if (selectLength != 0)
				{
				if (inMessage.GetInt32("menuCommand") == mcCopy || this->IsRangeEditable(selectStart, selectLength))
					{
					ZTuple theTuple = this->GetTuple(selectStart, selectLength);
					ZClipboard::sSet(theTuple);
					if (inMessage.GetInt32("menuCommand") == mcCut)
						this->DeleteText(selectStart, selectLength);
					}
				}
			return true;
			break;
			}
		case mcClear:
			{
			size_t selectStart, selectLength;
			this->GetSelection(selectStart, selectLength);
			if (selectLength != 0 && this->IsRangeEditable(selectStart, selectLength))
				{
				this->DeleteText(selectStart, selectLength);
				return true;
				}
			return true;
			break;
			}
		case mcPaste:
			{
			size_t selectStart, selectLength;
			this->GetSelection(selectStart, selectLength);
			if (this->IsRangeEditable(selectStart, selectLength))
				{
				ZTuple theTuple = ZClipboard::sGet();
				if (theTuple.Has("text/plain"))
					{
					this->ReplaceSelection(theTuple.GetString("text/plain"));
					return true;
					}
				}
			return true;
			break;
			}
		case mcSelectAll:
			{
			this->SetSelection(0, this->GetTextLength());
			return true;
			}
		}
	return false;
	}
Ejemplo n.º 5
0
void MessageButtonPane::SendTheMessage()
	{
	ZMessage msg;

	msg.SetString( "what", "ButtonMessage:display" );
	msg.SetString( "ButtonMessage:parameter", mMessages[ mSelectedButton ] );

	mMessenger.PostMessage(msg);
	}
Ejemplo n.º 6
0
void ZWindow::InvalidateWindowCursor()
	{
	if (!fPostedCursorInvalid)
		{
		fPostedCursorInvalid = true;
		ZMessage theMessage;
		theMessage.SetString("what", "InvalidCursor");
		this->QueueMessage(theMessage);
		}
	}
Ejemplo n.º 7
0
void ZWindow::InvalidateWindowMenuBar()
	{
	ZAssertLocked(kDebug_Window, this->GetLock());
	if (!fPostedInvalidateMenuBar)
		{
		fPostedInvalidateMenuBar = true;
		ZMessage theMessage;
		theMessage.SetString("what", "zoolib:InvalidateMenuBar");
		this->QueueMessage(theMessage);
		}
	}
Ejemplo n.º 8
0
void ZApp::InvalidateAllMenuBars()
	{
	// We don't need to be locked to broadcast this message
	ZTuple theTuple;
	theTuple.SetString("what", "zoolib:InvalidateAllMenuBars");

	ZMessage envelope;
	envelope.SetString("what", "zoolib:Owner");
	envelope.SetTuple("message", theTuple);

	fOSApp->BroadcastMessageToAllWindows(envelope);
	}
Ejemplo n.º 9
0
void PainterTest_App::OpenDocument(const ZMessage& inMessage)
	{
	const vector<ZTupleValue>& theVector = inMessage.GetVector("files");
	for (vector<ZTupleValue>::const_iterator i= theVector.begin(); i != theVector.end(); ++i)
		{
		if (ZFileSpec theFileSpec = ZRefDynamicCast<ZFileLoc>((*i).GetRefCounted()))
			this->OpenFileSpec(theFileSpec);
		}
	}
Ejemplo n.º 10
0
void BMDisplayWindow::ReceivedMessage(const ZMessage& inMessage)
	{
	string theWhat;
	if ( inMessage.GetString( "what", theWhat ) )
		{
		if ( theWhat == "ButtonMessage:display" )
			{
			string param;

			if ( inMessage.GetString( "ButtonMessage:parameter", param ) )
				{
				ZRef<ZUICaption> newCaption = new ZUICaption_Text(param, ZUIAttributeFactory::sGet()->GetFont_SystemLarge(), 0);
				mDisplay->SetCaption(newCaption, true);
				}
			}
		}
	return ZWindow::ReceivedMessage( inMessage );
	}
Ejemplo n.º 11
0
void ZApp::ReceivedMessage(const ZMessage& inMessage)
	{
	if (inMessage.Has("what"))
		{
		string theWhat = inMessage.GetString("what");
		if (theWhat == "zoolib:Menu")
			{
			switch (inMessage.GetInt32("menuCommand"))
				{
				case mcQuit:
					{
					this->QueueRequestQuitMessage();
					break;
					}
				default:
					{
					break;
					}
				}
			}
		}
	}
Ejemplo n.º 12
0
int main() {

    zmq::context_t context(1);
    zmq::socket_t socket(context, ZMQ_PAIR);

    thread t(zmq_thread, &context);

    socket.connect("inproc://thread");

    while (true) {

        ZMessage message;
        message.add("Ping1", 5);
        message.add("Ping2", 5);
        message.add("Ping3", 5);
        message.send(socket);

        zmq::message_t request;
        socket.recv(&request);
        cout << static_cast<char*>(request.data()) << std::endl;
        sleep_for(std::chrono::seconds(3));
    }
}
Ejemplo n.º 13
0
void FIFOReportPane::SubmitReport( ZMessage const &inReport )
{
	mFillLevel->SetFillLevel( inReport.GetInt32( "howFull" ),
								inReport.GetInt32( "capacity" ) );
								
	mFramesWritten->SetText( ZString::sFromInt( inReport.GetInt32( "framesWritten" ) ) );
	mFramesRead->SetText( ZString::sFromInt( inReport.GetInt32( "framesRead" ) ) );
	mSilentFrames->SetText( ZString::sFromInt( inReport.GetInt32( "silentFrames" ) ) );
	mWriteWaits->SetText( ZString::sFromInt( inReport.GetInt32( "writeWaits" ) ) );
	
	return;
}
Ejemplo n.º 14
0
bool ZApp::DispatchMessage(const ZMessage& inMessage)
	{
	if (ZMessageLooper::DispatchMessage(inMessage))
		return true;

	if (inMessage.Has("what"))
		{
		string theWhat = inMessage.GetString("what");
		if (theWhat == "zoolib:Idle")
			{
			this->Idle();
			return true;
			}
		else if (theWhat == "zoolib:CommandLine")
			{
			this->CommandLine(inMessage);
			return true;
			}
		else if (theWhat == "zoolib:RunStarted")
			{
			this->RunStarted();
			return true;
			}
		else if (theWhat == "zoolib:RunFinished")
			{
			this->RunFinished();
			return true;
			}
		else if (theWhat == "zoolib:OpenDocument")
			{
			this->OpenDocument(inMessage);
			return true;
			}
		else if (theWhat == "zoolib:PrintDocument")
			{
			this->PrintDocument(inMessage);
			return true;
			}
		else if (theWhat == "zoolib:WindowRosterChange")
			{
			this->WindowRosterChanged();
			return true;
			}
		else if (theWhat == "zoolib:InvalidateMenuBar")
			{
			if (fPostedInvalidateMenuBar)
				{
				fPostedInvalidateMenuBar = false;
				ZMenuBar theMenuBar;
				this->WindowSupervisorInstallMenus(theMenuBar);
				fOSApp->SetMenuBar(theMenuBar);
				}
			return true;
			}
		else if (theWhat == "zoolib:InvalidateAllMenuBars")
			{
			this->InvalidateMenuBar();
			return true;
			}
		else if (theWhat == "zoolib:RequestQuit")
			{
			if (this->QuitRequested())
				this->ExitRun();
			return true;
			}
		}
	return false;
	}
Ejemplo n.º 15
0
void ZApp::QueueRequestQuitMessage()
	{
	ZMessage theMessage;
	theMessage.SetString("what", "zoolib:RequestQuit");
	this->QueueMessage(theMessage);
	}
Ejemplo n.º 16
0
void ReceiveThread::run()
{
    LOG(INFO) << "Zmq receive thread is runing.";
    void *context = zmq_ctx_new();
    void *subscriber = zmq_socket(context, ZMQ_SUB);
    int rc = zmq_connect(subscriber, ZBROKER_BACKEND_SOCKET);
    assert(rc == 0);

    zmq_setsockopt(subscriber, ZMQ_SUBSCRIBE, TOPIC_BROADCAST, strlen(TOPIC_BROADCAST));
    zmq_setsockopt(subscriber, ZMQ_SUBSCRIBE, _topic.c_str(), _topic.size());
    LOG(INFO) << "Subscribe topic is " << _topic;

    // broadcast started.
    started.send();

    zmq_pollitem_t pollitems[] = { { NULL, 0, ZMQ_POLLIN, 0 } };


    /* poll */
    pollitems[0].socket = subscriber;

    while (1)
    {
        if (zmq_poll(pollitems, 1, -1) == -1)
        {
            LOG(ERROR) << "Failed to poll zmq.";
            break;
        }

        if (pollitems[0].revents & ZMQ_POLLIN)
        {
            int more, flags;
            size_t moresz = sizeof(more);
            ZMessage msg;

            while(1)
            {
                zmq_msg_t zmsg;

                if (zmq_msg_init(&zmsg) != 0)
                {
                    LOG(ERROR) << "Failed to init zmq message.";
                    break;
                }

                if (zmq_recvmsg(subscriber, &zmsg, 0) == -1)
                {

                    LOG(ERROR) << "Failed to receive msg.";
                    zmq_msg_close(&zmsg);
                    break;
                }

                if (zmq_getsockopt(subscriber, ZMQ_RCVMORE, &more, &moresz) == -1)
                {
                    LOG(ERROR) << "Failed to set socket option.";
                    more = 0;
                }

                if (more)
                {
                    flags = ZMQ_SNDMORE;
                }
                else
                {
                    flags = 0;
                }

                if(flags == ZMQ_SNDMORE) // Parse TOPIC FORM & TO
                {
                    char *szBuff;
                    int cnt = zmq_msg_size(&zmsg);

                    szBuff = (char*)malloc(cnt+1);
                    if(szBuff)
                    {
                        const char *split = "#";
                        char *to, *from;

                        memcpy(szBuff, (void *)zmq_msg_data(&zmsg), cnt);
                        szBuff[cnt] = '\0';

                        to = strtok(szBuff,split);
                        from = strtok(NULL,split);
                        if(to && from)
                        {
                            msg.setFrom(std::string(from));
                            msg.setTo(std::string(to));
                        }
                        free(szBuff);
                    }
                }
                else    // parse data
                {
                   if(!msg.getFrom().empty())
                   {
                       int cnt = zmq_msg_size(&zmsg);
                       void *buf = (void *)malloc(cnt+1);
                       if (buf)
                       {
                           char *pData = (char*)buf;
                           memcpy(buf, (void *)zmq_msg_data(&zmsg), cnt);
                           pData[cnt] = '\0';
                           std::string data((char*)buf);
                           msg.setData(data);
                           received.send(msg);
                           free(buf);
                       }
                    }
                }

                zmq_msg_close(&zmsg);

                if (flags == 0)
                {
                    break;
                }
            } // while
        } // if
    } // while
}
Ejemplo n.º 17
0
bool ZWindow::DispatchMessage(const ZMessage& inMessage)
	{
	if (ZMessageLooper::DispatchMessage(inMessage))
		return true;

	if (inMessage.Has("what"))
		{
		string theWhat = inMessage.GetString("what");
		if (theWhat == "Dispose")
			{
			delete this;
			return true;
			}
		else if (theWhat == "zoolib:ScreenLayoutChanged")
			{
			this->ForceOnScreen(true, true);
			return true;
			}
		else if (theWhat == "InvalidCursor")
			{
			fPostedCursorInvalid = false;
			ZCursor theCursor;
			bool gotIt = false;
			if (ZCaptureInput* theCaptureInput = fCaptureInput)
				{
				theCaptureInput->IncrementUseCount();
				if (ZSubPane* thePane = theCaptureInput->GetPane())
					gotIt = theCaptureInput->GetCursor(thePane->FromWindow(fLastMouseLocation), theCursor);
				theCaptureInput->DecrementUseCount();
				}
			else
				{
				ZPoint paneHitPoint = fLastMouseLocation - this->GetWindowOrigin();
				for (vector<ZWindowPane*>::iterator i = fVector_WindowPanes.begin(); i != fVector_WindowPanes.end(); ++i)
					{
					if ((*i)->GetVisible() && (*i)->CalcFrameRgn().Contains(paneHitPoint))
						{
						if (ZSubPane* hitPane = (*i)->FindPane(paneHitPoint - (*i)->GetLocation()))
							gotIt = hitPane->GetCursor(hitPane->FromWindow(paneHitPoint), theCursor);
						}
					}
				}
			// If neither the mouse tracker nor the enclosing pane set the cursor, ensure it's reset
			// to an arrow. If false is returned by the GetCursor methods they're supposed not to have
			// touched theCursor, but let's make sure and set it to be an arrow.
			if (!gotIt)
				theCursor.Set(ZCursor::eCursorTypeArrow);
			fOSWindow->SetCursor(theCursor);
			return true;
			}
		else if (theWhat == "zoolib:InvalidateMenuBar")
			{
			if (fPostedInvalidateMenuBar)
				{
				fPostedInvalidateMenuBar = false;
				ZMenuBar theMenuBar;
				this->GetWindowTarget()->DispatchInstallMenus(theMenuBar);
				fOSWindow->SetMenuBar(theMenuBar);
				}
			return true;
			}
		else if (theWhat == "zoolib:InvalidateAllMenuBars")
			{
			this->InvalidateWindowMenuBar();
			return true;
			}
		else if (theWhat == "zoolib:Close")
			{
			this->WindowCloseByUser();
			return true;
			}
		else if (theWhat == "zoolib:Zoom")
			{
			this->WindowZoomByUser();
			return true;
			}
		else if (theWhat == "zoolib:MouseDown")
			{
			this->WindowMessage_Mouse(inMessage);
			return true;
			}
		else if (theWhat == "zoolib:MouseUp")
			{
			this->WindowMessage_Mouse(inMessage);
			return true;
			}
		else if (theWhat == "zoolib:MouseEnter" || theWhat == "zoolib:MouseChange" || theWhat == "zoolib:MouseExit")
			{
			this->WindowMessage_Mouse(inMessage);
			return true;
			}
		else if (theWhat == "zoolib:CaptureCancelled")
			{
			this->WindowCaptureCancelled();
			return true;
			}
		else if (theWhat == "zoolib:FrameChange")
			{
			this->WindowFrameChange();
			return true;
			}
		else if (theWhat == "zoolib:ShownState")
			{
			this->WindowShownState((ZShownState)inMessage.GetInt32("shownState"));
			return true;
			}
		else if (theWhat == "zoolib:Activate")
			{
			if (fBackInkActive && fBackInkInactive && (fBackInkActive != fBackInkInactive))
				{
				if (!fBackInkActive->GetInk().IsSameAs(fBackInkInactive->GetInk()))
					this->InvalidateWindowRegion(ZDCRgn(this->GetSize()));
				}
			this->WindowActivate(inMessage.GetBool("active"));
			return true;
			}
		else if (theWhat == "zoolib:AppActivate")
			{
			this->WindowAppActivate(inMessage.GetBool("active"));
			return true;
			}
		else if (theWhat == "zoolib:Menu")
			{
			if (!this->WindowMenuMessage(inMessage) && fWindowSupervisor)
				fWindowSupervisor->WindowSupervisorPostMessage(inMessage);
			return true;
			}
		else if (theWhat == "zoolib:KeyDown")
			{
			this->WindowMessage_Key(inMessage);
			return true;
			}
		else if (theWhat == "zoolib:Idle")
			{
			this->WindowIdle();
			return true;
			}
		else if (theWhat == "zoolib:InvokeFunction")
			{
			if (MessageProc theProc = reinterpret_cast<MessageProc>(inMessage.GetPointer("function")))
				theProc(this, inMessage.GetValue("param"));
			return true;
			}
		}

	return false;
	}