зеркало из https://github.com/mozilla/pjs.git
1) cleanup ipcService/ipcTransport platform factoring
2) add ipc-startup-category 3) add ipc-startup and ipc-shutdown observer topics
This commit is contained in:
Родитель
944d358eb0
Коммит
ae00dedb0c
|
@ -1,3 +1,40 @@
|
|||
/* ***** BEGIN LICENSE BLOCK *****
|
||||
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
||||
*
|
||||
* 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 Mozilla IPC.
|
||||
*
|
||||
* The Initial Developer of the Original Code is
|
||||
* Netscape Communications Corporation.
|
||||
* Portions created by the Initial Developer are Copyright (C) 2002
|
||||
* the Initial Developer. All Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Darin Fisher <darin@netscape.com>
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the terms of
|
||||
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
||||
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
||||
* in which case the provisions of the GPL or the LGPL are applicable instead
|
||||
* of those above. If you wish to allow use of your version of this file only
|
||||
* under the terms of either the GPL or the LGPL, and not to allow others to
|
||||
* use your version of this file under the terms of the MPL, indicate your
|
||||
* decision by deleting the provisions above and replace them with the notice
|
||||
* and other provisions required by the GPL or the LGPL. If you do not delete
|
||||
* the provisions above, a recipient may use your version of this file under
|
||||
* the terms of any one of the MPL, the GPL or the LGPL.
|
||||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifndef ipcModuleUtil_h__
|
||||
#define ipcModuleUtil_h__
|
||||
|
||||
|
|
|
@ -41,6 +41,12 @@ interface nsISimpleEnumerator;
|
|||
interface ipcIMessageObserver;
|
||||
interface ipcIClientObserver;
|
||||
|
||||
%{C++
|
||||
#define IPC_SERVICE_STARTUP_CATEGORY "ipc-startup-category"
|
||||
#define IPC_SERVICE_STARTUP_TOPIC "ipc-startup"
|
||||
#define IPC_SERVICE_SHUTDOWN_TOPIC "ipc-shutdown"
|
||||
%}
|
||||
|
||||
/**
|
||||
* the IPC service provides the means to communicate with an external IPC
|
||||
* daemon and/or other mozilla-based applications on the same physical system.
|
||||
|
@ -50,10 +56,8 @@ interface ipcIClientObserver;
|
|||
* at application startup, the IPC service will attempt to establish a
|
||||
* connection with the IPC daemon. the IPC daemon will be automatically
|
||||
* started if necessary. when a connection has been established, the IPC
|
||||
* service will broadcast an "ipc-startup" notification using the observer
|
||||
* service.
|
||||
*
|
||||
* XXX startup category
|
||||
* service will enumerate the "ipc-startup-category" and broadcast an
|
||||
* "ipc-startup" notification using the observer service.
|
||||
*
|
||||
* when the connection to the IPC daemon is closed, an "ipc-shutdown"
|
||||
* notification will be broadcast.
|
||||
|
|
|
@ -35,20 +35,14 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#ifdef XP_UNIX
|
||||
#include <pwd.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
|
||||
#include "plstr.h"
|
||||
|
||||
#include "nsIFile.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsDirectoryServiceUtils.h"
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
#include "nsIPrefService.h"
|
||||
#include "nsIPrefBranch.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsICategoryManager.h"
|
||||
#include "nsCategoryManagerUtils.h"
|
||||
|
||||
#include "ipcConfig.h"
|
||||
#include "ipcLog.h"
|
||||
|
@ -153,14 +147,7 @@ ipcService::Init()
|
|||
if (appName.IsEmpty())
|
||||
appName = NS_LITERAL_CSTRING("test-app");
|
||||
|
||||
// get socket path from directory service
|
||||
nsCAutoString socketPath;
|
||||
#ifdef XP_UNIX
|
||||
if (NS_FAILED(GetSocketPath(socketPath)))
|
||||
socketPath = NS_LITERAL_CSTRING(IPC_DEFAULT_SOCKET_PATH);
|
||||
#endif
|
||||
|
||||
rv = mTransport->Init(appName, socketPath, this);
|
||||
rv = mTransport->Init(appName, this);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
return NS_OK;
|
||||
|
@ -199,28 +186,6 @@ ipcService::HandleQueryResult(const ipcMessage *rawMsg, PRBool succeeded)
|
|||
mQueryQ.DeleteFirst();
|
||||
}
|
||||
|
||||
#ifdef XP_UNIX
|
||||
nsresult
|
||||
ipcService::GetSocketPath(nsACString &socketPath)
|
||||
{
|
||||
nsCOMPtr<nsIFile> file;
|
||||
NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(file));
|
||||
if (!file)
|
||||
return NS_ERROR_FAILURE;
|
||||
// XXX may want to use getpwuid_r when available
|
||||
struct passwd *pw = getpwuid(geteuid());
|
||||
if (!pw)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
nsCAutoString leaf;
|
||||
leaf = NS_LITERAL_CSTRING(".mozilla-ipc-")
|
||||
+ nsDependentCString(pw->pw_name);
|
||||
file->AppendNative(leaf);
|
||||
file->AppendNative(NS_LITERAL_CSTRING("ipcd"));
|
||||
file->GetNativePath(socketPath);
|
||||
return NS_OK;
|
||||
}
|
||||
#endif
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// interface impl
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -373,16 +338,39 @@ void
|
|||
ipcService::OnConnectionEstablished(PRUint32 clientID)
|
||||
{
|
||||
mClientID = clientID;
|
||||
|
||||
//
|
||||
// enumerate ipc startup category...
|
||||
//
|
||||
NS_CreateServicesFromCategory(IPC_SERVICE_STARTUP_CATEGORY,
|
||||
NS_STATIC_CAST(nsISupports *, this),
|
||||
IPC_SERVICE_STARTUP_TOPIC);
|
||||
}
|
||||
|
||||
void
|
||||
ipcService::OnConnectionLost()
|
||||
{
|
||||
//
|
||||
// XXX error out any pending queries
|
||||
//
|
||||
|
||||
mClientID = 0;
|
||||
|
||||
//
|
||||
// error out any pending queries
|
||||
//
|
||||
while (mQueryQ.First()) {
|
||||
ipcClientQuery *query = mQueryQ.First();
|
||||
query->mObserver->OnClientStatus(query->mReqToken,
|
||||
ipcIClientObserver::CLIENT_DOWN,
|
||||
nsnull);
|
||||
mQueryQ.DeleteFirst();
|
||||
}
|
||||
|
||||
//
|
||||
// broadcast ipc shutdown...
|
||||
//
|
||||
nsCOMPtr<nsIObserverService> observ(
|
||||
do_GetService("@mozilla.org/observer-service;1"));
|
||||
if (observ)
|
||||
observ->NotifyObservers(NS_STATIC_CAST(nsISupports *, this),
|
||||
IPC_SERVICE_SHUTDOWN_TOPIC, nsnull);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -112,7 +112,6 @@ public:
|
|||
private:
|
||||
nsresult ErrorAccordingToIPCM(PRUint32 err);
|
||||
void HandleQueryResult(const ipcMessage *, PRBool succeeded);
|
||||
nsresult GetSocketPath(nsACString &);
|
||||
|
||||
// ipcTransportObserver:
|
||||
void OnConnectionEstablished(PRUint32 clientID);
|
||||
|
|
|
@ -60,18 +60,18 @@
|
|||
|
||||
nsresult
|
||||
ipcTransport::Init(const nsACString &appName,
|
||||
const nsACString &socketPath,
|
||||
ipcTransportObserver *obs)
|
||||
{
|
||||
mAppName = appName;
|
||||
mObserver = obs;
|
||||
|
||||
#ifdef XP_UNIX
|
||||
InitUnix(socketPath);
|
||||
#endif
|
||||
|
||||
LOG(("ipcTransport::Init [app-name=%s]\n", mAppName.get()));
|
||||
|
||||
#ifdef XP_UNIX
|
||||
nsresult rv = InitUnix();
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
#endif
|
||||
|
||||
// XXX service should be the observer
|
||||
nsCOMPtr<nsIObserverService> observ(do_GetService("@mozilla.org/observer-service;1"));
|
||||
if (observ) {
|
||||
|
|
|
@ -91,7 +91,6 @@ public:
|
|||
virtual ~ipcTransport() {}
|
||||
|
||||
nsresult Init(const nsACString &appName,
|
||||
const nsACString &socketPath, // ignored if not UNIX
|
||||
ipcTransportObserver *observer);
|
||||
nsresult Shutdown();
|
||||
|
||||
|
@ -140,8 +139,9 @@ private:
|
|||
//
|
||||
// unix specific helpers
|
||||
//
|
||||
nsresult InitUnix(const nsACString &socketPath);
|
||||
nsresult InitUnix();
|
||||
nsresult CreateTransport();
|
||||
nsresult GetSocketPath(nsACString &);
|
||||
|
||||
public:
|
||||
//
|
||||
|
|
|
@ -35,7 +35,14 @@
|
|||
*
|
||||
* ***** END LICENSE BLOCK ***** */
|
||||
|
||||
#include <pwd.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "nsIFile.h"
|
||||
#include "nsIServiceManager.h"
|
||||
#include "nsDirectoryServiceUtils.h"
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
#include "ipcSocketProviderUnix.h"
|
||||
#include "nsISocketTransportService.h"
|
||||
#include "nsIInputStream.h"
|
||||
|
@ -56,9 +63,11 @@ static NS_DEFINE_CID(kSocketTransportServiceCID, NS_SOCKETTRANSPORTSERVICE_CID);
|
|||
//-----------------------------------------------------------------------------
|
||||
|
||||
nsresult
|
||||
ipcTransport::InitUnix(const nsACString &socketPath)
|
||||
ipcTransport::InitUnix()
|
||||
{
|
||||
mSocketPath = socketPath;
|
||||
nsresult rv = GetSocketPath(mSocketPath);
|
||||
if (NS_FAILED(rv)) return rv;
|
||||
|
||||
ipcSocketProviderUnix::SetSocketPath(socketPath);
|
||||
return NS_OK;
|
||||
}
|
||||
|
@ -184,6 +193,26 @@ ipcTransport::CreateTransport()
|
|||
return rv;
|
||||
}
|
||||
|
||||
nsresult
|
||||
ipcTransport::GetSocketPath(nsACString &socketPath)
|
||||
{
|
||||
nsCOMPtr<nsIFile> file;
|
||||
NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(file));
|
||||
if (!file)
|
||||
return NS_ERROR_FAILURE;
|
||||
// XXX may want to use getpwuid_r when available
|
||||
struct passwd *pw = getpwuid(geteuid());
|
||||
if (!pw)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
nsCAutoString leaf;
|
||||
leaf = NS_LITERAL_CSTRING(".mozilla-ipc-")
|
||||
+ nsDependentCString(pw->pw_name);
|
||||
file->AppendNative(leaf);
|
||||
file->AppendNative(NS_LITERAL_CSTRING("ipcd"));
|
||||
file->GetNativePath(socketPath);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// ipcSendQueue
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
Загрузка…
Ссылка в новой задаче