Skip to content

Commit

Permalink
IPC for haiku
Browse files Browse the repository at this point in the history
Initial implementation of IPC for haiku will add it to description each time i amend
1)added empty functions
2)fixed building issues and successfully created a connection between webprocess
3)Added a message handler to look out for incoming messages to runloop
  • Loading branch information
RAJAGOPALAN-GANGADHARAN committed May 14, 2019
1 parent ce47621 commit ebecb1d
Show file tree
Hide file tree
Showing 12 changed files with 242 additions and 19 deletions.
2 changes: 1 addition & 1 deletion Source/WTF/wtf/Platform.h
Expand Up @@ -1178,7 +1178,7 @@
#define USE_EXPORT_MACROS 1
#endif

#if PLATFORM(GTK) || PLATFORM(WPE) || PLATFORM(HAIKU)
#if PLATFORM(GTK) || PLATFORM(WPE)
#define USE_UNIX_DOMAIN_SOCKETS 1
#endif

Expand Down
14 changes: 14 additions & 0 deletions Source/WebKit/Platform/IPC/Connection.h
Expand Up @@ -55,6 +55,11 @@
#include "GSocketMonitor.h"
#endif

#if PLATFORM(HAIKU)
#include <Handler.h>
#include <Messenger.h>
#endif

namespace IPC {

enum class SendOption {
Expand Down Expand Up @@ -143,6 +148,9 @@ class Connection : public ThreadSafeRefCounted<Connection, WTF::DestructionThrea
typedef HANDLE Identifier;
static bool createServerAndClientIdentifiers(Identifier& serverIdentifier, Identifier& clientIdentifier);
static bool identifierIsValid(Identifier identifier) { return !!identifier; }
#elif PLATFORM(HAIKU)
typedef team_id Identifier;
static bool identifierIsValid(Identifier identifier) { return BMessenger(NULL,identifier).IsValid(); }
#endif

static Ref<Connection> createServerConnection(Identifier, Client&);
Expand Down Expand Up @@ -398,6 +406,12 @@ class Connection : public ThreadSafeRefCounted<Connection, WTF::DestructionThrea
std::unique_ptr<Encoder> m_pendingWriteEncoder;
EventListener m_writeListener;
HANDLE m_connectionPipe { INVALID_HANDLE_VALUE };
#elif PLATFORM(HAIKU)
Identifier m_connectedProcess;
BHandler* m_readHandler;
BMessenger m_messenger;
void runReadEventLoop();
void runWriteEventLoop();
#endif
};

Expand Down
107 changes: 107 additions & 0 deletions Source/WebKit/Platform/IPC/haiku/ConnectionHaiku.cpp
@@ -0,0 +1,107 @@
/*
* Copyright (C) 2019 Haiku, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "config.h"
#include "Connection.h"

#include <unistd.h>
#include <Message.h>
#include <Looper.h>
namespace IPC{
class ReadLoop: public BHandler
{
public:
ReadLoop(IPC::Connection* con)
:BHandler("Read Message Loop"),
connection(con)
{
}
void MessageReceived(BMessage* message)
{
message->PrintToStream();
}
private:
IPC::Connection* connection;

};
void Connection::platformInitialize(Identifier identifier)
{
fprintf(stderr,"%s\n",__PRETTY_FUNCTION__);
m_connectedProcess = identifier;
}
void Connection::platformInvalidate()
{

}
void Connection::runReadEventLoop()
{
//RunLoop::run();
BLooper* looper = BLooper::LooperForThread(find_thread(NULL));
BLooper* looper = BLooper::LooperForThread(find_thread(NULL));
bool newLooper = false;
if (!looper) {
//This case is not good
return;
} else if (looper != be_app) {
fprintf(stderr, "Add handler to existing RunLoop looper\n");
}
looper->Lock();
looper->AddHandler(m_readHandler);
looper->SetPreferredHandler(m_readHandler);
looper->Unlock();
fprintf(stderr,"\n Connt id:%ld",looper->Thread());
}
void Connection::runWriteEventLoop()
{
}
bool Connection::open()
{
status_t result = m_messenger.SetTo(NULL,m_connectedProcess);
m_readHandler = new ReadLoop(this);
runReadEventLoop();
if(result == B_OK)
{
fprintf(stderr,"%s %ld %ld\n",__PRETTY_FUNCTION__,m_connectedProcess,getpid());
return true;
}

return false;
}
bool Connection::platformCanSendOutgoingMessages() const
{

}
bool Connection::sendOutgoingMessage(std::unique_ptr<Encoder> encoder)
{
fprintf(stderr,"%s\n",__PRETTY_FUNCTION__);
}
void Connection::willSendSyncMessage(OptionSet<SendSyncOption> )
{

}
void Connection::didReceiveSyncReply(OptionSet<SendSyncOption> )
{

}
}
88 changes: 88 additions & 0 deletions Source/WebKit/Platform/haiku/SharedMemoryHaiku.cpp
@@ -0,0 +1,88 @@
/*
* Copyright (C) 2019 Haiku, Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/

#include "config.h"
#include "SharedMemory.h"

#include "Decoder.h"
#include "Encoder.h"

namespace WebKit {

SharedMemory::Handle::Handle()
{
}

SharedMemory::Handle::~Handle()
{
}

SharedMemory::Handle::Handle(Handle&&) = default;
SharedMemory::Handle& SharedMemory::Handle::operator=(Handle&& other) = default;

void SharedMemory::Handle::clear()
{
}

bool SharedMemory::Handle::isNull() const
{
}

void SharedMemory::Handle::encode(IPC::Encoder& encoder) const
{
}

bool SharedMemory::Handle::decode(IPC::Decoder& decoder, Handle& handle)
{
}

static int createSharedMemory()
{
}

RefPtr<SharedMemory> SharedMemory::allocate(size_t size)
{
}

RefPtr<SharedMemory> SharedMemory::map(const Handle& handle, Protection protection)
{

}

SharedMemory::~SharedMemory()
{
}

bool SharedMemory::createHandle(Handle& handle, Protection)
{
}

unsigned SharedMemory::systemPageSize()
{
}

} // namespace WebKit


5 changes: 2 additions & 3 deletions Source/WebKit/PlatformHaiku.cmake
Expand Up @@ -5,11 +5,10 @@ list(APPEND WebKit_SOURCES
NetworkProcess/haiku/NetworkProcessMainHaiku.cpp
NetworkProcess/haiku/RemoteNetworkingContextHaiku.cpp

Platform/IPC/unix/AttachmentUnix.cpp
Platform/IPC/unix/ConnectionUnix.cpp
Platform/IPC/haiku/ConnectionHaiku.cpp
Platform/haiku/LoggingHaiku.cpp
Platform/haiku/ModuleHaiku.cpp
Platform/unix/SharedMemoryUnix.cpp
Platform/haiku/SharedMemoryHaiku.cpp

PluginProcess/unix/PluginControllerProxyUnix.cpp
PluginProcess/unix/PluginProcessMainUnix.cpp
Expand Down
5 changes: 5 additions & 0 deletions Source/WebKit/Shared/unix/AuxiliaryProcessMain.cpp
Expand Up @@ -38,7 +38,12 @@ bool AuxiliaryProcessMainBase::parseCommandLine(int argc, char** argv)
if (argc < 3)
return false;
m_parameters.processIdentifier = makeObjectIdentifier<WebCore::ProcessIdentifierType>(atoll(argv[1]));
#if PLATFORM(HAIKU)
m_parameters.connectionIdentifier = atol(argv[2]);
#else
m_parameters.connectionIdentifier = atoi(argv[2]);
#endif

return true;
}

Expand Down
1 change: 1 addition & 0 deletions Source/WebKit/UIProcess/AuxiliaryProcessProxy.cpp
Expand Up @@ -49,6 +49,7 @@ AuxiliaryProcessProxy::~AuxiliaryProcessProxy()

void AuxiliaryProcessProxy::getLaunchOptions(ProcessLauncher::LaunchOptions& launchOptions)
{
fprintf(stderr,"%s %ld \n",__PRETTY_FUNCTION__,getpid());
launchOptions.processIdentifier = m_processIdentifier;

if (const char* userDirectorySuffix = getenv("DIRHELPER_USER_DIR_SUFFIX"))
Expand Down
Expand Up @@ -31,6 +31,7 @@
#include <Roster.h>
#include <StackOrHeapArray.h>
#include <String.h>
#include <unistd.h>

using namespace WebCore;

Expand Down Expand Up @@ -67,7 +68,9 @@ void ProcessLauncher::launchProcess()
return;
}

BString processIdentifier;
BString processIdentifier,processID;
team_id UIProcessID = getpid();
processID.SetToFormat("%ld",UIProcessID);
processIdentifier.SetToFormat("%" PRIu64, m_launchOptions.processIdentifier.toUInt64());
unsigned nargs = 5; // size of the argv array for g_spawn_async()

Expand Down Expand Up @@ -95,6 +98,7 @@ void ProcessLauncher::launchProcess()
#endif
argv[i++] = executablePath.String();
argv[i++] = processIdentifier.String();
argv[i++] = processID.String();
// TODO pass our team_id so the web process can message us?
argv[i++] = nullptr;

Expand All @@ -103,7 +107,7 @@ void ProcessLauncher::launchProcess()
team_id child_id; // TODO do we need to store this somewhere?
status_t result = be_roster->Launch(&executableRef, i-1, argv, &child_id);

fprintf(stderr, "%s: %s\n", __PRETTY_FUNCTION__, strerror(result));
fprintf(stderr, "%s: %s %ld\n", __PRETTY_FUNCTION__, strerror(result),child_id);

// We've finished launching the process, message back to the main run loop.
RunLoop::main().dispatch([protectedThis = makeRef(*this), this, child_id] {
Expand Down
2 changes: 2 additions & 0 deletions Source/WebKit/WebProcess/WebPage/WebInspector.cpp
Expand Up @@ -90,6 +90,8 @@ void WebInspector::setFrontendConnection(IPC::Attachment encodedConnectionIdenti
IPC::Connection::Identifier connectionIdentifier(encodedConnectionIdentifier.port());
#elif OS(WINDOWS)
IPC::Connection::Identifier connectionIdentifier(encodedConnectionIdentifier.handle());
#elif PLATFORM(HAIKU)
IPC::Connection::Identifier connectionIdentifier(NULL);
#else
notImplemented();
return;
Expand Down
5 changes: 4 additions & 1 deletion Source/WebKit/WebProcess/WebPage/WebInspectorUI.cpp
Expand Up @@ -92,12 +92,15 @@ void WebInspectorUI::updateConnection()
IPC::Connection::Identifier connectionIdentifier, connClient;
IPC::Connection::createServerAndClientIdentifiers(connectionIdentifier, connClient);
IPC::Attachment connectionClientPort(connClient);
#elif PLATFORM(HAIKU)
IPC::Connection::Identifier connectionIdentifier;
IPC::Attachment connectionClientPort;
#else
notImplemented();
return;
#endif

#if USE(UNIX_DOMAIN_SOCKETS) || OS(DARWIN) || PLATFORM(WIN)
#if USE(UNIX_DOMAIN_SOCKETS) || OS(DARWIN) || PLATFORM(WIN) || PLATFORM(HAIKU)
m_backendConnection = IPC::Connection::createServerConnection(connectionIdentifier, *this);
m_backendConnection->open();
#endif
Expand Down
11 changes: 7 additions & 4 deletions Source/WebKit/WebProcess/haiku/WebProcessMainHaiku.cpp
Expand Up @@ -30,7 +30,8 @@
#include "WebProcess.h"

#include <Application.h>
#include<Message.h>
#include <Message.h>
#include <Messenger.h>

using namespace std;
using namespace WebCore;
Expand All @@ -46,13 +47,16 @@ class WebProcessApp: public BApplication

void MessageReceived(BMessage* msg)
{
fprintf(stderr, "%s\n", __PRETTY_FUNCTION__);
msg->PrintToStream();
switch(msg->what)
{
default:
BApplication::MessageReceived(msg);
}
}

void ReadyToRun()
{
fprintf(stderr, "%s\n", __PRETTY_FUNCTION__);
RunLoop::initializeMainRunLoop();
RunLoop::run();
}
Expand All @@ -64,7 +68,6 @@ class WebProcessMain final : public AuxiliaryProcessMainBase {
bool platformInitialize() override
{
WebProcessApp* app= new WebProcessApp();
fprintf(stderr, "%s\n", __PRETTY_FUNCTION__);
app->Run();
return true;
}
Expand Down
13 changes: 5 additions & 8 deletions Tools/MiniBrowser/haiku/App.cpp
Expand Up @@ -35,14 +35,11 @@ App::App(void)
void
App::MessageReceived(BMessage *msg)
{
switch(msg->what)
{
default:
{
BApplication::MessageReceived(msg);
break;
}
}
switch(msg->what)
{
default:
BApplication::MessageReceived(msg);
}
}
void App::ReadyToRun()
{
Expand Down

0 comments on commit ebecb1d

Please sign in to comment.