postgresql pqxx notify_listener - getting notify payload - postgresql

Native interface postgresql provides the following command:NOTIFY channel [ , payload ], where payload is variable string. I use library pqxx for interaction with database. It provides notify_listener interface. The callback which executed as notification have just one parameter - id.
This is my code:
class notif : public pqxx::notify_listener {
public:
notif(pqxx::connection_base &conn, const std::string &table, std::shared_ptr<notify_processor_t> pr) :
pqxx::notify_listener(conn, table), _table(table), _pr(pr) {}
notif(pqxx::connection_base &conn, const std::string &table) :
pqxx::notify_listener(conn, table), _table(table) {}
virtual void operator()(int id)
{
std::cout << "notification " << _table << std::endl;
if (_pr.get())
_pr->operator()();
}
private:
std::shared_ptr<notify_processor_t> _pr;
std::string _table;
};
How I can get the payload content using pqxx interface provided?

Found the following in libpqxx 4.0.1 version:
// Obsolete notification receiver.
/** #deprecated Use notification_receiver instead.
*/
class PQXX_LIBEXPORT PQXX_NOVTABLE notify_listener
You should use notification receiver class instead of notify_listener

Related

How to create a notification class in vala

Im learning vala language and I want to create a service to trigger a notification.
Thats my code
public class Services.Notifications : Glib.Object {
public void sendNotification (string title, string body,string icon_name, GLib.NotificationPriority priority) {
var notification = new Notification (title);
notification.set_body (body);
notification.set_icon (new ThemedIcon (icon_name));
notification.set_priority (priority);
send_notification ("com.github.andirsun.myapp", notification);
}
}
But Im facing this error
class Notifications: null
base type `null' of class `Services.Notifications' is not an object type
I added the file Services/Notification.vala in the meson.build file bit no works
You have a typo in your base class's name - Glib.Object should be GLib.Object (note the upper-case L)

Pybind11 Virtual Child Class Method not being called during recursion, Base Called instead

I have a simple test case for polymorphism that isn't working quite right.. I have two C++ classes, Client and Dispatcher. The dispatcher has a method called "Dispatch" that takes a Client* as an input and calls the clients virtual ProcessEvent() method. I've made both of these classes available to python using the code below. I've derived from the Client class as the python class SomeClient and overridden its ProcessEvent function. When I call "Dispatch" from anywhere EXCEPT inside the SomeClient:: ProcessEvent method, everything works as expected, I get a report from the child class. But when I call Dispatch from within SomeClient:: ProcessEvent, the base classes ProcessEvent is called. Any ideas what could be going wrong here? I expect to get an infinite recursion that results in SomeClient:: ProcessEvent being called forever.
C++:
#include <iostream>
#include "pybind11/pybind11.h"
namespace py = pybind11;
class Dispatcher;
class Client
{
public:
Client(Dispatcher* disp): PtrD(disp)
{
std::cout << "In Client::Client\n";
}
virtual ~Client(){};
virtual void ProcessEvent()
{
std::cout << "THIS SHOULDN'T HAPPEN --In Client::ProcessEvent\n";
}
Dispatcher* PtrD;
};
class Dispatcher
{
public:
Dispatcher()
{
std::cout << "In Dispatcher::Dispatcher\n";
}
virtual ~Dispatcher(){};
void Dispatch(Client* client)
{
std::cout << "Dispatcher::Dispatch called by " << client << std::endl;
client->ProcessEvent();
}
};
class DispatcherTrampoline : public Dispatcher
{
public:
using Dispatcher::Dispatcher;
};
class ClientTrampoline : public Client
{
public:
using Client::Client;
void ProcessEvent() override
{
PYBIND11_OVERLOAD(void,Client,ProcessEvent,);
}
};
PYBIND11_MODULE(libTestCase,mod)
{
py::class_<Client,ClientTrampoline> cli(mod,"Client");
cli.def(py::init<Dispatcher* >());
cli.def("ProcessEvent",&Client::ProcessEvent);
cli.def_readwrite("PtrD",&Client::PtrD);
py::class_<Dispatcher,DispatcherTrampoline> dsp(mod,"Dispatcher");
dsp.def(py::init< >());
dsp.def("Dispatch",&Dispatcher::Dispatch);
}
Python Test:
from build.libTestCase import Client,Dispatcher
class SomeClient(Client):
def __init__(self,d):
print("In SomeClient::__init__")
super().__init__(d);
def ProcessEvent(self):
print("in SomeClient::ProcessEvent,about to call self.ProcessEvent")
self.PtrD.Dispatch(self);
if __name__ == "__main__":
dd = Dispatcher()
cl = SomeClient(dd)
dd.Dispatch(cl)
TERMINAL OUTPUT:
In Dispatcher::Dispatcher
In SomeClient::__init__
In Client::Client
Dispatcher::Dispatch called by 0x20bb270
in SomeClient::ProcessEvent,about to call self.ProcessEvent
Dispatcher::Dispatch called by 0x20bb270
THIS SHOULDN'T HAPPEN --In Client::ProcessEvent

