Just the beginnings of a Photon Event Loop, still work in progress

This commit is contained in:
Jerry.Kirk%Nexwarecorp.com 1999-09-03 12:55:19 +00:00
parent 01abb3a4a1
commit 742eb0a560
9 changed files with 515 additions and 0 deletions

View File

@ -0,0 +1,100 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications, Inc. Portions created by Netscape are
* Copyright (C) 1999, Mozilla. All Rights Reserved.
*
* Contributor(s):
* Travis Bogard <travis@netscape.com>
* Jerry Kirk <Jerry.Kirk@NexwareCorp.com>
*/
#include "nsCRT.h"
#include "nsCEvent.h"
//*****************************************************************************
//*** nsCEvent: Object Management
//*****************************************************************************
nsCEvent::nsCEvent(void* platformEventData)
{
NS_INIT_REFCNT();
if (platformEventData)
{
mEventBufferSz = PhGetMsgSize ( (PhEvent_t *) platformEventData );
m_msg = (PhEvent_t *) malloc( mEventBufferSz );
NS_ENSURE_ARG_POINTER(m_msg);
nsCRT::memcpy(m_msg, platformEventData, mEventBufferSz);
}
else
{
mEventBufferSz = sizeof(PhEvent_t);
m_msg = (PhEvent_t *) malloc( mEventBufferSz );
NS_ENSURE_ARG_POINTER(m_msg);
nsCRT::memset(m_msg, 0, mEventBufferSz);
}
}
nsCEvent::~nsCEvent()
{
}
//*****************************************************************************
// nsCEvent::nsISupports
//*****************************************************************************
NS_IMPL_ISUPPORTS1(nsCEvent, nsIEvent)
//*****************************************************************************
// nsCEvent::nsIEvent
//*****************************************************************************
NS_IMETHODIMP nsCEvent::GetNativeData(nsNativeEventDataType dataType,
void** data)
{
NS_ENSURE_ARG(nsNativeEventDataTypes::PhotonMsgStruct == dataType);
NS_ENSURE_ARG_POINTER(data);
*data = m_msg;
return NS_OK;
}
NS_IMETHODIMP nsCEvent::SetNativeData(nsNativeEventDataType dataType,
void* data)
{
NS_ENSURE_ARG(nsNativeEventDataTypes::PhotonMsgStruct == dataType);
if(!data)
{
/* Get rid of the Event */
nsCRT::memset(m_msg, 0, mEventBufferSz);
}
else
{
unsigned long locEventBufferSz = PhGetMsgSize ( (PhEvent_t *) data );
if (locEventBufferSz > mEventBufferSz)
{
mEventBufferSz = locEventBufferSz;
m_msg = (PhEvent_t *) realloc( mEventBufferSz );
NS_ENSURE_ARG_POINTER(m_msg);
}
nsCRT::memcpy(m_msg, data, mEventBufferSz);
}
return NS_OK;
}

View File

@ -0,0 +1,47 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications, Inc. Portions created by Netscape are
* Copyright (C) 1999, Mozilla. All Rights Reserved.
*
* Contributor(s):
* Travis Bogard <travis@netscape.com>
* Jerry Kirk <Jerry.Kirk@NexwareCorp.com>
*/
#ifndef nsCEvent_h__
#define nsCEvent_h__
#include "PhT.h"
#include "nsIEvent.h"
class nsCEvent : public nsIEvent
{
public:
nsCEvent(void* platformEventData=nsnull);
NS_DECL_ISUPPORTS
NS_DECL_NSIEVENT
protected:
virtual ~nsCEvent();
protected:
PhEvent_t *m_msg;
unsigned long mEventBufferSz;
};
#endif /* nsCEvent_h__ */

View File

@ -0,0 +1,78 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications, Inc. Portions created by Netscape are
* Copyright (C) 1999, Mozilla. All Rights Reserved.
*
* Contributor(s):
* Travis Bogard <travis@netscape.com>
* Jerry Kirk <Jerry.Kirk@NexwareCorp.com>
*/
#include "nsCRT.h"
#include "nsCEventFilter.h"
//*****************************************************************************
//*** nsCEventFilter: Object Management
//*****************************************************************************
nsCEventFilter::nsCEventFilter(void* platformFilterData)
{
NS_INIT_REFCNT();
if(platformFilterData)
nsCRT::memcpy(&m_filter, platformFilterData, sizeof(m_filter));
else
nsCRT::memset(&m_filter, 0, sizeof(m_filter));
}
nsCEventFilter::~nsCEventFilter()
{
}
//*****************************************************************************
// nsCEventFilter::nsISupports
//*****************************************************************************
NS_IMPL_ISUPPORTS1(nsCEventFilter, nsIEventFilter)
//*****************************************************************************
// nsCEventFilter::nsIEventFilter
//*****************************************************************************
NS_IMETHODIMP nsCEventFilter::GetNativeData(nsNativeFilterDataType dataType,
void** data)
{
NS_ENSURE_ARG(nsNativeFilterDataTypes::PhotonFilter == dataType);
NS_ENSURE_ARG_POINTER(data);
*data = &m_filter;
return NS_OK;
}
NS_IMETHODIMP nsCEventFilter::SetNativeData(nsNativeFilterDataType dataType,
void* data)
{
NS_ENSURE_ARG(nsNativeFilterDataTypes::PhotonFilter == dataType);
if(!data)
nsCRT::memset(&m_filter, 0, sizeof(m_filter));
else
nsCRT::memcpy(&m_filter, data, sizeof(m_filter));
return NS_OK;
}

