socket.io why assert(false) - c++

I am developing a program in C++ to communicate over Socket.IO and I am referring the console example. At line 77-78 we have the following statements :
string user = data->get_map()["username"]->get_string();
string message = data->get_map()["message"]->get_string();
If I go to sio_message.h on line 101 we have definition of map method as given bellow. On line 103 their is an assert(false) statement which is causing my program to fail. Can anyone enlighten me why this assert(false) statement is present.
virtual std::map<std::string,message::ptr>& get_map()
{
assert(false); ///why this???
static std::map<std::string,message::ptr> s_empty_map;
s_empty_map.clear();
return s_empty_map;
}
My Code :
void Socket_IO::receive_listener(std::string const&name, sio::message::ptr const& data, bool hasAck, sio::message::list &ack_resp)
{
spdlog::info("Data Recieved : " + data->get_map()["message"]->get_string()); // I am getting an Socket.IO exception here
spdlog::info("Message Name : " + name);
}

Related

Azure IoT Edge C++ module not sending device to cloud telemetry

I have written an IoT Edge C++ module that is sending the event output using the following function call:
bool IoTEdgeClient::sendMessageAsync(std::string message)
{
bool retVal = false;
LOGGER_TRACE(IOT_CONNECTION_LOG, className + "::sendMessageAsync(...) START");
LOGGER_DEBUG(IOT_CONNECTION_LOG, className + "::sendMessageAsync(...) message : " << message);
Poco::Mutex::ScopedLock lock(_accessMutex);
MESSAGE_INSTANCE *messageInstance = CreateMessageInstance(message);
IOTHUB_CLIENT_RESULT clientResult = IoTHubModuleClient_LL_SendEventToOutputAsync(_iotHubModuleClientHandle, messageInstance->messageHandle, "output1", SendConfirmationCallback, messageInstance);
if (clientResult != IOTHUB_CLIENT_OK)
{
LOGGER_ERROR(IOT_CONNECTION_LOG, className + "::sendMessageAsync(...) ERROR : " << message << " Message id: " << messageInstance->messageTrackingId);
retVal = false;
}
else
{
retVal = true;
}
LOGGER_TRACE(IOT_CONNECTION_LOG, className + "::sendMessageAsync(...) END");
return retVal;
}
The result of the function call IoTHubModuleClient_LL_SendEventToOutputAsync is always coming as IOTHUB_CLIENT_OK. My module name is MicroServer and the route configured is:
FROM /messages/modules/MicroServer/outputs/output1 INTO $upstream
I do not see the SendConfirmationCallback function being called. Also, I do not see any device to cloud message appearing in the IoT hub. Any ideas why this is happening and how to fix it?
It turned out that I need to call this function atleast a couple of times per second
IoTHubModuleClient_LL_DoWork(_iotHubModuleClientHandle);
which I was not doing. As a result the code was not working properly. Once I started doing it. The code just worked.

How to print errors in lua script without running script?