Movesense: how to determine wbcmd port on mac os x

I've been digging around, but can't seem to find how to determine the proper port for a movesense device in the programming jig in order to use the wbcmd tool to query the device.
I've successfully used the jig to reflash devices, so that part is working. What I'm missing is how to determine the port option in wbcmd in order to successfully talk to the device on mac os X (currently: High Sierra).
I do see /dev/cu.usbserial-AIO4RYMP and /dev/tty.usbserial-AIO4RYMP, but using either of those as the --port option just returns "No device connected".
At this point, I am unsure if it's a wbcmd problem or a setup problem, but again, I can successfully flash a device with this setup on High Sierra no problem, and things look like they're configured correctly.
Thanks for any help
I'm not going deep into details of Mac serial ports but short rule is that /dev/tty.* is for incoming (like getty) and /dev/cu.* is for outgoing communication, so you should use the /dev/cu.* one.
Make sure you have defined SERIAL_COMMUNICATION(true) in your App.cpp and also note that enabling serial communication increases power usage of nRF52 by few milliamps.
EDIT: I stand corrected, looks like SERIAL_COMMUNICATION() -macro is deprecated in latest builds. Best way then is to use WB API system/settings/uarton -path and PUT true there. This setting is stored and needs to be done only once, and it takes effect on next reboot.
See Settings API YAML
Small sample code for application (UartClient.cpp):
#include "movesense.h"
#include "UartClient.hpp"
#include "system_settings/resources.h"
const char* const UartClient::LAUNCHABLE_NAME = "UART";
UartClient::UartClient()
: ResourceClient(WBDEBUG_NAME(__FUNCTION__), WB_EXEC_CTX_APPLICATION),
LaunchableModule(LAUNCHABLE_NAME, WB_EXEC_CTX_APPLICATION)
{
}
UartClient::~UartClient()
{
}
bool UartClient::initModule()
{
mModuleState = WB_RES::ModuleStateValues::INITIALIZED;
return true;
}
void UartClient::deinitModule()
{
mModuleState = WB_RES::ModuleStateValues::UNINITIALIZED;
}
bool UartClient::startModule()
{
mModuleState = WB_RES::ModuleStateValues::STARTED;
// Enable UART. Notice that the change takes effect on next reboot.
ResourceClient::asyncPut(WB_RES::LOCAL::SYSTEM_SETTINGS_UARTON(), AsyncRequestOptions::Empty, true);
return true;
}
void UartClient::stopModule()
{
mModuleState = WB_RES::ModuleStateValues::STOPPED;
}
Header (UartClient.hpp):
#pragma once
#include <whiteboard/LaunchableModule.h>
#include <whiteboard/ResourceClient.h>
class UartClient FINAL : private whiteboard::ResourceClient,
public whiteboard::LaunchableModule
{
public:
/** Name of this class. Used in StartupProvider list. */
static const char* const LAUNCHABLE_NAME;
UartClient();
~UartClient();
private:
/** #see whiteboard::ILaunchableModule::initModule */
virtual bool initModule() OVERRIDE;
/** #see whiteboard::ILaunchableModule::deinitModule */
virtual void deinitModule() OVERRIDE;
/** #see whiteboard::ILaunchableModule::startModule */
virtual bool startModule() OVERRIDE;
/** #see whiteboard::ILaunchableModule::stopModule */
virtual void stopModule() OVERRIDE;
};
Alternatively you can use the iOS sample application, there is an option to enable UART in UI. That change also takes effect on next reboot.

