Raspberry Pi watchdogging C++ program - c++

I have C++ app is running on my device which is a bit modified version of Raspberry PI. Application is reading data from a serial port and I need a device to reboot after some particular data is received. I've been wondering about integrating this functionality with watchdog but have no idea how to do it. Maybe there is a possibility to send some signal from my app to watchdog to tell that it's time to reboot?
P.S. Application starts as systemd service.

Call
std::system("sudo reboot");

Why would you do this that way? The reason one uses watchdogs is exactly what Marco described. If a system does not respond the watchdog triggers. Typically this is needed because devices that are lets say turned off do not send anything anymore, therefore you need some kind of trigger to let your system know it should reboot. Here you already get your trigger from the incoming signal therefore the watchdog is redundand. Simply reboot after you have received your data.

Watchdog is great if you want your device to reboot autonomously when your software blocks or Is not reachable anymore
If that is what you want to achieve watchdog is the right choice.

Related

In QNX, how to manage IPC connections between server and client?

Originally I titled the question as "In QNX, what is the difference between _PULSE_CODE_DISCONNECT and _PULSE_CODE_COIDDEATH?". However, I think my question is a little broader than that.
I have implemented an IPC server using the QNX Neutrino OS 6.6.0. Essentially I have a server that is queried for configuration information like settings and stuff. It also accepts changes to settings. It allows for clients to subscribe to it. This means that once subscribed, if a change happens to a setting, the server will notify those other clients.
So far so good. This stuff up to this point makes sense to me. What is not clear to me is the appropriate way to handle a client disconnecting or a process dying.
Right now, I'm receiving a _PULSE_CODE_DISCONNECT on my server. What exactly does that mean? I'm not receiving a _PULSE_CODE_COIDDEATH, which is what I was expecting.
I think in particular I'm a little confused on what a coid vs a scoid is in QNX.
Receiving _PULSE_CODE_COIDDEATH is dependent upon the flags you set when creating the channel. To get that pulse you need to set the channel flag _NTO_CHF_COID_DISCONNECT.
The _PULSE_CODE_DISCONNECT relates to the channel flag _NTO_CHF_DISCONNECT, to receive the pulse when all connections are detached.
See the documentation for the ChannelCreate:
http://www.qnx.com/developers/docs/6.6.0_anm11_wf10/index.html#com.qnx.doc.neutrino.lib_ref/topic/c/channelcreate.html
A coid is a connection id given to you when you connect to a channel via ConnectAttach.
scoid is a server connection id (assigned internally) which you get in the pulse you are talking about. In the message receive and reply context it is for the kernel to route the reply to the client.
Also, my understanding is that if you get the _PULSE_CODE_COIDDEATH you need to cleanup by calling ConnectDetach(scoid) where scoid is from the pulse.

Is it possible to listen for an event from an app, from outside of that app

I need to listen for touch events from a specific app(in blackberry 10 os). I am planning to write another app which does this. Is this possible?
APP A- the app which exists
APP B- The app i am going to write
what sort of modification do i need to do for the APPA to make this possible.
In the Cascades environment touch events are passed as SIGNALS which are received by SLOTS. This message passing implementation is bound to the threading model and does not have a direct inter process counterpart. Theoretically you could implement something on top of the QNX message passing system, or on top of BlackBerry Platform Services (BPS). This might be necessary if you need the kind of performance available within a single application.
The other option is to use the invokation API that BlackBerry provides in Cascades. This is a very flexible inter-process communications protocol but is inherently synchronous. Normally UI focus moves from the invoking process to the invoked process, this does not sound like what you want. The invoked process can return immediately after receiving the invokation and before posting any UI elements, but there is still the overhead of launching the invoked process, at least in the first instance, and context switching in other instances.
It might be more fruitful to be more specific about what you are really trying to accomplish.
I would start looking at Starting a process if you haven't all-ready.
Probably NOT !
Your app can only listen to touch events in your app and cannot spy on other apps.
Not possible. This would be a major security flaw...

Windows CE centralized message queue between processes

