Posts Tagged ‘OSGi’
Year In Review: Programming
Beginning of the year I embarked on a getting back in touch with my programming skills… and this year has been really successful. Here is what I accomplished, over the weekends and late nights:
· I programmed extensively in first of half on the year on IOS, especially IOS5 and iPad. I still need to work on my design skills but I covered a lot of ground Table Views & Controllers, Storyboards, Network Programming, XML parsing, Notifications, Pull To Refresh etc.).
· I refreshed my programming skills in Java by programming in OSGi Embedded environment…
· And to complete my journey – I signed up for courses with edX and Coursera on Cloud Programming. I would have liked to do a project or two of mine but I had to be satisfied with the assignments and the tests that were done as a part of the course. I ended up learning about R, Ruby and Rails. I had signed up for a few courses but the three that I completed were:
o CS169.1x Software As A Service @ edX
o CS169.2x Software As A Service @ edX
o Computing for Data Analysis @ Coursera [Data Analysis using R]
SSDP Service using Java/OSGi [Part 3, ROM]
The SSDP service runs as a thread when the OSGi bundle is installed and started – “AdvertiseServiceSSDP()”. [The call before that – SocksServer is the class that implements the network interface between the IOS app & the Plug Computer as explained in the project overview.
public void start(BundleContext bc) throws Exception {
this.bc = bc;
nServer = new SocksServer(bc);
advtROMService = new AdvertiseServiceSSDP(bc);
}
Here is the SSDP code:
public void run() {
String msg = "LISTEN-FOR=THIS MESSAGE";
String chkResponse = "RESPOND-WITH-THIS-MESSAGE";
try {
int port = 1900;
InetAddress listenSSDP = InetAddress.getByName("239.255.255.250");
MulticastSocket ms = new MulticastSocket(port); // Create socket
ms.joinGroup(listenSSDP);
System.out.println("\n Rcvr started, Ready to Receive... \n");
boolean match = false;
do {
byte[] response = new byte[256];
DatagramPacket rspPkt = new DatagramPacket(response, response.length);
ms.receive(rspPkt);
//System.out.println("\n Done Receiving!\n");
String getResponse;
getResponse = new String(rspPkt.getData());
match = getResponse.regionMatches(0, msg, 0, msg.length());
if (match)
{
System.out.println("Controller found\n");
// Send Response
InetAddress IPAddress = rspPkt.getAddress();
byte[] sendData = new byte[1024];
String sendResponse = chkResponse;
sendResponse += IPAddress.getHostName();
sendResponse += "/:portAddr";
System.out.println(sendResponse);
sendData = sendResponse.getBytes();
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 1900);
ms.send(sendPacket);
System.out.println("Response Sent");
match = false;
}
} while(match==false);
} catch(Exception ignore) {
System.out.println(ignore.getMessage());
}
}
The above code when running on the Plug Computer(s) allows the IOS app to discover them. Of course the beauty is that this will work for all devices that support OSGi/JVM and have multicast networking support.
SSDP Service/Device Discovery [Part 2, ROM]
//// serviceSSDP.h// SimpleSSDPDiscovery//// Created by Ashu Joshi on 3/1/12.// Copyright (c) 2012 Movinture, LLC. All rights reserved.//
#import <Foundation/Foundation.h>#import “AsyncUdpSocket.h”#import “connectedLifeController.h”
@interface serviceSSDP : NSObject
// This is the string that is Multicast to Discover the Controller@property (strong, nonatomic) NSString *discoverControllerString;// The Controller would respond with the string below upon discovery being received@property (strong, nonatomic) NSString *responseStringFromController;// The list of discovered controllers@property (strong, nonatomic) NSMutableArray *controllerList;
@property (strong, nonatomic) connectedLifeController *currentController;
@property (strong, nonatomic) AsyncUdpSocket *ssdpSocket;
– (BOOL)startControllerDiscoveryProcess;
– (BOOL)startControllerDiscoveryProcess:(NSMutableArray *)listOfControllers;@end
Getting Started: IOS-based OSGi Application Manager
I am going to provide more details on the project that I have in of the earlier posts. The objective of the project is to build a network interface between an iOS application & a device running OSGi (it could be any device running OSGi since that lends to portability but I am going to start with a Plug Computer). And using that network interface/protocol the IOS/iPad application would function as a “Remote Manager” to the Plug Computer. Obviously all code on the Plug that interacts with the iOS/iPad app would be developed in OSGi/JVM.
I had started doing some preliminary design work and thinking through in late January, and to prepare spent last two weeks of December (2011) getting my coding skills comfortable with both Java & iOS/Objective-C. The approach was to build the project incrementally, baby steps at a time. The key was to define the network protocol/interface between the iOS App & Plug. The interface by itself was very simple but I had to decide what it would do and more importantly in the first iteration what it won’t do.
Here is a simple diagram illustrating the protocol/interface, and I had decided to use a Sockets Interface between the iOS and Plug. The Plug and the iPad are both on the same network/subnet.
Using sockets was my first decision – in my next iteration I would move to a REST API between the two. I can comfortably say 3 months into it that the design & implementation is flexible enough where my “network interface” code on both sides is separate from the actual command processing. The next couple of decisions were also what not to take on in the first round of implementation – no TLS/SSL sockets and no authentication. I would take that on once I have the entire interface working. In addition there is no authentication or provisioning for the iPad/iOS app – that is – I have not built in any authorization check before the iOS/iPad app would be allowed to access the OSGi information on the Plug computers.