2013-06-18 02:33:48 +04:00
|
|
|
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim: set sw=2 ts=8 et ft=cpp: */
|
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
|
|
|
|
2013-11-01 13:45:46 +04:00
|
|
|
/* Copyright © 2013, Deutsche Telekom, Inc. */
|
|
|
|
|
2013-06-18 02:33:48 +04:00
|
|
|
#ifndef mozilla_ipc_Nfc_h
|
|
|
|
#define mozilla_ipc_Nfc_h 1
|
|
|
|
|
2015-03-11 10:34:00 +03:00
|
|
|
#include <mozilla/ipc/ListenSocket.h>
|
2015-01-21 12:59:21 +03:00
|
|
|
#include <mozilla/ipc/StreamSocket.h>
|
2015-03-11 10:33:00 +03:00
|
|
|
#include <mozilla/ipc/UnixSocketConnector.h>
|
2013-06-18 02:33:48 +04:00
|
|
|
|
|
|
|
namespace mozilla {
|
|
|
|
namespace ipc {
|
|
|
|
|
2014-02-19 11:14:22 +04:00
|
|
|
class NfcSocketListener
|
|
|
|
{
|
|
|
|
public:
|
2015-03-09 10:27:00 +03:00
|
|
|
enum SocketType {
|
2015-03-11 10:34:00 +03:00
|
|
|
LISTEN_SOCKET,
|
2015-03-09 10:27:00 +03:00
|
|
|
STREAM_SOCKET
|
|
|
|
};
|
|
|
|
|
2014-02-19 11:14:22 +04:00
|
|
|
virtual void ReceiveSocketData(nsAutoPtr<UnixSocketRawData>& aData) = 0;
|
2015-03-09 10:27:00 +03:00
|
|
|
|
|
|
|
virtual void OnConnectSuccess(enum SocketType aSocketType) = 0;
|
|
|
|
virtual void OnConnectError(enum SocketType aSocketType) = 0;
|
|
|
|
virtual void OnDisconnect(enum SocketType aSocketType) = 0;
|
2014-02-19 11:14:22 +04:00
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class NfcListenSocket final : public mozilla::ipc::ListenSocket
|
2015-03-11 10:34:00 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NfcListenSocket(NfcSocketListener* aListener);
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
void OnConnectSuccess() override;
|
|
|
|
void OnConnectError() override;
|
|
|
|
void OnDisconnect() override;
|
2015-03-11 10:34:00 +03:00
|
|
|
|
|
|
|
private:
|
|
|
|
NfcSocketListener* mListener;
|
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class NfcConnector final : public mozilla::ipc::UnixSocketConnector
|
2015-03-11 10:33:00 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
NfcConnector()
|
|
|
|
{ }
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
int Create() override;
|
2015-03-11 10:33:00 +03:00
|
|
|
bool CreateAddr(bool aIsServer,
|
|
|
|
socklen_t& aAddrSize,
|
|
|
|
sockaddr_any& aAddr,
|
2015-03-21 19:28:04 +03:00
|
|
|
const char* aAddress) override;
|
|
|
|
bool SetUp(int aFd) override;
|
|
|
|
bool SetUpListenSocket(int aFd) override;
|
2015-03-11 10:33:00 +03:00
|
|
|
void GetSocketAddr(const sockaddr_any& aAddr,
|
2015-03-21 19:28:04 +03:00
|
|
|
nsAString& aAddrStr) override;
|
2015-03-11 10:33:00 +03:00
|
|
|
};
|
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
class NfcConsumer final : public mozilla::ipc::StreamSocket
|
2013-06-18 02:33:48 +04:00
|
|
|
{
|
|
|
|
public:
|
2014-02-19 11:14:22 +04:00
|
|
|
NfcConsumer(NfcSocketListener* aListener);
|
2013-11-01 13:45:46 +04:00
|
|
|
|
2014-02-19 11:14:22 +04:00
|
|
|
void Shutdown();
|
|
|
|
bool PostToNfcDaemon(const uint8_t* aData, size_t aSize);
|
2013-11-01 13:45:46 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
ConnectionOrientedSocketIO* GetIO() override;
|
2015-01-21 12:59:21 +03:00
|
|
|
|
2013-06-18 02:33:48 +04:00
|
|
|
private:
|
2015-01-21 12:59:21 +03:00
|
|
|
void ReceiveSocketData(
|
2015-03-21 19:28:04 +03:00
|
|
|
nsAutoPtr<UnixSocketRawData>& aData) override;
|
2013-06-18 02:33:48 +04:00
|
|
|
|
2015-03-21 19:28:04 +03:00
|
|
|
void OnConnectSuccess() override;
|
|
|
|
void OnConnectError() override;
|
|
|
|
void OnDisconnect() override;
|
2013-06-18 02:33:48 +04:00
|
|
|
|
|
|
|
private:
|
2014-02-19 11:14:22 +04:00
|
|
|
NfcSocketListener* mListener;
|
2013-06-18 02:33:48 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace ipc
|
|
|
|
} // namepsace mozilla
|
|
|
|
|
|
|
|
#endif // mozilla_ipc_Nfc_h
|