HoloLens Callbacks with Native Library

My goal is to call methods, which are implemented in the Unity Code, from my UWP DLL. (So I can use them in my HoloLens Project)
I tried this with a bigger project but failed. Therefore I wrote a simple example to make it easier to find the mistake and exclude other influences.
But still, I get the same error.
My Working Environment:
64-bit Computer with OS Windows 10
Micsrosoft Visual Studio Community
2015 Version 14.0.25431.01 Update 3
HoloLens Emulator 10.0.14393.0
Unity 5.5.0f3 Personal (64 bit)
Creating the UWP DLL:
To approach this I created a C++ DLL(Windows Universal) in Visual Studio 2015 as followed:
New Project > Visual C++ > Windows > Universal > DLL(Universal Windows)
After the project was auto generated I added my code.
So the code looks like this:
Native Library Code:
SimpleProjectDLL.cpp:
#include "pch.h"
#define DLL_EXPORT __declspec(dllexport)
typedef void(*CB_V)();
typedef void(*CB_V_VI)(const char * a, int b);
CB_V_VI cb_native_log;
CB_V cb_call;
void log()
{
// this method makes problems !
cb_native_log("Call for callback", 1);
}
extern "C" {
DLL_EXPORT void initInterfaceCallbacks(
CB_V_VI native_log,
CB_V call
) {
cb_native_log = native_log;
cb_call = call;
}
DLL_EXPORT void callSmth()
{
cb_call();
}
DLL_EXPORT int getSomeInt()
{
return 42;
}
DLL_EXPORT void initCallback()
{
log();
}
}
SimpleProjectDLL.h is prepearing the delegates:
SimpleProjectDLL.h:
#pragma once
#include <cstdint>
#define DLL_EXPORT __declspec(dllexport)
extern "C"
{
typedef void(*CB_V)();
typedef void(*CB_V_VI)(const char * a, int b);
}
I did not make any changes to the auto generated files dllmain.cpp, pch.cpp, pch.h or targetver.h.
Finally I build the project for "Release" mode and architecture "x86" to generate the DLL-file.
Location of the DLL-file is now: project-root-folder/Release/SimpleProject/SimpleProjectDLL.dll.
---------------------
Next step I created a new Unity Project added the HoloLens-Toolkit and made sure that the new project is running fine on the emulator.
Unity Project Code:
After that I added the SimpleProjectDLL.dll in the Asset-Folder and implemented the following code:
First of all we need to create the connection between the delegates.
Cpp.cs prepears the Delegates:
Cpp.cs
using UnityEngine;
using System;
using System.Runtime.InteropServices;
namespace Cpp
{
delegate void DelegateV();
delegate void DelegateVVi(IntPtr a, int b);
}
SimpleInterfaceCpp.cs initializes the connection:
SimpleInterfaceCpp.cs
using Cpp;
using System.Runtime.InteropServices;
using UnityEngine;
public static class SimpleInterfaceCpp
{
public static void Init()
{
initInterfaceCallbacks(
SimpleInterface.NativeLog,
SimpleInterface.Call
);
}
[DllImport(SimpleInterface.DLL)]
private static extern void initInterfaceCallbacks(
DelegateVVi native_log,
DelegateV call
);
}
Main:
MainController.cs
using UnityEngine;
using System.Collections;
using System.Runtime.InteropServices;
public class MainController : MonoBehaviour
{
void Start ()
{
SimpleInterfaceCpp.Init();
SimpleInterface.TestCalls();
}
}
SimpleInterface.cs is calling the methodes:
SimpleInterface.cs
using System;
using UnityEngine;
using System.Runtime.InteropServices;
using AOT;
using IntPtr = System.IntPtr;
using Cpp;
using StringReturn = System.IntPtr;
public class SimpleInterface
{
public const string DLL = "SimpleProjectDLL";
public static void TestCalls()
{
// This works fine
int number = getSomeInt();
Debug.Log("getSomeInt: " + number);
// This also works fine and outputs "--- A callback ---"
callSmth();
// This call gives the output "call_log: native log" but crashes afterwards !
initCallback();
}
[MonoPInvokeCallback(typeof(DelegateVVi))]
public static void NativeLog(IntPtr logMessage,
int logLevel)
{
string result = StringFromCReturn(logMessage);
UnityEngine.Debug.Log(result); // outputs "call_log: native log"
}
[MonoPInvokeCallback(typeof(DelegateV))]
public static void Call()
{
UnityEngine.Debug.Log("--- A callback---");
}
[DllImport(DLL)]
private static extern void initCallback();
[DllImport(DLL)]
private static extern void callSmth();
[DllImport(DLL)]
private static extern int getSomeInt();
public static string StringFromCReturn(StringReturn someReturnVal)
{
return Marshal.PtrToStringAnsi(someReturnVal);
}
}
Now if I create a SLN, open the project in Visual Studio and start it with the "HoloLens Emulator" I get the following Output:
getSomeInt: 42
(Filename: C:/buildslave/unity/build/artifacts/generated/Metro/runtime/DebugBindings.gen.cpp Line: 51)
--- A callback---
(Filename: C:/buildslave/unity/build/artifacts/generated/Metro/runtime/DebugBindings.gen.cpp Line: 51)
call_log: native log
(Filename: C:/buildslave/unity/build/artifacts/generated/Metro/runtime/DebugBindings.gen.cpp Line: 51)
The program '[1932] SimpleProject.exe' has exited with code -1073740791 (0xc0000409).
After that the App just closes.
So my Question is, does anyone know what the problem could be?
Is this the right way to use callbacks in a HoloLens Project?
Or does someone know how to find an error description for the code "-1073740791 (0xc0000409)" ?
Additional Information:
I also tried it on a real HoloLens device, same issue, so the problem does not lays at the emulator.
The error is STATUS_STACK_BUFFER_OVERRUN. The call destroyed callstack.
You have different declarations of callbacks in SimpleProjectDLL.cpp and SimpleProjectDLL.h. Cpp file uses "CPP" call conversation, header uses "C" call conversation.
You should change SimpleProjectDLL.cpp by removing
typedef void(*CB_V)();
typedef void(*CB_V_VI)(const char * a, int b);
and adding
#include "SimpleProjectDLL.h"

