How to hook the service control handler from a Topshelf service - topshelf

I have an existing Windows service that uses Topshelf very successfully.
I now need to have the service receive notifications when specific USB devices are connected / disconnected to / from the machine.
I can't see anything in Topshelf that would allow me to do this. But I believe that there is a way to do it using Win32 APIs like ServiceControlHandlerEx and RegisterDeviceNotification with the DEVICE_NOTIFY_SERVICE_HANDLE option.
Will using these Win32 APIs interfere with Topshelf? As I understand it, Topshelf wraps the service control handler itself so my service also trying to do the same thing may cause it some problems?
Update:
It is possible to hook device notifications from the service control handler within a Topshelf based service. See sample project for details. Many thanks to Chris Patterson for his help.

Topshelf won't interfere with you calling these Win32 APIs.

Related

Sonos control api: polling rate & subscription

We are controlling the sonos via a small IOT device. This device will be placed at the homes of our customers.
In our home automation system we need to know the playbackstate + volume of the players/groups.
At which polling rate can we ask these parameters ?
We cannot use a cloud server to handle the subscription events.
I tried to put a https webservice in the IOT device with a self signed certificate but this doesn't work.
After I have posted the subscription I get a request in my webservice but the cloud sonos server disconnects immediately.
Probably because of the certificate is self signed - Or can there be another reason ?
Is there another way to recieve status events ?
During discovery In the players Json object there is a key 'websocketUrl'.
The documentation says "The secure WebSocket URL for the device. See Connect for details".
But I cannot find more info about this.
Can this be used ?
At which polling rate can we ask these parameters?
Consider using subscriptions instead of polling. See this answer for more: https://stackoverflow.com/a/60893119/4902948
We cannot use a cloud server to handle the subscription events...
Or can there be another reason?
Is there another way to [receive] status events?
You must host a service that satisfies a set of requirements to receive events. See this answer for more: https://stackoverflow.com/a/57189717/4902948
Also see Details on API credentials and events in New features in versions 11.1, 11.2 (S1), & 12.0 (S2).
Can [the 'websocketUrl'] be used?
This is not publicly available for use.
It would be a lot easier to use the (undocumented but more useful) UPnP APIs. You could simply Subscribe to the UPnP RenderingControl endpoint, then you will get an event every time the volume changes. To find when the track changes, subscribe to AVTransport endpoint.
You can do this with a local server (this is how every Sonos app works after all) and no special cert requirements either.
UPnP events are described in the UPnP spec.
Your question doesn't provide details about the language you're using, but if the device is powerfull enough to run node, you have a good change with my sonos library.
You can just pull the required information from the device as often as you like. Or use the build-in event subscriptions. If you use the events, it will automatically setup an http listener and automatically subscribe to all the events you're listening for.
Events are instant (as in 50ms-100ms after the event took place on the device).
If you request information it is send directly to the device and the device will respond with the answer. Pulling multiple data points per second has never been a problem to me.
Warning as stated above, this uses the undocumented local UPNP api, but since their own app also uses it, I'm guessing that won't change soon.

Intercept USSD events on Windows Phone 7

Windows phone7 does not support phase 2 communication using USSD. Is there a way to intercept an outgoing USSD request on a Windows Phone 7 device in order to route to an application to handle the request instead?
The APIs for such low level operations --- even more so when they are related to the cellular interface --- are not available.
If we take into account that more innocent things are not allowed in WP7, I think that the USSD interception has little chance of being available in the future...
Only Microsoft Partners or OEMs have access to native API which is basically something much like Windows CE/Windows Mobile. There are functions that can receive USSD but none that can prevent default handling of the messages (namely: displaying popup with the message).

Push Notification Server in Java

Microsoft describes a method to create a push notification service in C#.
But I rather want to run a Java service for this is that possible at all?
Absolutely. It's just a matter of making an HTTP/HTTPS request to Microsoft. MSDN shows the headers and payloads to be sent.

How to setup a SMS Gateway on Windows 7 and test with .NET

My company is working for a Telco who will allow us to send/receive sms using their gateway eventually but for now I need a sms gateway setup on my Win7 box that I can used to test and build an applicaton that sends and optionally receive sms messages.
I have had a look at Kannel but I cant seem to find a Win7 version or dont know how to compile and setup one on Win7.
If someone has any experience in this then please help me. Thanks
If you will be connecting to the telco it will probably be to their SMSC directly via SMPP or similar protocols, which means you will need to setup something to talk to that. Kannel is an excellent open source implementation of an SMS Gateway, and probably your best bet at this. It will take care of talking with the telco's SMSC, and will provide you with a simple HTTP based interface to submit messages to from your application.
In that case, you are better off trying to set it up sooner rather than later, because quite a bit is involved in Kannel's configuration. It requires linux based systems to run and there is no windows port.
However, in order to get started developing your application, you can look into a fake SMS Gateway that will accept the same HTTP interface as Kannel, and return back made up replies. A quick and dirty way would be to write a simple web page in any language you wish, that will accept a few parameters over a web request and print out "55124" for the new message id, or similar. Then your application can do a simple HTTP call to it to simulate sending an sms:
http://smsgateway.local/simulator.php?to=12345678&from=12345&body=hello+there
If you want something more realistic look at this list of software. There are some libraries for sending sms via mobile phone connected serially, and SMPPSim which looks like it could work for you for this.

Cisco IP Phone Call Manager handle events

I'm new on cisco IP Phones.
I have a cisco call manager system also a 7970 Ip phone.
The phone cominicates with Cisco Call Manager application.
I want to listen events when user logon and send some commands to phone.,
Is there any idea about this task?
Is there a way to got events from cisco call manager or I have to listen up the ports of IP phone?
Cisco JTAPI is the best API to perform 3rd party call control and get events about IP phone state. You'll write an application in Java that uses the Cisco JTAPI jar. This api will let you subscribe to a specific phone and you'll be able to get events like OnHook, OffHook, Connected, Disconnected, etc.
JTAPI is fairly complicated. Cisco has a product called Cisco Unified Application Environment that can help simplify the development task. It isn't free, however.
Is the phone registered as SIP phone or SCCP phone .
Traces from the call manager are the best way of finding out what is happening in the sytem.
You can also look for packet captures on the phone in those captures you can see SCCP events and SIP events
for example you can see events like
SIP INVITE , OK , BYE..etc.
apart from this call manager traces SDI and SDL traces for "call manager service" will give you whole lot of information you need.
This link will help you take traces in call manager:
http://www.cisco.com/en/US/products/sw/voicesw/ps556/products_tech_note09186a0080094e89.shtml

Resources