View File

@ -0,0 +1,47 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications, Inc. Portions created by Netscape are
* Copyright (C) 1999, Mozilla. All Rights Reserved.
*
* Contributor(s):
* Travis Bogard <travis@netscape.com>
* Jerry Kirk <Jerry.Kirk@NexwareCorp.com>
*/
#ifndef nsCEventFilter_h__
#define nsCEventFilter_h__
#include "PhT.h"
#include "nsIEventFilter.h"
#include "nsCPhFilter.h"
class nsCEventFilter : public nsIEventFilter
{
public:
nsCEventFilter(void* platformFilterData=nsnull);
NS_DECL_ISUPPORTS
NS_DECL_NSIEVENTFILTER
protected:
virtual ~nsCEventFilter();
protected:
nsCPhFilter m_filter;
};
#endif /* nsCEventFilter_h__ */

View File

@ -0,0 +1,38 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications, Inc. Portions created by Netscape are
* Copyright (C) 1999, Mozilla. All Rights Reserved.
*
* Contributor(s):
* Travis Bogard <travis@netscape.com>
* Jerry Kirk <Jerry.Kirk@NexwareCorp.com>
*/
#ifndef nsCPhFilter_h__
#define nsCPhFilter_h__
#include "Pht.h"
class nsCPhFilter
{
public:
// HWND hWnd;
// UINT wMsgFilterMin;
// UINT wMsgFilterMax;
// UINT wRemoveFlags; // fRemoveEvent flag passed to PeekEvent takes precedent
}; // over PM_NOREMOVE and PM_REMOVE.
#endif /* nsPhFilter_h__ */

View File

@ -0,0 +1,122 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications, Inc. Portions created by Netscape are
* Copyright (C) 1999, Mozilla. All Rights Reserved.
*
* Contributor(s):
* Travis Bogard <travis@netscape.com>
* Jerry Kirk <Jerry.Kirk@NexwareCorp.com>
*/
#include "nsCPlatformBaseLoop.h"
#include "nsCPhFilter.h"
//*****************************************************************************
//*** nsCPlatformBaseLoop: Object Management
//*****************************************************************************
nsCPlatformBaseLoop::nsCPlatformBaseLoop(nsEventLoopType type) :
nsCBaseLoop(type)
{
m_PhThreadId = pthread_self();
}
nsCPlatformBaseLoop::~nsCPlatformBaseLoop()
{
}
//*****************************************************************************
// nsCPlatformBaseLoop:: Internal Platform Implementations of nsIEventLoop
// (Error checking is ensured above)
//*****************************************************************************
nsresult nsCPlatformBaseLoop::PlatformGetNextEvent(void* platformFilterData,
void* platformEventData)
{
nsCPhFilter* filter=(nsCPhFilter*)platformFilterData;
PhEvent_t* pEvent = (PhEvent_t*) platformEventData;
if(::GetMessage(pMsg, filter->hWnd, filter->wMsgFilterMin,
filter->wMsgFilterMax))
return NS_OK;
return NS_COMFALSE;
}
nsresult nsCPlatformBaseLoop::PlatformPeekNextEvent(void* platformFilterData,
void* platformEventData, PRBool fRemoveEvent)
{
nsCWinFilter* filter=(nsCWinFilter*)platformFilterData;
MSG* pMsg=(MSG*)platformEventData;
if(fRemoveEvent)
filter->wRemoveFlags|= PM_REMOVE;
else
filter->wRemoveFlags&= ~PM_REMOVE;
if(::PeekMessage(pMsg, filter->hWnd, filter->wMsgFilterMin,
filter->wMsgFilterMax, filter->wRemoveFlags))
return NS_OK;
return NS_COMFALSE;
}
nsresult nsCPlatformBaseLoop::PlatformTranslateEvent(void* platformEventData)
{
MSG* pMsg=(MSG*)platformEventData;
::TranslateMessage(pMsg);
return NS_OK;
}
nsresult nsCPlatformBaseLoop::PlatformDispatchEvent(void* platformEventData)
{
MSG* pMsg=(MSG*)platformEventData;
::DispatchMessage(pMsg);
return NS_OK;
}
nsresult nsCPlatformBaseLoop::PlatformSendLoopEvent(void* platformEventData, PRInt32* result)
{
MSG* pMsg=(MSG*)platformEventData;
*result = ::SendMessage(pMsg->hwnd, pMsg->message, pMsg->wParam,pMsg->lParam);
return NS_OK;
}
nsresult nsCPlatformBaseLoop::PlatformPostLoopEvent(void* platformEventData)
{
MSG* pMsg=(MSG*)platformEventData;
if(!pMsg->hwnd)
{
if(!::PostThreadMessage(m_WinThreadId, pMsg->message, pMsg->wParam,
pMsg->lParam))
return NS_ERROR_FAILURE;
}
else if(!::PostMessage(pMsg->hwnd, pMsg->message, pMsg->wParam, pMsg->lParam))
return NS_ERROR_FAILURE;
return NS_OK;
}
nsNativeEventDataType nsCPlatformBaseLoop::PlatformGetEventType()
{
return nsNativeEventDataTypes::WinMsgStruct;
}
nsNativeEventDataType nsCPlatformBaseLoop::PlatformGetFilterType()
{
return nsNativeFilterDataTypes::WinFilter;
}
PRInt32 nsCPlatformBaseLoop::PlatformGetReturnCode(void* platformEventData)
{
MSG* pMsg=(MSG*)platformEventData;
return pMsg->wParam;
}

