I am facing issue in passing data between c# and C++ (QT) application through named pipe communication. C# client application connects to NamedPipe server which is in c++ but message is not being parsed correctly on server. Example, I am sending value of short variable = 2 and c++ code parse byte array into unsigned int but value is coming always zero in server. Could you please let me know what I am doing wrong?
Client and server code:
NamedPipe Server code in C++ using QT Library
QLocalSocket *local_socket = _local_server->nextPendingConnection();
if (!local_socket->waitForReadyRead(gft::PROC_TIMEOUT)) {
qDebug() << "gft_plugin: timeout while waiting for data";
return;
}
int bytesavailable = local_socket->bytesAvailable();
QByteArray buffer;
QDataStream in(&buffer, QIODevice::ReadOnly);
buffer.append(local_socket->readAll());
unsigned int msg;
in >> msg;
unsigned int a_id = msg;
NamedPipe Client (C#)
var clientStream = new NamedPipeClientStream("localhost", "gft_plugin_server", PipeDirection.InOut);
clientStream.Connect();
if (clientStream.IsConnected)
{
_stop = false;
UInt16 a_id = 2;
byte[] b = BitConverter.GetBytes(a_id);
clientStream.Write(b, 0, b.Count());
clientStream.Flush();
}
else
{
MessageBox.Show("Could not connected");
}
Related
I am developing an application in C++, winApi and Qt. What this application does is that it communicates through serial COM ports.
A user can open multiple pairs of ports and an opened port listens other port constantly.
To implement this functionality I use windows threads.There is a method named startRead() that reads from other port constantly and changes the text area.
void SendAndReceive::startRead(){
DWORD numRead = 0;
std::string hex;
while (1)
{
char *buffer = (char *)malloc(sizeof(char) * 500);
BOOL ret = ReadFile(portHandler, buffer, 500, &numRead, 0);
if (!ret)
{
std::string errorMessage = "";
}
buffer[numRead] = '\0';
std::string receivedData(buffer);
QString QData(receivedData.c_str());
if (ui->checkBox->isChecked())
{
std::string receivedData(buffer);
hex= stringToHex(receivedData);
QString QData1(hex.c_str());
emit asHex(QData1);
}
QString QData2(receivedData.c_str()) ;
emit finished(QData2);
free(buffer);
}
}
And there is another thread that writes data periodically to other port. For example , if you enter 2 seconds in a text line , the program writes data to other port at every 2 seconds and this method is writePeriodic().
void SendAndReceive::writePeriodic(){
DWORD numWritten;
while (1 && checkWrite == true )
{
Concurrency::wait(timePeriod*1000);
QString QData = ui->textEdit->toPlainText();
std::string data = QData.toStdString();
WriteFile(portHandler, data.c_str(), strlen(data.c_str()), &numWritten, NULL);
}
}
So when I run this program , program runs smoothly for 2 or 3 minutes and then it crashes and I get errors like "Program has stopped working" , "program closed unexpectedly".When I debug program , it says something like "Qt5Core not loaded" or "Qt5Gui not loaded".
Before I ask here , I did some search on the web . First I did not use emit finished(QString) signal , instead I directly manipulated GUI objects inside startRead() method.(I did something like ui->text_edit->setText(some QString)).But after some search I learn that I can not change GUI objects from another thread so I decided to use signal and slot mechanism and it has not solved my problem so far.I get same error again and again.Please tell me what I am doing wrong . If you need further explanation, I will happily give more details.
I am trying to implement a Chrome extension using runtime.connectNative and postMessage. I am following the Chrome documentation, downloaded the native messaging example, and changed the native app to using C++.
However, the native app cannot receive the message from the Chrome extension.
Meanwhile, when the native app using the printf function write message to chrome extension, the extension can not receive and the message just shown in the console.
Any ideas how to solve the problem?
You didn't provide a lot information about what you actually tried, so I will do my best to explain the steps needed to implement Chrome Extension, Native Messaging host and establish communication between them. (Please examine the following link to obtain more information about Chrome Native Messaging: Chrome Native Messaging How to.
CHROME EXTENSION
Firstly, we need to set up Chrome extension. As this will be very simple extension, we need only manifest.json file (please note this is extension's manifest file - native host will have its own manifest file as well) and background.js javascript implementation.
The following is sample manifest.json file:
{
"name": "Test extension",
"description": "Native messaging test",
"permissions": [
"nativeMessaging",
"tabs",
"activeTab",
"background",
"http://*/", "https://*/"
],
"background": {
"scripts": ["background.js"]
},
"version": "1.0",
"minimum_chrome_version": "29",
"manifest_version": 2
}
Important things here are that implementation will be provided in background.js, minimum supported Chrome version is 29 and HTTP and HTTPS are both supported.
Next, background.js file has the following content:
var port = chrome.runtime.connectNative('com.dolby.native_messaging_host');
port.onMessage.addListener(function(msg) {
console.log(msg.text);
});
port.onDisconnect.addListener(function() {
console.log("Disconnected");
});
port.postMessage({"text":"This is message from Chrome extension"});
The code itself is pretty self-explanatory - we try to connect to native host identified by com.dolby.native_messaging_host key (I will come to this in a minute). Then, we register a listener for onMessage event (this event is triggered when native host sends a message to the chrome extension). We also register a listener for disconnect event (for example when native host dies this event will be triggered). And finally, we send a message using postMessage method.
NATIVE MESSAGING HOST
Now, native host also has its own manifest.json file. Very simple manifest.json file for native host is as follows:
{
"name": "com.dolby.native_messaging_host",
"description": "Native messaging host",
"path": "C:\\Users\\dbajg\\Desktop\\Native-messaging-host\\Debug\\Native-messaging-host.exe",
"type": "stdio",
"allowed_origins": [
"chrome-extension://bjgnpdfhbcpjdfjoplajcmbleickphpg/"
]
}
Couple of interesting things here: name identifies the key under which this native host is registered. Path is full path to native host executable. Type of communication stdio means we are using standard input/output for communication (only type currently supported). And finally, allowed_origins specify which extensions can communicate with this native host - so you have to find out what is your extension's key!.
The next step is to register this Native Messaging host in registry (for Windows) and specify the location to its manifest file. The following screenshots explains how to this for Windows (examine provided link to find out how to do this in OSX and Linux):
After you've added registry entry for your native host the only remaining thing is to write your native host. The following C++ code implements simple native host that reads messages from the standard input and writes response to standard output (when you send #STOP# message the native host exits):
#include <iostream>
#include <string>
int main(){
std::string oneLine = "";
while (1){
unsigned int length = 0;
//read the first four bytes (=> Length)
/*for (int i = 0; i < 4; i++)
{
int read_char = getchar();
length += read_char * (int) pow(2.0, i*8);
std::string s = std::to_string((long long)read_char) + "\n";
fwrite(s.c_str(), sizeof(char), s.size(), f);
fflush(f);
}*/
//Neat way!
for (int i = 0; i < 4; i++)
{
unsigned int read_char = getchar();
length = length | (read_char << i*8);
}
//read the json-message
std::string msg = "";
for (int i = 0; i < length; i++)
{
msg += getchar();
}
std::string message = "{\"text\":\"This is a response message\"}";
// Collect the length of the message
unsigned int len = message.length();
// Now we can output our message
if (msg == "{\"text\":\"#STOP#\"}"){
message = "{\"text\":\"EXITING...\"}";
len = message.length();
std::cout << char(len>>0)
<< char(len>>8)
<< char(len>>16)
<< char(len>>24);
std::cout << message;
break;
}
// return stdin message
len = length;
std::cout << char(len>>0)
<< char(len>>8)
<< char(len>>16)
<< char(len>>24);
std::cout << msg << std::flush;
// return response message
// std::cout << char(len>>0)
// << char(len>>8)
// << char(len>>16)
// << char(len>>24);
//
// std::cout << message << std::flush;
}
return 0;
}
Messages sent by extension to native host is formed in a way that first byte stores the number of bytes in the message. So the first thing native host must do is to read the first 4 bytes and calculate the size of the message. I explained how to do this in another post that can be found here:
How to calculate size of the message sent by chrome extension
For future Google people, here's how I do it:
C style
Reading
char bInLen[4];
read(0, bInLen, 4); // 0 is stdin
unsigned int inLen = *(unsigned int *)bInLen;
char *inMsg = (char *)malloc(inLen);
read(0, inMsg, inLen);
inMsg[inLen] = '\0';
...
free(inMsg);
Writing
char *outMsg = "{\"text\":\"This is a response message\"}";
unsigned int outLen = strlen(outMsg);
char *bOutLen = (char *)&outLen;
write(1, bOutLen, 4); // 1 is stdout
write(1, outMsg, outLen);
fflush(stdout);
C++ style
Reading
char bInLen[4];
cin.read(bInLen, 4);
unsigned int inLen = *reinterpret_cast<unsigned int *>(bInLen);
char *inMsg = new char[inLen];
cin.read(inMsg, inLen);
string inStr(inMsg); // if you have managed types, use them!
delete[] inMsg;
Writing
string outMsg = "{\"text\":\"This is a response message\"}";
unsigned int outLen = outMsg.length();
char *bOutLen = reinterpret_cast<char *>(&outLen);
cout.write(bOutLen, 4);
cout << outMsg << flush;
I am learning boost::asio network programming and tried to make simple file transfer exercise, using blocking sockets, and so, stuck upon strange issue issue.
Server (receiver) loop is following:
while (true){
int bufSize{ static_cast<int>(pow(2, 18)) };
char* buf{ new char[bufSize] };
__int64 currPos{ 0 };
__int64 fileSize;
std::string fileName;
mSocket->receive(buffer(buf, bufSize)); // here we get pre-defined packet with XML
ParseDescXML(std::string{ buf }, &fileName, &fileSize); // and parse this XML, get name and size
std::ofstream ofs(mSavePath + fileName, std::ios::binary);
if (ofs.is_open()){
while (currPos != fileSize) {
if (bufSize > fileSize - currPos){
delete[] buf;
bufSize = fileSize - currPos;
buf = new char[bufSize];
}
mSocket->receive(buffer(buf, bufSize));
ofs.write(buf, bufSize);
currPos += bufSize;
std::cout << "SERVER " << currPos << std::endl;
}
}
delete[] buf;
ofs.close();
slDebug("Receive completed"); // output some stuff, not related to issue
}
client (sender) loop is following:
mWorkerOccupied = true;
std::ifstream ifs(filePath, std::ios::binary);
if (!ifs.is_open()){
mWorkerOccupied = false;
return false;
}
mFileName = filePath.substr(filePath.find_last_of('\\') + 1, filePath.length());
mCurrPos = 0;
mFileSize = GetFileSize(&ifs);
std::string xmlDesc{ MakeXMLFileDesc(mFileName, mFileSize) }; // here we make XML description
xmlDesc.push_back('\0');
int bufSize{ static_cast<int>(pow(2, 18)) };
char* buf{ new char[bufSize] };
mSocket->send(buffer(xmlDesc.c_str(), bufSize)); // and send it.
while (mCurrPos != mFileSize){
if (bufSize > mFileSize - mCurrPos){
delete[] buf;
bufSize = mFileSize - mCurrPos;
buf = new char[bufSize];
}
ifs.read(buf, bufSize);
mSocket->send(buffer(buf, bufSize));
mCurrPos += bufSize;
std::cout << "CLIENT " << mCurrPos << std::endl;
}
ifs.close();
delete[] buf;
mWorkerOccupied = false;
slDebug("SendFile completed");
All this stuff is running in parallels threads.
From my understanding it should be working this way:
Server thread runs servers and hangs, until incoming connection (working as expected, so I did not include this code here).
Client thread runs after some time and connects to server (working as expected)
Server waiting for first packet, contains XML (working as expected)
Client sends XML, server gets it (working as expected)
Client starts to send actual binary data, server get it. Here we have major problem.
I have a output of current position of file in both client and server loop.
I expect it to be something like:
CLIENT 228 // first we send some data
SERVER 228 // Server gets it and outputs the same file pos
or
CLIENT 228
CLIENT 456
SERVER 228
SERVER 456
But what I am actually getting - confuses me...
SERVER 499384320
SERVER 499646464
CLIENT 88604672
SERVER 499908608
CLIENT 88866816
SERVER 500170752
SERVER 500432896
SERVER 500695040
SERVER 500957184
Far more messages regarding receiving something by server, than client ones about sending. How it can be? Literally, looks like client sent only 80mb of data, while server already received 500mb of data... I thought, that server thread should wait on receive(), since I am using blocking socket, but this is strange. Could someone explain me, why I have this huge desync?
You're assuming that receive reads the entire buffer size at once, but it doesn't necessarily:
The receive operation may not receive all of the requested number of bytes. Consider using
the read function if you need to ensure that the requested amount of data is read before the
blocking operation completes
receive returns the amount of data read, you should change your code to something like:
size_t recvd = mSocket->receive(buffer(buf, bufSize));
ofs.write(buf, recvd);
currPos += recvd;
I wrote two programs, one as server and another as client. The server is written in standard C++ using WinSock2.h. It is a simple echo server which means the server responds what it receives back to the client. I used a new thread for every client's connection, and in each thread:
Socket* s = (Socket*) a;
while (1) {
std::string r = s->ReceiveLine()
if (r.empty()) {
break;
}
s->SendLine(r);
}
delete s;
return 0;
Socket is a class from here. The server runs properly and I've tested it using telnet, it works well.
Then I wrote the client using C++.NET (or C++/CLI), TcpClient is used to send and receive message from the server. The code is like:
String^ request = "test";
TcpClient ^ client = gcnew TcpClient(server, port);
array<Byte> ^ data = Encoding::ASCII->GetBytes(request);
NetworkStream ^ stream = client->GetStream();
stream->Write(data, 0, data->Length);
data = gcnew array<Byte>(256);
String ^ response = String::Empty;
int bytes = stream->Read(data, 0, data->Length);
response = Encoding::ASCII->GetString(data, 0, bytes);
client->Close();
When I run the client and tries to show the response message onto my form, the program halted at the line int bytes = stream->Read(data, 0, data->Length); and cannot fetch the response. The server is running and there's nothing to do with the network as they are all running on the same computer.
I guess the reason is that the data server responds with is less than data->Length, so the Read method is waiting for more data. Is that right? How should I solve this problem?
Edit
I think I've solved the problem... There are another two methods in the Socket class, ReceiveBytes and SendBytes, and these two methods will not delete the unused space in the bytes array. So the length of data back from the server will match that from the client, thus the Read method will not wait for more data to come.
std::string Socket::ReceiveLine() {
std::string ret;
while (1) {
char r;
switch(recv(s_, &r, 1, 0)) {
case 0: // not connected anymore;
// ... but last line sent
// might not end in \n,
// so return ret anyway.
return ret;
case -1:
return "";
// if (errno == EAGAIN) {
// return ret;
// } else {
// // not connected anymore
// return "";
// }
}
ret += r;
if (r == '\n') return ret;
}
}
i guess receiveline function of the server is waiting for an enter key '\n'.
just try with "test\n" string.
String^ request = "test\n";
// other codes....
I'm working on simple host program (c++/xcode/osx) that establishes a connection to a Bluetooth client and opens an RFCOMM channel for data transmission. When I send data from the BT client to the host I get my data mixed with random dumps from what looks to be a Bluetooth Audio Agent. Is it possible that I'm sharing my RFCOMM channel with the OS X Bluetooth Audio Agent?
My Bluetooth device needs to support both Serial (SPP) and Hands-Free (HFP) profiles. So I strongly believe that the issue is around the HFP or SCO profile polluting my RFCOMM channel with it's data. Is there a way to make sure that I only get my data coming through the channel?
Here's a condensed version of my project. When the client is connected it starts echoing the letter a. The host app prints what it receives from the client, and if the received data is an a it also logs OK!\n.
#include <IOBluetooth/IOBluetoothUserLib.h>
#include <IOBluetooth/IOBluetoothUtilities.h>
#include <IOBluetoothUI/IOBluetoothUI.h>
#include <IOBluetoothUI/IOBluetoothUIUserLib.h>
#include "testApp.h"
// Callback function create-connection
void bluetoothCreateConnection_c(void *userRefCon, IOBluetoothDeviceRef deviceRef, IOReturn status) {
printf("Created connection\n");
}
// Callback for RFCOMM events
void rfcommEventListener_c (IOBluetoothRFCOMMChannelRef channel_ref, void *userRefCon, IOBluetoothRFCOMMChannelEvent *event) {
if (event->eventType == kIOBluetoothRFCOMMNewDataEvent) {
const char *data_const = (const char *)event->u.data.dataPtr;
char *dataAsBytes = const_cast<char *>(data_const);
string in_s = (string)dataAsBytes;
printf("%s", dataAsBytes);
if(in_s == "a") {
printf("OK!\n");
}
}
}
void testApp::setup() {
BluetoothDeviceAddress *addr;
string s = "00-16-a4-00-72-3d"; // hardcoded BT address
CFStringRef str_addr;
str_addr = CFStringCreateWithCString(kCFAllocatorDefault, s.c_str(), kCFStringEncodingMacRoman);
IOBluetoothCFStringToDeviceAddress(str_addr, addr);
IOBluetoothDeviceRef dev = IOBluetoothDeviceCreateWithAddress(addr);
IOBluetoothDeviceOpenConnection(dev, &bluetoothCreateConnection_c, NULL);
printf("in openRFCOMMChannel\n");
CFArrayRef device_services = IOBluetoothDeviceGetServices(dev);
printf("Getting SDP service record\n");
IOBluetoothSDPServiceRecordRef service_record = (IOBluetoothSDPServiceRecordRef) CFArrayGetValueAtIndex(device_services, 0);
UInt8 channel_id;
IOBluetoothRFCOMMChannelRef channel_ref;
printf("Finding channel ID\n");
IOBluetoothSDPServiceRecordGetRFCOMMChannelID(service_record, &channel_id);
// Open channel and listen for RFCOMM data
IOBluetoothDeviceOpenRFCOMMChannelAsync(dev, &channel_ref, channel_id, &rfcommEventListener_c, NULL);
}
Here's the output from the program:
run
[Switching to process 41228]
Running…
in openRFCOMMChannel
2011-06-13 13:44:04.762 test (Debug)[41228:a0f] *** __NSAutoreleaseNoPool(): Object 0x1d27770 of class NSCFArray autoreleased with no pool in place - just leaking
Getting SDP service record
Finding channel ID
Created connection
aOK!
aaOK!
aaOK!
a!()*\251\253\274_BluetoothVersionNumber_PersistentServicesZHIDDevices_SCOAudioDevices_DaemonNoRoleSwitchDeviceList_!DaemonControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionarya)*\251\253\274_BluetoothVersionNumber_PersistentServicesZHIDDevices_SCOAudioDevices_DaemonNoRoleSwitchDeviceList_!DaemonControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionarya\251\253\274_BluetoothVersionNumber_PersistentServicesZHIDDevices_SCOAudioDevices_DaemonNoRoleSwitchDeviceList_!DaemonControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionarya_BluetoothVersionNumber_PersistentServicesZHIDDevices_SCOAudioDevices_DaemonNoRoleSwitchDeviceList_!DaemonControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryauetoothVersionNumber_PersistentServicesZHIDDevices_SCOAudioDevices_DaemonNoRoleSwitchDeviceList_!DaemonControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryathVersionNumber_PersistentServicesZHIDDevices_SCOAudioDevices_DaemonNoRoleSwitchDeviceList_!DaemonControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryasionNumber_PersistentServicesZHIDDevices_SCOAudioDevices_DaemonNoRoleSwitchDeviceList_!DaemonControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaumber_PersistentServicesZHIDDevices_SCOAudioDevices_DaemonNoRoleSwitchDeviceList_!DaemonControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionarya_PersistentServicesZHIDDevices_SCOAudioDevices_DaemonNoRoleSwitchDeviceList_!DaemonControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryarsistentServicesZHIDDevices_SCOAudioDevices_DaemonNoRoleSwitchDeviceList_!DaemonControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaentServicesZHIDDevices_SCOAudioDevices_DaemonNoRoleSwitchDeviceList_!DaemonControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryarvicesZHIDDevices_SCOAudioDevices_DaemonNoRoleSwitchDeviceList_!DaemonControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryasZHIDDevices_SCOAudioDevices_DaemonNoRoleSwitchDeviceList_!DaemonControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaDevices_SCOAudioDevices_DaemonNoRoleSwitchDeviceList_!DaemonControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaes_SCOAudioDevices_DaemonNoRoleSwitchDeviceList_!DaemonControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaSCOAudioDevices_DaemonNoRoleSwitchDeviceList_!DaemonControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryadioDevices_DaemonNoRoleSwitchDeviceList_!DaemonControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryavices_DaemonNoRoleSwitchDeviceList_!DaemonControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionarya_DaemonNoRoleSwitchDeviceList_!DaemonControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaemonNoRoleSwitchDeviceList_!DaemonControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaoRoleSwitchDeviceList_!DaemonControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaSwitchDeviceList_!DaemonControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryahDeviceList_!DaemonControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaceList_!DaemonControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryat_!DaemonControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaaemonControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaControllersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaollersConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryasConfigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaigurationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryationKey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaey_ControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaControllerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaollerPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaPowerState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaState_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionarya_BluetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryauetoothAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryathAutoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaoSeekHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaHIDDevices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryavices_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionarya_PersistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryarsistentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaentPortsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryartsZPANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaANDevices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaices]PairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaPairedDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryadDevices_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaces_PersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaPersistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaistentPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryatPortsServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryasServicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaicesOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryaOMstreamtyped\201\350\204#\204\204\204NSMutableDictionaryastreamtyped\201\350\204#\204\204\204NSMutableDictionaryaamtyped\201\350\204#\204\204\204NSMutableDictionaryaed\201\350\204#\204\204\204NSMutableDictionarya\204#\204\204\204NSMutableDictionarya\204NSMutableDictionaryaaeDictionaryaionaryayaNSDictionaryationaryaryaNSObjectajectaa\206\242a_00-14-51-cc-20-41_00-0a-95-3f-fe-8a\324a0-14-51-cc-20-41_00-0a-95-3f-fe-8a\324a51-cc-20-41_00-0a-95-3f-fe-8a\324a-20-41_00-0a-95-3f-fe-8a\324a1_00-0a-95-3f-fe-8a\324a0-0a-95-3f-fe-8a\324a95-3f-fe-8a\324a-fe-8a\324aa\324a\324aOK!
a\232a00-16-a4-00-17-7e_00-16-a4-00-72-3d_00-23-7f-49-98-a6_00-1a-10-04-13-9a\323a6-a4-00-17-7e_00-16-a4-00-72-3d_00-23-7f-49-98-a6_00-1a-10-04-13-9a\323a00-17-7e_00-16-a4-00-72-3d_00-23-7f-49-98-a6_00-1a-10-04-13-9a\323a-7e_00-16-a4-00-72-3d_00-23-7f-49-98-a6_00-1a-10-04-13-9a\323a00-16-a4-00-72-3d_00-23-7f-49-98-a6_00-1a-10-04-13-9a\323a6-a4-00-72-3d_00-23-7f-49-98-a6_00-1a-10-04-13-9a\323a00-72-3d_00-23-7f-49-98-a6_00-1a-10-04-13-9a\323a-3d_00-23-7f-49-98-a6_00-1a-10-04-13-9a\323a00-23-7f-49-98-a6_00-1a-10-04-13-9a\323a3-7f-49-98-a6_00-1a-10-04-13-9a\323a49-98-a6_00-1a-10-04-13-9a\323a-a6_00-1a-10-04-13-9a\323a00-1a-10-04-13-9a\323aa-10-04-13-9a\323a04-13-9a\323a-9a\323a\323aOK!
aYAgentPathXDriverID_IOAudioControls_W/System/Library/CoreServices/BluetoothAudioAgent.app/Contents/MacOS/BluetoothAudioAgent_00-16-a4-00-17-7e-SCO\244antPathXDriverID_IOAudioControls_W/System/Library/CoreServices/BluetoothAudioAgent.app/Contents/MacOS/BluetoothAudioAgent_00-16-a4-00-17-7e-SCO\244ahXDriverID_IOAudioControls_W/System/Library/CoreServices/BluetoothAudioAgent.app/Contents/MacOS/BluetoothAudioAgent_00-16-a4-00-17-7e-SCO\244averID_IOAudioControls_W/System/Library/CoreServices/BluetoothAudioAgent.app/Contents/MacOS/BluetoothAudioAgent_00-16-a4-00-17-7e-SCO\244a_IOAudioControls_W/System/Library/CoreServices/BluetoothAudioAgent.app/Contents/MacOS/BluetoothAudioAgent_00-16-a4-00-17-7e-SCO\244aAudioControls_W/System/Library/CoreServices/BluetoothAudioAgent.app/Contents/MacOS/BluetoothAudioAgent_00-16-a4-00-17-7e-SCO\244aControls_W/System/Library/CoreServices/BluetoothAudioAgent.app/Contents/MacOS/BluetoothAudioAgent_00-16-a4-00-17-7e-SCO\244aols_W/System/Library/CoreServices/BluetoothAudioAgent.app/Contents/MacOS/BluetoothAudioAgent_00-16-a4-00-17-7e-SCO\244aW/System/Library/CoreServices/BluetoothAudioAgent.app/Contents/MacOS/BluetoothAudioAgent_00-16-a4-00-17-7e-SCO\244atem/Library/CoreServices/BluetoothAudioAgent.app/Contents/MacOS/BluetoothAudioAgent_00-16-a4-00-17-7e-SCO\244aibrary/CoreServices/BluetoothAudioAgent.app/Contents/MacOS/BluetoothAudioAgent_00-16-a4-00-17-7e-SCO\244ay/CoreServices/BluetoothAudioAgent.app/Contents/MacOS/BluetoothAudioAgent_00-16-a4-00-17-7e-SCO\244aeServices/BluetoothAudioAgent.app/Contents/MacOS/BluetoothAudioAgent_00-16-a4-00-17-7e-SCO\244aices/BluetoothAudioAgent.app/Contents/MacOS/BluetoothAudioAgent_00-16-a4-00-17-7e-SCO\244aBluetoothAudioAgent.app/Contents/MacOS/BluetoothAudioAgent_00-16-a4-00-17-7e-SCO\244aoothAudioAgent.app/Contents/MacOS/BluetoothAudioAgent_00-16-a4-00-17-7e-SCO\244audioAgent.app/Contents/MacOS/BluetoothAudioAgent_00-16-a4-00-17-7e-SCO\244agent.app/Contents/MacOS/BluetoothAudioAgent_00-16-a4-00-17-7e-SCO\244aapp/Contents/MacOS/BluetoothAudioAgent_00-16-a4-00-17-7e-SCO\244aontents/MacOS/BluetoothAudioAgent_00-16-a4-00-17-7e-SCO\244ats/MacOS/BluetoothAudioAgent_00-16-a4-00-17-7e-SCO\244acOS/BluetoothAudioAgent_00-16-a4-00-17-7e-SCO\244aluetoothAudioAgent_00-16-a4-00-17-7e-SCO\244aothAudioAgent_00-16-a4-00-17-7e-SCO\244adioAgent_00-16-a4-00-17-7e-SCO\244aent_00-16-a4-00-17-7e-SCO\244a00-16-a4-00-17-7e-SCO\244a6-a4-00-17-7e-SCO\244a00-17-7e-SCO\244a-7e-SCO\244aCO\244aOK!
aN\332a\332aOK!
a%aOK!
aaOK!
a.aOK!
aIOAudioControlType_IOAudioControlSubType_IOAudioControlChannelID_IOAudioControlValue_IOAudioControlChannelName_IOAudioLevelControlMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeaioControlType_IOAudioControlSubType_IOAudioControlChannelID_IOAudioControlValue_IOAudioControlChannelName_IOAudioLevelControlMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeatrolType_IOAudioControlSubType_IOAudioControlChannelID_IOAudioControlValue_IOAudioControlChannelName_IOAudioLevelControlMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeaype_IOAudioControlSubType_IOAudioControlChannelID_IOAudioControlValue_IOAudioControlChannelName_IOAudioLevelControlMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeaIOAudioControlSubType_IOAudioControlChannelID_IOAudioControlValue_IOAudioControlChannelName_IOAudioLevelControlMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeadioControlSubType_IOAudioControlChannelID_IOAudioControlValue_IOAudioControlChannelName_IOAudioLevelControlMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeantrolSubType_IOAudioControlChannelID_IOAudioControlValue_IOAudioControlChannelName_IOAudioLevelControlMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeaSubType_IOAudioControlChannelID_IOAudioControlValue_IOAudioControlChannelName_IOAudioLevelControlMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeaaIOAudioControlChannelID_IOAudioControlValue_IOAudioControlChannelName_IOAudioLevelControlMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeaioControlChannelID_IOAudioControlValue_IOAudioControlChannelName_IOAudioLevelControlMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeatrolChannelID_IOAudioControlValue_IOAudioControlChannelName_IOAudioLevelControlMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeahannelID_IOAudioControlValue_IOAudioControlChannelName_IOAudioLevelControlMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmealID_IOAudioControlValue_IOAudioControlChannelName_IOAudioLevelControlMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeaIOAudioControlValue_IOAudioControlChannelName_IOAudioLevelControlMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeadioControlValue_IOAudioControlChannelName_IOAudioLevelControlMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeantrolValue_IOAudioControlChannelName_IOAudioLevelControlMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeaValue_IOAudioControlChannelName_IOAudioLevelControlMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmea_IOAudioControlChannelName_IOAudioLevelControlMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeaAudioControlChannelName_IOAudioLevelControlMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeaControlChannelName_IOAudioLevelControlMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeaolChannelName_IOAudioLevelControlMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeannelName_IOAudioLevelControlMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeaaaaaaaaaaaaaaaame_IOAudioLevelControlMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeaIOAudioLevelControlMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeadioLevelControlMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeavelControlMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeantrolMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeaMaxDB_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmea_IOAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeaAudioLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeaLevelControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeaControlMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeaolMaxValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeaValue_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmea_IOAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeaAudioLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeaLevelControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeaControlMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeaolMinValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeaValue_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmea_IOAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeaAudioLevelControlMinDB_IOAudioControlUsagelevlvlmeaLevelControlMinDB_IOAudioControlUsagelevlvlmeaControlMinDB_IOAudioControlUsagelevlvlmeaolMinDB_IOAudioControlUsagelevlvlmeaaIOAudioControlUsagelevlvlmeaioControlUsagelevlvlmeatrolUsagelevlvlmeasagelevlvlmealevlvlmeavlmeaOK!
Ok, I'm pretty sure I found my problem. The data pointer that I copied over to a char * wasn't 0 terminated. I rewrote this:
const char *data_const = (const char *)event->u.data.dataPtr;
char *dataAsBytes = const_cast<char *>(data_const);
string in_s = (string)dataAsBytes;
To this:
const char *data_const = (const char *)data.dataPtr;
char *dataAsBytes = const_cast<char *>(data_const);
dataAsBytes[data.dataSize] = '\0';
printf("%s %i %i\n", dataAsBytes, data.dataSize);