Thursday, June 5, 2008

How to build ruby OpenAMQ extension

Building ruby extension of OpenAMQ is bit painful. I have wrote step by step guide to build ruby extension. Please refer the following URL : http://wiki.openamq.org/addon:ruby-extension/comments/show

Tuesday, April 8, 2008

Shutdown hook for C++

Shutdown hook is not a strange for Java people. It's there since JDK 1.3 . But for the C++ I couldn't found similar function. I wrote a simple program to demonstrate the some features of shutdown hook using available function in c++. I think C++ library is rich enough to write a complete shutdown hook. But indeed it bit hard when compare to Java.

When you hit the Ctrl+c following program will call “fnBeforeExit” function before the system get shut.
If you wish you can try this program by replacing never ending loop with “exit(0)”.

//
// File: Newmain.cc
// Author: eranga
//
// Created on April 8, 2008, 3:52 PM
//

#include < stdio.h>
#include < stdlib.h>
#include < iostream>
#include < csignal>

//
// Shut down hook for C++
//

//Shut down function done all the cleanups
void fnBeforeExit(void) {
puts("Exit function calls.");
puts("Do connection close, filde descriptor close...etc in here.");
}

//Function to call when interactive attention signal recieved
//Generally generated by the application user.
void sigint_handler(int sig) {
std::cout << "Exit call ( Ctrl + C ) " << sig << "\n";
exit(0);
}

int main(int argc, char** argv) {

/*
* The function pointed by the function pointer argument is called when the program terminates normally.
* If more than one atexit function has been
* specified by different calls to this function,
* they are all executed in reverse order as a stack,
* i.e. the last function specified is the first to be executed at exit.
* One single function can be registered to be executed at exit more than once.
* C++ implementations are required to support the registration of at least 32 atexit functions.
*/
atexit(fnBeforeExit);

std :: cout << "Program started....." << std::endl;

/*
* Specifies a way to handle signals
* SIGINT - (Signal Interrupt) Interactive attention signal. Generally generated by the application user.
*/
signal(SIGINT, sigint_handler);

while(true){

}

return (EXIT_SUCCESS);
}

Saturday, March 15, 2008

Quickfix support for FIX 5.0

Still I couldn’t see progressive communication about FIX 5.0 protocol support for Quickfix engine. Some of the user raise this question few times back in the developer mailing list, but still can’t see the green light. The current release of Quickfix 1.12.4 is pretty stable and according to Oren Quickfix willing to support FIX 5.0 near future.

Sunday, January 13, 2008

Long MAX in C++

Yesterday I wrote a program to print long max in C++. In 32 bit systems it prints a very small value [ Refer the program ). I am wonder if I want to store a long number which is the most appropriate data type in C++.

#include < stdlib.h>
#include < iostream>
#include < limits>

using namespace std;

int main(int argc, char** argv) {

// Print the long max value
// 64 bit machine this prints -> 9223372036854775807
// 32 bit machine this prints -> 2147483647
cout << "Max value for long : " << numeric_limits::max() << endl;

return (EXIT_SUCCESS);
}

Wednesday, January 9, 2008

Configure printers in Ubuntu

It is not very hard to configure printers in Ubuntu. The easiest way is run "http://localhost:631". This will prompt the Common UNIX Printing System. You can add,remove and manage using this web console. Another way to do this in Xwindow system run System -> Administration -> Printing. This will prompt a window based printer management system.

Tuesday, January 8, 2008

Read Property File from JAVA

In most causes we need to keep our configuration information in a property file. This will increase the usability as well as maintainability of a project. This program demonstrate how to read a Java property file and how to extract values from that.

Sample property file: [ myprop.properties ]

name=Jeorge
age=17
country=Sri Lanka
city=Colombo

/*
* Main.java
*
* Created on January 8, 2008, 1:55 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/

package blog2;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

/**
*
* @author eranga
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws FileNotFoundException, IOException, Exception {

if(args.length != 1){
throw new Exception("Please provide property file name as a command line parameter !");
}

String propertyFile = args[0];
File configPropsFile = new File(propertyFile);

if(!configPropsFile.exists())
throw new Exception("The config file : " + propertyFile + " does not exist.");

Properties myProp = new Properties();

myProp.load(new FileInputStream(propertyFile));

// Access properties
String prop1 = myProp.getProperty("name");
}

}

Monday, January 7, 2008

C++ Pre Processor Commands

When you write C++ programs ( Specially when error handling )you might need to get running file name, current execution line and system time. Following program demonstrate that.

//
// File: PreProcessorCommands.cc
// Author: eranga
//
// Created on January 7, 2008, 5:24 PM
//

#include
#include
using namespace std;

//
//
//
int main(int argc, char** argv) {

cout << "File Name : " << __FILE__ << endl;
cout << "Current Time : " << __TIME__ << endl;
cout << "Current Line : " << __LINE__ << endl;

return (EXIT_SUCCESS);
}