View File

@ -0,0 +1,57 @@
/* -*- Mode: IDL; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
*
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
* the License at http://www.mozilla.org/MPL/
*
* Software distributed under the License is distributed on an "AS
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
* implied. See the License for the specific language governing
* rights and limitations under the License.
*
* The Original Code is the Mozilla browser.
*
* The Initial Developer of the Original Code is Netscape
* Communications, Inc. Portions created by Netscape are
* Copyright (C) 1999, Mozilla. All Rights Reserved.
*
* Contributor(s):
* Travis Bogard <travis@netscape.com>
* Jerry Kirk <Jerry.Kirk@NexwareCorp.com>
*/
#ifndef nsCPlatformBaseLoop_h__
#define nsCPlatformBaseLoop_h__
#include "PhT.h"
#include "nsCBaseLoop.h"
class nsCPlatformBaseLoop : public nsCBaseLoop
{
protected:
nsCPlatformBaseLoop(nsEventLoopType type);
virtual ~nsCPlatformBaseLoop();
// Internal Platform Implementations of nsIEventLoop
// (Error checking is ensured above)
// We can over-ride these at a high level because they are the same
// across all types of event loops.
nsresult PlatformGetNextEvent(void* platformFilterData, void* platformEventData);
nsresult PlatformPeekNextEvent(void* FilterData, void* platformEventData,
PRBool fRemoveElement);
nsresult PlatformTranslateEvent(void* platformEventData);
nsresult PlatformDispatchEvent(void* platformEventData);
nsresult PlatformSendLoopEvent(void* platformEventData, PRInt32* result);
nsresult PlatformPostLoopEvent(void* platformEventData);
nsNativeEventDataType PlatformGetEventType();
nsNativeFilterDataType PlatformGetFilterType();
PRInt32 PlatformGetReturnCode(void* platformEventData);
protected:
pthread_t m_PhThreadId;
};
#endif /* nsCAppLoop_h__ */

View File

@ -0,0 +1,12 @@
#include "nsISupports.idl"
#include "nsIEvent.idl"
/**
* The nsIPhEvent defines what a message looks like on the Photon Platform.
*/
[scriptable, uuid(2EFB5005-4508-11d3-AEDA-00A024FFC08C)]
interface nsIPhEvent : nsIEvent
{
//XXX Place the contents of a Photon PhEvent_t struct here.
};

View File

@ -0,0 +1,14 @@
#include "nsISupports.idl"
#include "nsIEventFilter.idl"
/**
* The nsIPhEventFilter defines what a message filter looks like on the Photon
* Platform.
*/
[scriptable, uuid(2EFB5006-4508-11d3-AEDA-00A024FFC08C)]
interface nsIPhEventFilter : nsIEventFilter
{
//XXX Place the contents of a Photon PhEvent_t struct here.
//As well as other needed filtering criteria.
};