Rx undefined error while using signalR Hubs

I am trying to implement push notifications using signalR hubs. I have a sample code, which when I run, I get an error saying
JavaScript runtime error: 'Rx' is undefined
This error comes in the dynamic signalr/hubs file.
I have added all the necessary Javascript references i.e., jquery, signalR and signalr/hubs.
What am i missing ?
My code looks something like this:
Global.asax file has this
public class Global : System.Web.HttpApplication
{
protected void Application_Start(object sender, EventArgs e)
{
RouteTable.Routes.MapHubs("~/signalr");
}
My Hub is defined like this
[HubName("HealthCheck")]
public class MyConnectionClass : Hub
{
public static List<string> messages = new List<string>();
public void GetServiceState()
{
Clients.updateMessages(messages);
}
public void UpdateServiceState()
{
messages.Add(DateTime.Now.ToString("dd/MM/yyyy HH:mm:ss"));
Clients.updateMessages(messages);
}
And my client in javascript like this
$(function () {
// creates a proxy to the health check hub
var healthCheckHub = $.connection.healthCheck;
// handles the callback sent from the server
healthCheckHub.updateMessages = function (data) {
$("li").remove();
$.each(data, function () {
$('#messages').append('<li>' + this + '</li>');
});
};
$("#trigger").click(function () {
healthCheckHub.server.updateServiceState();
});
// Start the connection and request current state
$.connection.hub.start(function () {
healthCheckHub.server.getServiceState();
});
});
Also I have added all the necessary js references in the client.
I have picked this sample from here
Is this enough or am i missing something ?
Thanks
Given that the error is about Rx not being defined I'm wondering if you may have installed the wrong NuGet package. It sounds like you installed SignalR.Reactive instead.
I think this is the package you really want. (Note that this is a prerelease version and I think the package names changed quite recently so it's possible the tutorial you're following is slightly out of date, which may have been what's caused the confusion.)