I'm new using Lua in C++. I have some problem with printing error of script.
My purpose is :
Find errors of syntax, function name using luaL_dofile or luaL_dostring without running code like
build codes in Visual studio.
(When using luaL_loadfile or luaL_loadstring, it just find syntax error like 'a == 1', but can't find function name error like 'prit(a)')
Want to print all errors.(In lua, if there was 2 or more errors, it only prints error that was occurred first)
For example I made lua script like this :
test.lua
function sayHello(name)
print("Hello, " .. name .. "!")
end
for a=0, 10
print(a)
end
sayHello()
and in c++ code :
test.cpp
...
int ret;
ret = luaL_dofile(LuaState, filename);
if(ret != 0) {
cout << "error : " << lua_tostring(LuaState, -1) << endl;
lua_pop(LuaState, 1);
}
I want to print errors like :
lua: test.lua:2: attempt to concatenate local `name' (a nil value)
lua: test.lua:7: `do' expected near `print'
Could anybody teach me?

Invoking a method thtough C#

I am trying to get some data from the UWF_Volume WMI provider. Please see the following link,
https://msdn.microsoft.com/en-us/library/jj979756(v=winembedded.81).aspx
More specifically I am trying to get the exclusion files using the following class,
UInt32 GetExclusions([out, EmbeddedInstance("UWF_ExcludedFile")] string ExcludedFiles[]);
I am not familiar with out parameters but from a research I can understand that acts as a reference argument. So I wrote the following method,
public void getUWFExclusions()
{
{
string computer = ".";
ManagementScope scope = new ManagementScope(#"\\" + computer + #"\root\standardcimv2\embedded");
ManagementClass cls = new ManagementClass(scope.Path.Path, "UWF_Volume", null);
foreach (MethodData m in cls.Methods)
{
richTextBox1.AppendText("The class contains this method:" + m.Name + "\n");
}
ManagementBaseObject outParams;
foreach (ManagementObject mo in cls.GetInstances())
{
outParams = mo.InvokeMethod("GetExclusions", null, null);
richtextbox1.appendtext(string.format("ExcludedFiles" + mo[ExcludedFiles]));
}
}
catch (Exception e)
{
richTextBox1.AppendText(e.ToString());
}
}
The problem is that the line,
richtextbox1.appendtext(string.format("ExcludedFiles" + mo[ExcludedFiles]));
returns "Not Found"
I appreciate any help to debug this problem.
I guess you are missing the Object Query that actually gets data via call to WMI. I am not sure about windows 8 but till 7 we used to get data by WQL and that is not there in above code.

Adobe Air - native process communication with exe fails

I'm struggling with Adobe Air native process communication. I'd like to pass an c++ exe shellcommands stored at processArgs when started. The c++ program uses this arguments to choose device channel and symbolrate of an CAN-Bus-Adapter. The c program itself creates an json database for an html page. While the c program is processing i'd like to get some feedback of the program and if it exits adobe air should create a link for the html page with the function onExit. The c program uses standart output of iostream lib ("cout", "cerr") to send messages to adobe air.
Adobe Air script:
var process;
function launchProcess()
{
if(air.NativeProcess.isSupported)
{
setupAndLaunch();
}
else
{
air.Introspector.Console.log("NativeProcess not supported.");
}
}
function setupAndLaunch()
{
var cpp_device = $( "#device option:selected" ).val();
var cpp_channel= $("#channel option:selected").text();
var cpp_symbolRate= $("#symbolRate option:selected").val();
air.Introspector.Console.log("CHANNEL",cpp_channel);
air.Introspector.Console.log("Device",cpp_device);
air.Introspector.Console.log("Symbol Rate",cpp_symbolRate);
var nativeProcessStartupInfo = new air.NativeProcessStartupInfo();
var file = air.File.applicationDirectory.resolvePath("InteractiveDocumentation.exe");
nativeProcessStartupInfo.executable = file;
var processArgs = new air.Vector["<String>"]();
processArgs.push(cpp_device);
processArgs.push(cpp_channel);
processArgs.push(cpp_symbolRate);
nativeProcessStartupInfo.arguments = processArgs;
process = new air.NativeProcess();
process.start(nativeProcessStartupInfo);
process.addEventListener(air.ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
process.addEventListener(air.ProgressEvent.STANDARD_ERROR_DATA, onErrorData);
process.addEventListener(air.IOErrorEvent.STANDARD_OUTPUT_IO_ERROR, onIOError);
process.addEventListener(air.IOErrorEvent.STANDARD_ERROR_IO_ERROR, onIOError);
process.addEventListener(air.NativeProcessExitEvent.EXIT, onExit);
}
function onOutputData(event)
{
air.Introspector.Console.log("Got: ", process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable));
}
function onErrorData(event)
{
air.Introspector.Console.log("ERROR -", process.standardError.readUTFBytes(process.standardError.bytesAvailable));
}
function onExit(event)
{
air.Introspector.Console.log("Process exited with ",event.exitCode);
$("#output").html("Start");
}
function onIOError(event)
{
air.Introspector.Console.log(event.toString());
}
$(function()
{
$("#start").click(function()
{
air.Introspector.Console.log("START");
launchProcess();
});
});
the c program is quite long, and here i post only the main part
int main( int argc, char *argv[])
{
//! get shell commands for init
// echo shell commands
for( int count = 0; count < argc; count++ )
{
cout << " argv[" << count << "] "
<< argv[count];
}
// handle data
intDevice = (int)(argv[1][0] - '0');
intChannel = (int)(argv[2][0] - '0');
intChannel -= 1;
intSymbolRate = atoi(argv[3]);
//! class function calls
useDll CanFunction;
try
{
CanFunction.initProg();
CanFunction.ecuScan();
CanFunction.openSession();
CanFunction.readECU();
CanFunction.stopProg();
return 0;
}
//! exception handling
catch(int faultNumber)
{
....
}
}
First I used only the onExit listener and everything works fine. After I used start conditions adobe air only responses if i call no class functions except the CanFunction.initProg() and the onExit function was called but skipped the jQuery command to create the link. If I add the class function calls, the c program is called and the json database created but Adobe Air doesnt received any responses. The json database is still created. This confuses me.
My c program uses some *.dll files to communicate with the bus so i could imagine that it is a windows problem. But it is still weird.
Has anybody an idea why adobe air communication doesnt work with my c program if i call my class functions or why the jQuery command is skipped?
Or is there a better solution to call a c++ exe from adobe air?

QuickFix Login Failed due to password missing

I am using quickfix C++ implementation to connect to the FIX Server, everything is ok except when i tries to connect it says the field missing username. To correct this i added the following code to the toAdmin Method
void Application::toAdmin( FIX::Message& message, const FIX::SessionID& sessionID)
{
if (FIX::MsgType_Logon == message.getHeader().getField(FIX::FIELD::MsgType))
{
FIX44::Logon & logon_message = dynamic_cast<FIX44::Logon&>(message);
logon_message.setField(FIX::Username("username"));
logon_message.setField(FIX::Password("password"));
}
std::cout<<message.toString();
}
}
but is causes an exception. To check whether it is working or not also tried to print the message using std::cout<<message.ToString();
but nothing worked.
I think you were almost there. Here is my solution for initiating a FIX session with FXCM in C# (should be easy for you to port a C++ implementation).
1- Use the QuickFix Examples.TradeClient project.
2- Ensure your fix.cfg file is present in TradeClient/bin/Debug directory.
3- Ensure your dictionary (FIXFXCM10.XML) is present in TradeClient/bin/Debug directory.
4- Your main Program.cs should look something like this;
var settings = new QuickFix.SessionSettings("fix.cfg");
var client = new QuickFixClient();
var storeFactory = new QuickFix.FileStoreFactory(settings);
var logFactory = new QuickFix.ScreenLogFactory(settings);
var initiator = new QuickFix.Transport.SocketInitiator(client, storeFactory, settings, logFactory);
initiator.Start();
client.Run();
initiator.Stop();
and replace
public void ToAdmin(Message message, SessionID sessionID) {}
with this
public void ToAdmin(Message message, SessionID sessionID)
{
if (message.GetType() == typeof(QuickFix.FIX44.Logon))
{
message.SetField(new Username("YOUR_USERNAME"));
message.SetField(new Password("YOUR_PASSWORD"));
}
message.SetField(new QuickFix.Fields.Account("YOUR_ACCOUNT_NUMBER"));
}
FXCM require the account number (tag 1=) to be sent with every message to be valid. That could also prevent a successful logon if its not present.
Hope this helps!
This is how I added password:
void toAdmin( FIX::Message& message, const FIX::SessionID& sessionID)
{
// put password in the logon message
if (FIX::MsgType_Logon == message.getHeader().getField(FIX::FIELD::MsgType))
{
FIX::Password fixpasswd = ConfigSingleton::getInstance().CurrenexConfig.FIXPassword; //use your std::string password here.
message.getHeader().setField(FIX::Password(fixpasswd)); //also add username here.
}
}
If you can see your username and password, then it means ok already.
Regarding the exception, I also encountered before. For me, it comes from toApp function and I changed it as below and it works fine:
void toApp( FIX::Message& message, const FIX::SessionID& sessionID )
throw( FIX::DoNotSend )
{
try
{
FIX::PossDupFlag possDupFlag;
message.getHeader().getField( possDupFlag );
if ( possDupFlag ) throw FIX::DoNotSend();
}
catch ( FIX::FieldNotFound& e)
{
//std::cout << e.what() << " " << message.toString() << ENDLINE;
}
}
Actually, no exception.
BTW, if you didn't define your own function for some message types, the messages will be rejected.
Hope this will help.