Boost Install on Fedora 8
June 9, 2008
Today I reinstalled Boost on Fedora, after a couple of hours of playing around getting everything working I decided to write up a post about it. In the past I have found Boost to be an amazing library to work with. If you have never had a chance to use it I highly recommend it, Boost can really can open your eyes to the elegance of C++ and is packed full of great libraries for solving every day coding issues. Specifically in the past I have had a chance to work with boost’s smart pointers, threading and filesystem libraries. I will soon be writing some tutorials on using Boost, so expect that soon.
One note with the installation of Boost on Linux is that it can be somewhat of a mystery at times and is no easy challenge to setup at first. Hopefully this post will help users out there skip some of the issues I had to work through.
Installation
The first thing to do is to grab the Boost source package and Boost Jam pre-built executable from here
This tutorial uses:
Before starting ensure you are root and have g++ installed. In Fedora you can do this with…
% yum install gcc-c++
Extract the Boost package.
% tar xzf boost_1_33_1.tar.gz
Then extract the bjam files.
% tar xzf boost-jam-3.1.14.tgz
Move into the root of the bjam directory, and run the build.sh script to generate the bjam executable.
% cd boost-jam-3.1.14
% ./build.sh
Grab the bjam file that was created from /bin.linuxx86/ and move it into the boost_1_33_1 directory. Run the following, this will take anywhere from 10-20 minutes to run, possibly more depending your system setup.
% bjam ––toolset=gcc install
Once it has finished you can check to ensure the libraries and include files are where they should be.
% cd /usr/local/include/boost-1_33_1
% ls -l
and
% cd /usr/local/lib
% ls -l
Testing the Install
Now we need to ensure that everything was successful. The best way to do this is to write a test app utilizing one of the Boost libraries, for this demonstration we will use the filesystem library.
First, lets set up the environment variables in our .bashrc to make our lives a little easier when compiling.
% vi .bashrc
Add the following lines to your .bashrc and then restart your shell to enable the new exports
export CPLUS_INCLUDE_PATH=/usr/local/include/boost-1_33_1
export LIBRARY_PATH=/usr/local/lib
export LD_LIBRARY_PATH=/usr/local/lib
Now that our environment is setup we can write the example code. This code below uses the Boost filesystem library to check to see if your home directory exists and is a directory.
#include <iostream>
#include <boost/filesystem/operations.hpp>
namespace fs=boost::filesystem;
int main()
{
fs::path homePath("/home/");
if(fs::exists(homePath) && fs::is_directory(homePath))
std::cout << "Directory: " << homePath.leaf() << " exists!" << std::endl;
}
Then compile the source.
% g++ -o boost_test boost_test.cpp -lboost_filesystem-gcc
% ./boost_test
If all has went well you should see Directory: home exists!
No Kettle, No Worries
June 8, 2008
![]() |
Everyone knows programmers and techies alike are caffeine addicts. I myself am no different and usually drink a mixture of both tea and coffee. However about a month ago I started to really get tired of always having to put my kettle on every 15mins as I downed cup after cup of green tea while coding. Not only is it just a pain, but your constantly loosing your train of thought while working.
Because of this problem I applied my coffee habits to my tea habits and began to use my coffee maker for tea as well. This allows me to have a pot of tea staying warm for long periods of time with very little effort. To do it just remove any filters from your coffee maker, pour in the water, throw 3 to 4 tea bags in the pot and your good to go.
Android Notifications
June 7, 2008
Last night I spent sometime experimenting with how to implement a notification system class to abstract the details away of launching notifications from my main application service. After looking into what Android provides for doing this I found it to very clear and easy to implement.
Android’s Notification Manager
The Android Notification Manager handles the system level work of producing notifications allowing us to create custom notification objects specifying how we want our notifications to be produced. You do not need to initialize the Notification Manager instead you can just retrieve a handle to the service using getSystemService(String) passing it the identifier NOTIFICATION_SERVICE. In order to get a context to call this method I had to send the callers context to my constructor and import android.content.Context because my class does not inherit from any Android classes as it is just a helper class to my service. The code below demonstrates the process to get the handle.
mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Android’s Notification
To create the Notification object we just call the constructor passing the notification details we want which will determine the final resulting notification. In most cases the constructor takes enough parameters to fulfill the requirements for most notifications you will need to invoke, however there are additional properties provided which can be set on the object after initialization.
Two of the parameters for the constructor are intents, one to be invoked when a user clicks the icon and one when a click on the content of the notification occurs. I generated an explicit intent to call one of my activities, which in this case provides functionality to view a new incoming message.
Intent viewMsgIntent = new Intent(context, ReceiveMessage.class);
viewMsgIntent.putExtra("Contact", contact);
viewMsgIntent.putExtra("Message", msg);
I also set up the ticker text string, which is the string that gets scrolled across the notification menu at the top of the screen when a notification is received.
String tickerText = "New message received from " + contact + "...";
The rest of the parameters include, two icons, one for the status bar at the top of the screen, and an application icon which is larger and is displayed in the notifications drop down menu.
The when parameter specifies a time stamp to determine when the notification should be launched. I wanted my notification to be launched instantly so I used the System.currentTimeMillis() to get the current time.
Here is the final code for initializing the notification object.
Intent viewMsgIntent = new Intent(cx, ReceiveMessage.class);
viewMsgIntent.putExtra("contact", contact);
viewMsgIntent.putExtra("message", msg);
String tickerText = "New message received from " + contact + "...";
if(msg.length() > 40)
msg = msg.substring(0, 40);
Notification obj = new Notification(
cx, // our context
R.drawable.im_icon, // the icon for the status bar
tickerText, // the text to display in the ticker
System.currentTimeMillis(), // the timestamp for the notification
titleText, // the title for the notification
msg, // the details to display in the notification
viewMsgIntent, // the contentIntent (see above)
R.drawable.im_icon, // the app icon
"IM App", // the name of the app
viewMsgIntent);
Sending the Notification Out
Once the notification object is created you can invoke it by calling the notify method on the Notification Manager, passing it the notification object. The first parameter of this method is an ID representing the notification.
mNotificationManager.notify(R.string.recv_msg_notif_id, obj);
So thats it, a very basic break down of the notification process in Android.
You can find more information here:
