Sunday, April 20, 2014

Objective C pre-processor macros

Below is a list of pre-processor macros available in objective C.

__func__ => prints the current function signature
__LINE__ => prints the line number in the source code file
__FILE__ => path source to the source file
__PRETTY_FUNCTION__ is similar to __func__ but just that it is a gcc extension that prints the "pretty" name of the function including its signature. Used in C++.

When running the same in iOS code, it appears the __func__ and the __PRETTTY_FUNCTION__ give the same result

references:
https://developer.apple.com/library/ios/qa/qa1669/_index.html



Saturday, April 19, 2014

SIPp tool - installing on Windows

SIPp is a tool that can be used for testing the SIP scenarios by simulating it. The download page is at
http://sourceforge.net/projects/sipp/files/sipp/3.4/ as of this writing the latest version is 3.4

SIPp tool is mainly for Linux and Cygwin. Those who dont have a Linux machine, can install the Cygwin and configure the SIPp tool. SIPp on windows as per the sourceforge site, will work on WindowsXP and not on Windows 2000 due to IPV6 support.

There is a utility called SippGuiSetup.exe, but this is not really a GUI tool to simulate the test cases, but just a tool to prepare the call flows.

The detailed instructions for testing this is available at http://sipp.sourceforge.net/doc/reference.html
This notes are from my attempt to install on my Windows XP machine.

Step 1: Download Cygwin.
The download link is available at SIPp page which is http://win6.jp/Cygwin/
The version downloaded was, WpdPack_4_1_2

- Downloaded the zip file at this location and it contained bin, usr, lib files inside
- Download the WinPcap developer pack and copy to c:\cygwin\lib\WpdPack. The instructions page asked to rename the pthread.h file inside the c:\cygwin\lib\WpdPack\include , but this file was not available in the cygwin that i downloaded.

It appears that the Cygwin installation is not correct and it was not able to get to the Cygwin command line.

Tried searching again and found a link to directly install the Cygwin as an exe. The link is available here.

The cygwin installation was successful, and tried to execute the cygwin using the command prompt as well as given in the reference. However, this was getting a failure.

This needs to be tried again!

references:

http://sipp.sourceforge.net/
http://sipp.sourceforge.net/doc/reference.html

Thursday, April 17, 2014

Sip Stack - REGISTER analysis

SalOp is the main structure passed around in various classes. When linphone_proxy_config_register is called, it is creating a new SalOp using sal_op_new function and the SalOp's userdata pointer is set to the LPConfig object

The refresher, transaction is two main portions of the core. For every request, a transaction is created and a refresher is created with this transaction. For specific functionalities, there are specific c files. For example, for registration, the file is sal_op_register.c, this file is mainly for doing the register related header addition, set from, to, contact, route headers, builds the request using sal_op_build_request, and finally calls the sal_op_impl.c file to send and create the request. sal_op_impl.c calls the transaction api to create a transaction and it in turn creates a refresher as well. When it asks the sal_op_impl.c to create a transaction and register, it sends a function pointer as the listener inorder to get the call backs.

The sal_op_impl.c also sets a default retry timer of 1 minute that kicks in when the request is not able to be sent out. also, it has a manual mode refresher. This is mainly to decide whether the refresh should be done by the library or by the app when the expiration of the refresher timer happens.

Below is the websequence diagram notes for the REGISTER sending part

lpcore -> proxy.c : lp_proxy_config_register(true)
proxy.c -> sal_op_registration.c : sal_register
sal_op_registration.c -> sal_op_impl.c : sal_op_send_and_create_refresher
sal_op_impl.c -> sal_op_impl.c : sal_op_send_request_with_expires
sal_op_impl.c -> transaction.c : belle_sip_client_transaction_create_refresher
transaction.c -> refresher.c : belle_sip_refresher_new

In another Blog, the details of processing of the incoming SIP message will be analyzed


Wednesday, April 16, 2014

Unit testing iOS code - SenTesting framework

Apple gives definition of unit testing as a way to ensure that the code you write adhere to the design specifications and it keep adhering to the specifications as you modify it. To me, it is almost the same and also making sure the code is without lot of bugs especially around the area those are rarely tested or executed in real world.

Xcode gives a way to include Unit test bundles. These bundles contain methods that exercise the code in a library or app to perform unit testing.

There are main three portions to it.

1. Setting up unit testing in a project
2. Writing test case methods
3. Running unit tests

Setting up the unit testing is pretty straight forward. on the project window add a new target and select the type as Other -> Cocoa Touch Unit Testing Bundle. Give the target name. In the new versions of XCode, am using the XCode 5.0 it asks for the Type of the Unit testing. The drop down has two options 1, OCUnit (Xcode 4 compatible) 2, XCTest

Selecting the OCUnit makes the SenTestingKit framework a required library to be added. This time selected the OCUnit as the XCTests is comparatively newer approach that also integrates with the Continuous Integration feature available in XCode 5.0.

Adding a new Unit Testing Target includes a set of source files which is containing one function testExample and other two life cycle functions setUp, tearDown.

Below are the instructions before running the tests which i had to do to get this working.

