Added a registrar skeleton.

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@374 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2002-07-21 22:40:07 +00:00
parent e0cc8c68a4
commit 4b8a71155a
8 changed files with 305 additions and 0 deletions
@@ -0,0 +1,28 @@
// ClipboardHandler.cpp
#include <Message.h>
#include "ClipboardHandler.h"
// constructor
ClipboardHandler::ClipboardHandler()
: BHandler()
{
}
// destructor
ClipboardHandler::~ClipboardHandler()
{
}
// MessageReceived
void
ClipboardHandler::MessageReceived(BMessage *message)
{
switch (message->what) {
default:
BHandler::MessageReceived(message);
break;
}
}
+16
View File
@@ -0,0 +1,16 @@
// ClipboardHandler.h
#ifndef CLIPBOARD_HANDLER_H
#define CLIPBOARD_HANDLER_H
#include <Handler.h>
class ClipboardHandler : public BHandler {
public:
ClipboardHandler();
virtual ~ClipboardHandler();
virtual void MessageReceived(BMessage *message);
};
#endif // CLIPBOARD_HANDLER_H
+50
View File
@@ -0,0 +1,50 @@
#ifndef DEBUG_H
#define DEBUG_H
/* Debug - debug stuff
**
** Initial version by Axel Dörfler, [email protected]
** This file may be used under the terms of the OpenBeOS License.
*/
#include <stdio.h>
#define __out printf
// Short overview over the debug output macros:
// PRINT()
// is for general messages that very unlikely should appear in a release build
// FATAL()
// this is for fatal messages, when something has really gone wrong
// INFORM()
// general information, as disk size, etc.
// REPORT_ERROR(status_t)
// prints out error information
// RETURN_ERROR(status_t)
// calls REPORT_ERROR() and return the value
// D()
// the statements in D() are only included if DEBUG is defined
#define DEBUG_APP "REG"
#ifdef DEBUG
#define PRINT(x) { __out(DEBUG_APP ": "); __out x; }
#define REPORT_ERROR(status) __out(DEBUG_APP ": %s:%ld: %s\n",__FUNCTION__,__LINE__,strerror(status));
#define RETURN_ERROR(err) { status_t _status = err; if (_status < B_OK) REPORT_ERROR(_status); return _status;}
#define FATAL(x) { __out(DEBUG_APP ": "); __out x; }
#define INFORM(x) { __out(DEBUG_APP ": "); __out x; }
#define FUNCTION(x) { __out(DEBUG_APP ": %s() ",__FUNCTION__); __out x; }
#define FUNCTION_START() { __out(DEBUG_APP ": %s()\n",__FUNCTION__); }
#define FUNCTION_END() { __out(DEBUG_APP ": %s() done\n",__FUNCTION__); }
#define D(x) {x;};
#else
#define PRINT(x) ;
#define REPORT_ERROR(status) ;
#define RETURN_ERROR(status) return status;
#define FATAL(x) { __out(DEBUG_APP ": "); __out x; }
#define INFORM(x) { __out(DEBUG_APP ": "); __out x; }
#define FUNCTION(x) ;
#define FUNCTION_START() ;
#define FUNCTION_END() ;
#define D(x) ;
#endif
#endif /* DEBUG_H */
+14
View File
@@ -0,0 +1,14 @@
SubDir OBOS_TOP src servers registrar ;
UsePublicHeaders app ;
UsePrivateHeaders app ;
Server obos_registrar :
ClipboardHandler.cpp
MIMEManager.cpp
Registrar.cpp
;
LinkSharedOSLibs obos_registrar :
<boot!home!config!lib>libopenbeos.so
be root
;
+28
View File
@@ -0,0 +1,28 @@
// MIMEManager.cpp
#include <Message.h>
#include "MIMEManager.h"
// constructor
MIMEManager::MIMEManager()
: BLooper("main_mime")
{
}
// destructor
MIMEManager::~MIMEManager()
{
}
// MessageReceived
void
MIMEManager::MessageReceived(BMessage *message)
{
switch (message->what) {
default:
BLooper::MessageReceived(message);
break;
}
}
+16
View File
@@ -0,0 +1,16 @@
// MIMEManager.h
#ifndef MIME_MANAGER_H
#define MIME_MANAGER_H
#include <Looper.h>
class MIMEManager : public BLooper {
public:
MIMEManager();
virtual ~MIMEManager();
virtual void MessageReceived(BMessage *message);
};
#endif // MIME_MANAGER_H
+105
View File
@@ -0,0 +1,105 @@
// Registrar.cpp
#ifndef DEBUG
# define DEBUG 1
#endif
#include "Debug.h"
#include <Application.h>
#include <Message.h>
#include <OS.h>
#include <RegistrarDefs.h>
#include "ClipboardHandler.h"
#include "MIMEManager.h"
#include "Registrar.h"
// constructor
Registrar::Registrar()
: BApplication(kRegistrarSignature),
fClipboardHandler(NULL),
fMIMEManager(NULL)
{
FUNCTION_START();
// move the following code to ReadyToRun() once it works.
fClipboardHandler = new ClipboardHandler;
AddHandler(fClipboardHandler);
fMIMEManager = new MIMEManager;
fMIMEManager->Run();
}
// destructor
Registrar::~Registrar()
{
FUNCTION_START();
fMIMEManager->Lock();
fMIMEManager->Quit();
RemoveHandler(fClipboardHandler);
delete fClipboardHandler;
}
// MessageReceived
void
Registrar::MessageReceived(BMessage *message)
{
FUNCTION_START();
switch (message->what) {
case B_REG_GET_MIME_MESSENGER:
{
PRINT(("B_REG_GET_MIME_MESSENGER\n"));
BMessenger messenger(NULL, fMIMEManager);
BMessage reply(B_REG_SUCCESS);
reply.AddMessenger("messenger", messenger);
message->SendReply(&reply);
break;
}
case B_REG_GET_CLIPBOARD_MESSENGER:
{
PRINT(("B_REG_GET_CLIPBOARD_MESSENGER\n"));
BMessenger messenger(fClipboardHandler);
BMessage reply(B_REG_SUCCESS);
reply.AddMessenger("messenger", messenger);
message->SendReply(&reply);
break;
}
default:
BApplication::MessageReceived(message);
break;
}
FUNCTION_END();
}
// ReadyToRun
void
Registrar::ReadyToRun()
{
FUNCTION_START();
}
// QuitRequested
bool
Registrar::QuitRequested()
{
FUNCTION_START();
// The final registrar must not quit. At least not that easily. ;-)
return BApplication::QuitRequested();
}
// main
int
main()
{
FUNCTION_START();
// rename the main thread
rename_thread(find_thread(NULL), kRosterThreadName);
// create and run the registrar application
Registrar *app = new Registrar();
PRINT(("app->Run()...\n"));
app->Run();
PRINT(("delete app...\n"));
delete app;
FUNCTION_END();
return 0;
}
+48
View File
@@ -0,0 +1,48 @@
//------------------------------------------------------------------------------
// Copyright (c) 2001-2002, OpenBeOS
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the "Software"),
// to deal in the Software without restriction, including without limitation
// the rights to use, copy, modify, merge, publish, distribute, sublicense,
// and/or sell copies of the Software, and to permit persons to whom the
// Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
// DEALINGS IN THE SOFTWARE.
//
// File Name: Registrar.h
// Author: Ingo Weinhold ([email protected])
// Description: Registrar application.
//------------------------------------------------------------------------------
#ifndef REGISTRAR_H
#define REGISTRAR_H
#include <Application.h>
class ClipboardHandler;
class MIMEManager;
class Registrar : public BApplication {
public:
Registrar();
virtual ~Registrar();
virtual void MessageReceived(BMessage *message);
virtual void ReadyToRun();
virtual bool QuitRequested();
private:
ClipboardHandler *fClipboardHandler;
MIMEManager *fMIMEManager;
};
#endif // REGISTRAR_H