本文整理汇总了C++中KMessage类的典型用法代码示例。如果您正苦于以下问题:C++ KMessage类的具体用法?C++ KMessage怎么用?C++ KMessage使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了KMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: ioctl
void KBattleshipClient::slotReadData()
{
int len;
ioctl(fd(), FIONREAD, &len);
if(!len)
{
delete m_readNotifier;
m_readNotifier = 0;
emit sigEndConnect();
return;
}
char *buf = new char[len + 1];
readBlock(buf, len);
buf[len] = 0;
m_readBuffer += QString::fromUtf8(buf);
delete []buf;
int pos;
while ((pos = m_readBuffer.find("</kmessage>")) >= 0)
{
pos += 11; // Length of "</kmessage>"
KMessage *msg = new KMessage();
msg->setDataStream(m_readBuffer.left(pos));
m_readBuffer.remove(0, pos);
emit sigNewMessage(msg);
}
}
示例2: KMessage
void KBattleshipWindow::slotSendVersion()
{
KMessage *msg = new KMessage(KMessage::GETVERSION);
msg->versionMessage();
slotSendMessage(msg);
QTimer::singleShot(150, this, SLOT(slotSendGreet()));
}
示例3:
status_t
BPrivate::send_request_to_launch_daemon(KMessage& request, KMessage& reply)
{
status_t status = request.SendTo(get_launch_daemon_port(),
B_PREFERRED_TOKEN, &reply);
if (status != B_OK)
return status;
return (status_t)reply.What();
}
示例4: toPrivate
status_t
MessageAdapter::_ConvertKMessage(const KMessage *fromMessage,
BMessage *toMessage)
{
if (!fromMessage || !toMessage)
return B_BAD_VALUE;
// make empty and init what of the target message
toMessage->MakeEmpty();
toMessage->what = fromMessage->What();
BMessage::Private toPrivate(toMessage);
toPrivate.SetTarget(fromMessage->TargetToken());
toPrivate.SetReply(B_SYSTEM_TEAM, fromMessage->ReplyPort(),
fromMessage->ReplyToken());
// iterate through the fields and import them in the target message
KMessageField field;
while (fromMessage->GetNextField(&field) == B_OK) {
int32 elementCount = field.CountElements();
if (elementCount > 0) {
for (int32 i = 0; i < elementCount; i++) {
int32 size;
const void *data = field.ElementAt(i, &size);
status_t result;
if (field.TypeCode() == B_MESSAGE_TYPE) {
// message type: if it's a KMessage, convert it
KMessage message;
if (message.SetTo(data, size) == B_OK) {
BMessage bMessage;
result = _ConvertKMessage(&message, &bMessage);
if (result < B_OK)
return result;
result = toMessage->AddMessage(field.Name(), &bMessage);
} else {
// just add it
result = toMessage->AddData(field.Name(),
field.TypeCode(), data, size,
field.HasFixedElementSize(), 1);
}
} else {
result = toMessage->AddData(field.Name(), field.TypeCode(),
data, size, field.HasFixedElementSize(), 1);
}
if (result < B_OK)
return result;
}
}
}
return B_OK;
}
示例5: sizeof
void
PortNotificationService::Notify(uint32 opcode, port_id port)
{
char eventBuffer[64];
KMessage event;
event.SetTo(eventBuffer, sizeof(eventBuffer), PORT_MONITOR);
event.AddInt32("event", opcode);
event.AddInt32("port", port);
DefaultNotificationService::Notify(event, opcode);
}
示例6: Notify
void Notify(uint32 eventCode, struct image* image)
{
char eventBuffer[128];
KMessage event;
event.SetTo(eventBuffer, sizeof(eventBuffer), IMAGE_MONITOR);
event.AddInt32("event", eventCode);
event.AddInt32("image", image->info.id);
event.AddPointer("imageStruct", image);
DefaultNotificationService::Notify(event, eventCode);
}
示例7: UpdateListener
status_t
NotificationManager::UpdateListener(const char* serviceName,
uint32 eventMask, NotificationListener& listener)
{
char buffer[96];
KMessage specifier;
specifier.SetTo(buffer, sizeof(buffer), 0);
specifier.AddInt32(kEventMaskString, eventMask);
return UpdateListener(serviceName, &specifier, listener);
}
示例8:
status_t
BPrivate::send_authentication_request_to_registrar(KMessage& request,
KMessage& reply)
{
status_t error = request.SendTo(get_registrar_authentication_port(), 0,
&reply);
if (error != B_OK)
return error;
return (status_t)reply.What();
}
示例9: notify_interface_removed
status_t
notify_interface_removed(net_interface* interface)
{
if (sNotificationModule == NULL)
return B_NOT_SUPPORTED;
char messageBuffer[512];
KMessage message;
message.SetTo(messageBuffer, sizeof(messageBuffer), B_NETWORK_MONITOR);
message.AddInt32("opcode", B_NETWORK_INTERFACE_REMOVED);
message.AddString("interface", interface->name);
return sNotificationModule->send_notification(&message);
}
示例10: _ConvertKMessage
status_t
MessageAdapter::Unflatten(uint32 format, BMessage *into, const char *buffer)
{
if (format == KMessage::kMessageHeaderMagic) {
KMessage message;
status_t result = message.SetTo(buffer,
((KMessage::Header *)buffer)->size);
if (result != B_OK)
return result;
return _ConvertKMessage(&message, into);
}
try {
switch (format) {
case MESSAGE_FORMAT_R5:
{
r5_message_header *header = (r5_message_header *)buffer;
BMemoryIO stream(buffer + sizeof(uint32),
header->flattened_size - sizeof(uint32));
return _UnflattenR5Message(format, into, &stream);
}
case MESSAGE_FORMAT_R5_SWAPPED:
{
r5_message_header *header = (r5_message_header *)buffer;
BMemoryIO stream(buffer + sizeof(uint32),
__swap_int32(header->flattened_size) - sizeof(uint32));
return _UnflattenR5Message(format, into, &stream);
}
case MESSAGE_FORMAT_DANO:
case MESSAGE_FORMAT_DANO_SWAPPED:
{
dano_section_header *header = (dano_section_header *)buffer;
ssize_t size = header->size;
if (header->code == MESSAGE_FORMAT_DANO_SWAPPED)
size = __swap_int32(size);
BMemoryIO stream(buffer + sizeof(uint32), size - sizeof(uint32));
return _UnflattenDanoMessage(format, into, &stream);
}
}
} catch (status_t error) {
into->MakeEmpty();
return error;
}
return B_NOT_A_MESSAGE;
}
示例11: while
// _RequestThread
int32
AuthenticationServer::_RequestThread()
{
TaskManager taskManager;
while (!fTerminating) {
taskManager.RemoveDoneTasks();
// read the request
KMessage request;
status_t error = request.ReceiveFrom(fRequestPort);
if (error != B_OK)
continue;
// get the parameters
const char* context = NULL;
const char* server = NULL;
const char* share = NULL;
bool badPassword = true;
request.FindString("context", &context);
request.FindString("server", &server);
request.FindString("share", &share);
request.FindBool("badPassword", &badPassword);
if (!context || !server || !share)
continue;
String foundUser;
String foundPassword;
if (!badPassword && _GetAuthentication(context, server, share,
&foundUser, &foundPassword)) {
_SendRequestReply(request.ReplyPort(), request.ReplyToken(),
error, false, foundUser.GetString(), foundPassword.GetString());
} else {
// we need to ask the user: create a task that does it
UserDialogTask* task = new(nothrow) UserDialogTask(this, context,
server, share, badPassword, request.ReplyPort(),
request.ReplyToken());
if (!task) {
ERROR(("AuthenticationServer::_RequestThread(): ERROR: "
"failed to allocate "));
continue;
}
status_t error = taskManager.RunTask(task);
if (error != B_OK) {
ERROR(("AuthenticationServer::_RequestThread(): Failed to "
"start server info task: %s\n", strerror(error)));
continue;
}
}
}
return 0;
}
示例12: while
status_t
LocalDebuggerInterface::GetNextDebugEvent(DebugEvent*& _event)
{
while (true) {
char buffer[2048];
int32 messageCode;
ssize_t size = read_port(fDebuggerPort, &messageCode, buffer,
sizeof(buffer));
if (size < 0) {
if (size == B_INTERRUPTED)
continue;
return size;
}
if (messageCode <= B_DEBUGGER_MESSAGE_HANDED_OVER) {
debug_debugger_message_data message;
memcpy(&message, buffer, size);
if (message.origin.team != fTeamID)
continue;
bool ignore = false;
status_t error = _CreateDebugEvent(messageCode, message, ignore,
_event);
if (error != B_OK)
return error;
if (ignore) {
if (message.origin.thread >= 0 && message.origin.nub_port >= 0)
error = continue_thread(message.origin.nub_port,
message.origin.thread);
if (error != B_OK)
return error;
continue;
}
return B_OK;
}
KMessage message;
size = message.SetTo(buffer);
if (size != B_OK)
return size;
return _GetNextSystemWatchEvent(_event, message);
}
return B_OK;
}
示例13: ieee80211_notify_scan_done
void
ieee80211_notify_scan_done(struct ieee80211vap* vap)
{
release_sem_etc(vap->iv_ifp->scan_done_sem, 1,
B_DO_NOT_RESCHEDULE | B_RELEASE_ALL);
TRACE("%s\n", __FUNCTION__);
if (sNotificationModule != NULL) {
char messageBuffer[512];
KMessage message;
message.SetTo(messageBuffer, sizeof(messageBuffer), B_NETWORK_MONITOR);
message.AddInt32("opcode", B_NETWORK_WLAN_SCANNED);
message.AddString("interface", vap->iv_ifp->device_name);
sNotificationModule->send_notification(&message);
}
}
示例14: new
status_t
LocalDebuggerInterface::_GetNextSystemWatchEvent(DebugEvent*& _event,
KMessage& message)
{
status_t error = B_OK;
if (message.What() != B_SYSTEM_OBJECT_UPDATE)
return B_BAD_DATA;
int32 opcode = 0;
if (message.FindInt32("opcode", &opcode) != B_OK)
return B_BAD_DATA;
DebugEvent* event = NULL;
switch (opcode)
{
case B_THREAD_NAME_CHANGED:
{
int32 threadID = -1;
if (message.FindInt32("thread", &threadID) != B_OK)
break;
thread_info info;
error = get_thread_info(threadID, &info);
if (error != B_OK)
break;
event = new(std::nothrow) ThreadRenamedEvent(fTeamID,
threadID, threadID, info.name);
break;
}
default:
{
error = B_BAD_DATA;
break;
}
}
if (event != NULL)
_event = event;
return error;
}
示例15: notify_interface_changed
status_t
notify_interface_changed(net_interface* interface, uint32 oldFlags,
uint32 newFlags)
{
if (sNotificationModule == NULL)
return B_NOT_SUPPORTED;
char messageBuffer[512];
KMessage message;
message.SetTo(messageBuffer, sizeof(messageBuffer), B_NETWORK_MONITOR);
message.AddInt32("opcode", B_NETWORK_INTERFACE_CHANGED);
message.AddString("interface", interface->name);
if (oldFlags != newFlags) {
message.AddInt32("old flags", oldFlags);
message.AddInt32("new flags", newFlags);
}
return sNotificationModule->send_notification(&message);
}