Setup: 4 processes need to monitor a centralized source (I am thinking Message Queue) and be alerted when a message is put into the queue. This is for reporting errors that each process needs to know about to decide what they individually will do about it.
I have a few questions however, since I want to make sure Message Queues are the best way to go about it before I venture to far down that road.
Does the Message Queue API on Windows CE have events/notifications of some sort? If not, does the Windows CE OS itself allow you to tie in to the queue somehow for alerts of new messages arriving? Is there a better Inter Process communication tool for this kind of setup and requirements?
EDIT: Also, this will be a running log of errors that cant be lost, so I will put it on my flash memory.
What always works is a simple TCP connection via loopback. This also makes it easy to debug on a desktop system, in case you want. Concerning CE's message queues, those are always 1:1, so you'd need as many as you have connections between processes. Also, if you want to use them in a TCP stream-like manner, you'll need one for each direction.
There is another way you could use, and that is to monitor the file that you're logging the info to. I'm not sure to what extent CE supports a notification API for file changes, but if you don't need low-latency reactions, you can always poll every now-and-then. Alternatively, use a named event after writing to the logfile.

Simple online game servers monitor

I want to make a tool that runs on win32 to monitor our online game servers. The servers actually are .exe files. I need to know whether they have crashed so I can restart them. Therefore, the tool will have 2 main features:
Frequently check a list of the server programs to see whether they are running or not
Reopen the executable of any server that has crashed
Does anyone have any idea or knows an API to start with?
If you're in Win32, you can start out with C# using System.Diagnostics
using System.Diagnostics;
Then get a process list:
Process[] processlist = Process.GetProcesses();
foreach(Process theprocess in processlist){
Console.WriteLine(“Process: {0} ID: {1}”, theprocess.ProcessName, theprocess.Id);
}
And from there it's up to you what you want to do with the info.
Game servers should produce logs. You should make a service / cron job to monitor the logs. Depends on the contents of logs, your service should act respective actions, e.g. restart service, trigger alarms, etc.
I realize that this is not exactly what you asked for, but what about doing the monitoring with a fully-fledged monitoring tool such as Nagios? You would of course have to "teach" the monitoring tool about the processes that shall be monitored but you would also profit from its more advanced functions. In the case of Nagios, for example, these would comprise automatic e-mail notifications, an online dashboard of process status, notifications via SMS etc.
You should start the game servers using CreateProcess or similar in the win32 api.
You will get back a process handle in the lpProcessInformation parameter.
You can use WaitForSingleObject to WaitForMultipleObjects to wait until that handle is notified which will happen when the process terminates for any reason.

How can I Execute a Function when Windows Shut down

How Can I execute a function when Windows shutdown. Here is my scenario, I am mounting a drive using WNetAddConnection2 function in my application. Now I want user to set the option if the drive will be mounted on next system startup or not.
If he selects , not to mount on next startup , then I need to remove the drive using WNetCancelConnection2 , but this should only happen when user shutdown the system.
I can only think of only solution. Create a service which will check the user option and then decide whether to mount the drive or not.
Are there any other ways to go ahead with it?
If you have a main window (even an invisible one) that can process messages, you can handle the WM_ENDSESSION message.
See: http://msdn.microsoft.com/en-us/library/aa376889(v=VS.85).aspx
If you can make your app into a Windows service (or have your app communicate state with one that you provide) you can perform required actions on receipt of SERVICE_CONTROL_SHUTDOWN in your service control handler function. This would decouple your app that handles user interaction from the shutdown handling, which requires something to be running all the time (what if the user logs off?).
explorer.exe is the GUI process of windows which usually only gets shut down if Windows shuts down (exceptions have to be made for certain error conditions). You could listen on the WM_DESTROY window message for the process ID of explorer.exe and dismount then.
The way I can think of is to:
Register your program to auto Start up (when PC starts). Here's a tutorial on howto.
Store the user option (as mentioned above) in a repository or registry (if you know how). When your app would have started, you can read your registry and act accordingly.
For shutdown, your application will have to hook itself on a SystemEvent to detect shutdown (then you can act accordingly). Here's an example on howto (C#). For C++, you can listen to WM_ENDSESSION message.
I hope that my 2 cents can help you.