- In the build settings pane, search for bundle loader and test host and test host. If these are highlighted, which means these are having some values, then delete them so that they become unhighlighted. from Products -> Run, run the tests.  This was going through the setUp , testExample, tearDown methods in order and since the testExample had statement STFail, the test was declared to be failure.

Next review of this framework, i think mainly the below will be interesting

- How to write more test methods
- how to do testing that involves server responses
- How to do testing of screen flow
- How to run some test at some point of execution in the app midway.

This below article gives Good explanation of the entire setup
https://developer.apple.com/legacy/library/documentation/DeveloperTools/Conceptual/UnitTesting/02-Setting_Up_Unit_Tests_in_a_Project/setting_up.html#//apple_ref/doc/uid/TP40002143-CH3-SW1



Tuesday, April 15, 2014

iBeacon Hands On - Transmitter & Scanner Part

Finally decided to implement the details acquired into an app.

There are two parts for this app. One, Beacon Tranmittor and next part is Beacon Monitor.

- Created a Single View application
- included CoreLocation, CoreBluetooth frameworks to it.
- Created a class BeaconTransmitter
- Created CLBeaconRegion object to create the beacon region for transmission
- Created a NSDictionary to hold the peripheral properties of this beacon
- Created a CBPeripheralManager instance to create get the delegates for peripheral start and stop. This is used for start and stop of advertising respectively.

Implemented the CBPeripheralManagerDelegate to get the peripheral updates. in the peripheral update when the event is CBPeripheralManagerStatePoweredOn, startAdvertising the beacon using peripheral manager startAdvertising api by passing the beacon properties dictionary.  Similarly, when the state is powered off, we should stop the advertising.


For the Beacon Monitoring part, the main two classes required are

. CLLocationManager
- CLBeaconRegion

first need to create an instance of CLLocationManager and set the delegate and override the didEnterRegion and didExitRegion methods mainly. We also need to initiate the CLBeaconRegion object and give the uuid as the known uuid of the beacon . say for e,g. the uuid given in the above trasmitting part. also the same identifier can be given as well. to start monitoring for region, core location manager instance created has a method startMonitoringForRegion. When the didEnterRegion is called back, the code can search for ranging the beacon with the given identifiers specificatlly using startRangingBeaconsInRegion. Similarly when the didExitRegion is called back, code can stop ranging the beacons. When the specific beacon is ranged, the didRangeBeacons method will be called back. We get a set of beacons in this call back and one can decide based on number of factors such as proximity, rssi strength etc.

Below is my observation on the whole application

- If the transmitter is a phone, when the screen locks up, the device which is monitoring for this transmitter receives didExitRegion callback. This makes the app to be available always in foreground. This is kind of a restriction. But assuming in the realworld, it may be some other device that is acting as a transmitter

- When the call back didRangeBeacon comes into the app, it keeps coming. But if kill the app and launch again, even though other transmitter is still transmitting, the didRangeBeacon doesnt come to the app.





Sunday, April 13, 2014

SOAP frameworks for iOS

gSoap is a SOAP framework built on C++. This is available on multiple platforms such as Windows, MAC, WINCE, Symbian, Palm OS. This framework is open source for non commercial use. This is licensed under GPLv2. This toolkit follows WS-I Basic Profile 1.0a, 1.1, 1.2 recommendations. 

This framework supports SOAP 1.1/1.2, WSDL 1.1/1.2, UDDI v2.0 WS Policy 1.2/1.5, WS Security Policy 1.5, WS-Reliable Messaging, WS-Addressing, Supports XML schema primitive XSD types, simple types, complex types, extension, restriction elements, attributes, elements/attribute references etc. 

A good amount of documentation on this can be found at http://www.cs.fsu.edu/~engelen/soap.html

Other frameworks are: 

http://code.google.com/p/wsdl2objc -
http://sudzc.com 
http://www.cs.fsu.edu/~engelen/soap.html -

MotionManager, Augmented Reality framework a quick look


Magneto meter.
CMMotoionManager : is the iOS framework to get the motion services provided by the iOS. This services provides app with accelerometer data, rotation-rate data, magnatometer data and other device motion data such as attitude.  The framework supports accessing both raw and processed accelerometer data using block based interfaces. For devices with built in gyro scope, one can retrieve the gyro data as well and process data reflecting attittude and rotation rates of device. One can use both the accelerometer and gyro based data for games or other apps that use motion as input or as a way to enhance overall user experience.

references: https://www.inkling.com/read/learning-ios-programming-alasdair-allan-2nd/chapter-9/the-core-motion-framework

Augmented Reality Framework : 
Augmented reality is a cool and popular technique where you view the world through device you like, say camera of an iPhone or google glass and overlay extra info about those places on top of the real world view.  

The question of why we need this framework irrespective of Map frameworks, is that when we need to find where to place the overlay on the screen for a POI. for e.g. If we have a POI on the north side of you and the device is pointing to the north east, the question is where to show the POI. towards the left or to the center. It all depends on the current position of the device. If the device is sligthly towards the ground, the POI should be shown at the top. If it is pointing to the south, the POI should not be shown at all. The ARKit uses the device's gyroscope and the compass to find out where the device is pointing and the degree of tilt. Using this info it decides where and whether the POI should be shown. 

references: http://www.raywenderlich.com/42266/augmented-reality-ios-tutorial-location-based