Sunday, October 10, 2010

Subclipse SVN plug-in for Eclipse

10/10/10 - had to post something.

I've experiences utter frustration with the SVN command-line client to maintain the various projects I've been working on and the lack of a Linux equivalent to TortoiseSVN. Typical example, I added a directory to the repository by mistake before running a clean operation. It took 20 minutes trying to delete files, cleanup commands to get back to a starting place with the files I really wanted to add.

The only apparent GUI for SVN on Linux appears to be through an Eclipse plug-in. Since I am moving my projects to Eclipse anyway this is a no-brainer.

Subclipse

Subclipse is the Eclipse client that integrates directly with the Eclipse IDE, even my Eclipse CDT IDE works. The download instructions are out of date with the Helios package of Eclipse (or Linux version). But you can more or less follow the instructions they give.

The installation is performed from within Eclipse

1. Start Eclipse
2. Help > Install New Software
3. In the Install wizard, Work with: field, enter the URL for the Subclipse version from the download and install page of the Subclipse site. In my case: http://subclipse.tigris.org/update_1.6.x.
4. I selected all the packages there, Core SVNKit Library, Optional JNA Library, Subclipse.
5. Finish your way through the wizard to install everything.
6. After the install you have to restart Eclipse.
7. I got a JavaHL error on start up of Eclipse, having to do with the JNA library. This is another topic discussed on the Subclipse wiki.
8. I ignored the error and Subclipse worked so I don't know how serious it is. I since went and installed then performed the JavaHL test cases successfully.
9. Note: I already had the SVN subversion command-line client installed, that may be a prerequisite, I am not sure to be honest.


The usage of Subclipse is not that clear-cut and documentation is lacking.

1. You need to set up a repository. Under Window > Open Perspective > Other choose SVN Repository Exploring. You can add a new repository if you have the URL (I had already created a local repository with the command line client, "file:///home/ammianus/svn-repo").
2. From the SVN Repository Explorer perspective, you can right-click a folder in your repository then click Import..., select a project in your workspace and you are good to go.
3. Once a project is associated with a location in your repository, if you right-click on a project or file > Context Menu > Team > * there will be all the normal SVN commands you would need. You will also notice that next to the project name will be the SVN repository location in brackets [].
4. You can see the behavior of Subclipse in a Console view in which you can switch to the SVN console output.

Sunday, September 26, 2010

Building Static Libraries and Test Program with Eclipse CDT

Based on sample code from a book, GNU/Linux Application Programming by M. Tim Jones, I have been reading to refresh myself on Linux programming, specifically in the C language, I have been trying to explore using the Eclipse CDT IDE.

I have managed to get projects set up in Eclipse for a simple application that prints numbers to a file. For the sake of practice, I have split the code into 1) a static library, libexp, based on the random number API library example from Chapter 7 2) a static library, libtherm, that wraps the random function with a function that returns the "temperature" 3) a simple executable that calls the temperature library function multiple times and prints the results.

Eclipse CDT
I downloaded and installed the Eclipse CDT Helios version for Linux (x86_64)
This requires a Java Runtime be installed on the machine. I had to install OpenJDK (1.6.0_18, 64-bit)

Project Structure

I started from an existing project I had created using the Automake/Autoconfig to set up a build environment. In this set up, I there was a single "project" directory with an app and lib subfolders containing respective source and build files.

As far as I can tell, the Eclipse CDT approach is that there is a single build target per Project. Perhaps if you develop the Makefile rather than have Eclipse create one you could do a different set up. Going with a completely Eclipse controlled build process I created separate projects for each static library and the executable file. All the source files went directly into each project directory under the workspace.


Build Artifacts

See Right-click Project > Properties > C/C++ Build > Settings > Build Artifact
For each of my projects libexp and libtherm, I set the Build Artifact properties as Artifact Type: Static Library, Artifact Name: ${ProjName}, Artifact Extension: a.

This results when you compile in Eclipse building and archiving the object files into libexp.a and

For temp-app the difference was the Build Artifact was set to Type Executable and there was no extension.

Referencing Libraries

In my case, the libtherm library references libexp library. The temp-app needed to reference both libtherm and libexp.
For libtherm Properties > C/C++ General > Paths and Symbols > References. I checked off libexp / Active.

This adds under the Includes > GNU C tab the Include directory /libexp.

I also updated the Properties > Project References to check off libexp project.

These steps also add GCC Compiler flags. Under Properties > C/C++ Build > Settings > GCC C Compiler > Includes it adds under -l included paths: "${workspace_loc:/libexp}"

If you click on the main GCC C Compiler heading All the options are listed:
-I"/home/me/workspace/libexp" -O0 -g3 -pedantic -Wall -c -fmessage-length=0


For the temp-app the procedure was more or less the same. Under the Project References, Path and Symbol References I added the two library projects libexp, libtherm.

Difference seems to be in the Executable type Project, the C/C++ Build > Settings has new options for GCC C Linker. Under Libraries -l I added "therm" and "exp" (GCC C Linker will prepend "lib" and append ".a"). Under the Library Search Path (-L) I added paths to the Debug directories in my other projects where the library artifacts were being built. For GCC C Linker All Options this results in:
-static -L"/home/me/workspace/libtherm/Debug" -L"/home/me/workspace/libexp/Debug" -o"appexp" ./test.o -ltherm -lexp

(note: one crucial step when linking libraries that may refer to each other: you must order them in a top down way. i.e. the libraries that have their own references to lower level libraries should be ordered first, so in my case it was -ltherm then -lexp. See this discussion on StackOverflow for more details: GCC C++ Linker errors: Undefined reference to ...')

Running the Project

Once the projects have been set up and you have a working build. You can try to run it.

See Run > Run Configurations
Add a new C/C++ Application to run e.g. "AppExp". Clicking run will execute the program with output going to your Eclipse Console panel

Monday, September 20, 2010

Java method to copy file to UNC network location

Small update on something I used for work. I needed a way to copy a file stored locally from one machine to another machine on the network with a shared folder. This is an all Windows environment.

To copy a file with Java (JRE 1.4 or higher) the method found here was really helpful:

...
//File in = new File("local-file.txt")
//File out = new File("\\\\network\folder\file.txt")
FileChannel inChannel = new
FileInputStream(in).getChannel();
FileChannel outChannel = new
FileOutputStream(out).getChannel();
try {
inChannel.transferTo(0, inChannel.size(),
outChannel);
}
catch (IOException e) {
throw e;
}
finally {
if (inChannel != null) inChannel.close();
if (outChannel != null) outChannel.close();
}
...

Credit: http://www.rgagnon.com/javadetails/java-0064.html

Used the "new" technique using the java.nio package for transferring the file. See FileChannel.transferTo()

The example in the how-to page describes copying an input File in to an output File out

All I had to do was make sure that Java would understand a UNC style network file path for the out File that I wanted to copy to. It was really as simple as that, and worked perfectly. Just remember to double-escape the "\" including the starting "\\" prefix in your UNC file path.

File out = new File("\\\\host-name\\path\\to\\target-file.zip");

That page also discusses an issue on Windows where files of sizes greater than 64 MB fail with an "java.io.IOException: Insufficient system resources exist to complete the requested service" error. I initially tried with the suggested workaround to transfer the file in 64 MB chunks, which worked. For the record the file transfer for a larger file (167 MB) took around 18sec with this method. Given that this issue is several years and java versions old I thought I would try this out without splitting up the file.

My development system is Windows 7, JRE 1.5.0_22, the target host with the network share was on Windows XP. Using the original transferTo method without splitting the file successfully copied my large test file with no errors. There was also a slight performance gain as the copy took about 16 seconds that time.

Doing a little research in the Oracle Sun Developer Network Bug Database, it seems this may have been an issue fixed in: 6431344. Or it may have been that this was an OS problem and doesn't manifest on the Win 7 platform. In either case seems to be working.

Related bugs:
6822107
6486606

Sunday, August 22, 2010

WorldWind - WMS Authentication Support

A new user on the World Wind forums has submitted some changes for review and inclusion into the World Wind source. It is nice to see some contributions from the community still. I picked up his changes and belatedly did a code review and tried to test them. Note this authentication just adds a username and password via the .NET Framework's "System.Net.NetworkCredential" object added to the existing request sent to the WMS server.

Unfortunately I don't have a WMS server with authentication to test his fix against. I did some basic regression testing and existing WMS functionality seems to work fine. From reviewing the code nothing appeared to be harmful and it made sense, though he added no commenting for any of the changes. I asked the user to provide more code comments as well as to finish an enhancement he was apparently making to the WMS browser for username and password fields in the browser GUI.

Forum discussion

You can get the source and see it in action from my SVN branch:

https://nasa-exp.svn.sourceforge.net/svnroot/nasa-exp/branches/ammianus

I will hold off on commiting his changes to the World Wind trunk until he responds to my questions and maybe finishes his work on the WMS Browser.

I have to say, this is probably my last contribution to the WW.NET project for now. I think it has run its course and led to a dead end, technically and in terms of a learning experience. I have begun new projects to learn more about coding in GNU/Linux and as a result want to focus my efforts towards Real-Time and Embedded system development. I have to thank the World Wind project both as a learning exercise and for the fact it did get me a job interview for a GIS programming position, and it was the first true Open Source project I made contributions to. Here's to many more.

Tuesday, August 17, 2010

Redwoods - Day 32

Now that the seedlings have had a month to grow they have been doing well.


In general we water about twice a week, and spray the leaves and branches around every other day. The only windows in the room face east, so they get a lot of direct sun in the morning, and indirect the rest of the day. We've used some Miracle-Gro Liquid Houseplant Food, which we use for all our other house plants. In both cases starting from the bottom of the stem and growing up, the stem is turning a reddish-brown color with what seems to be the start of the redwood bark in what will be the trunk. It is only about the first 4-5 inches and after that the rest of the stem is still green like a plant's.

Specimen J2 is growing a bit fuller and maybe slightly taller. It grew a second set of branches radiating from the crown.
Specimen B2 is a little slower growing. Early on it had some "burning" of needles on some lower branches, possibly due to too much direct sunlight or under-watering. It seems to have recovered slowly but now is growing taller with more branches off the main stem.

Saturday, August 7, 2010

Ubuntu Remote Desktop

Last week after installing Ubuntu Linux on a new desktop I had moderate success trying to remote into the box using vncserver.

After speaking to a co-worker I found out that Ubuntu has a remote desktop capability built in to Gnome. That was great to know, so this weekend I spent some time to set that up finally. Enabling Remote Desktop connections is as easy as going to a Preferences Control Panel, a few check boxes are you it took to set it up. See this guide for more info: Remote Access to the Ubuntu Linux Desktop.

On the Windows side, my laptop already had TightVNC client (http://www.tightvnc.com). Using the above guide it was easy to connect to the Remote Desktop on the server using the default port of 5900 and desktop of :0.

This did log me in to the Gnome desktop, and thought I could move the mouse and control the desktop through TightVNC, it would not refresh the screen in the client window. After trying out a few solutions from the Ubuntu forums that didn't work, I remembered something the same co-worker mentioned. Basically there are some issues with VNC if you have any of the desktop effects enabled.

To disable them go to:
System > Preferences > Appearence >Visual Effects

Set to "None"
Immediately this disables the "effects". The only noticeable difference is that there were some transparency effects in some of the windows, and these were turned off. This probably helps with performance in any case.

This did the trick and my VNC client came back to life and started to function. Although it is a little choppy if you try to drag a window around the desktop it worked pretty well with the "High-speed Network" connection profile in TightVNC.

Update

Adobe Flash Plugin installed today randomly. All I did was go to http://www.pandora.com/ and install the plugin, worked fine, and the box has been serving its first function as a dedicated internet radio player in my living room.

Sunday, August 1, 2010

Ubuntu Experiment

I've been interested in learning about embedded system programming especially as it relates to real-time software and operating systems. This has all been spurred by my interest in the software in used by various areas of our space program ( see post Exploring the Milky Way, May 15, 2010). I did a brief search around job postings for aerospace and NASA type software eng. openings, found very little Ada, the language used to program Cassini, did find a few related VxWorks, real-time C++, POSIX C, so thought it would be worth my while to go back to programming in C/C++ on Linux environments, especially as Embedded Linux is growing in popularity[Yaghmour, Building Embedded Linux Systems, 2003].

To move towards that goal, I needed a Linux development system. I didn't want to dual boot one of my existing Windows machines and possibly deal with driver hell.

Got a machine the other day. Nothing cutting edge. AMD Athlon II X2 215 (Dual cores, ~2.70 GHz). 4GB Memory, 500GB hard disk, NVIDIA® GeForce® 6150 SE. Good thing is that the case has a slim profile, 10.4" H x 3.9" W x 14.6" D. I wanted something small and quiet so I could leave running as a server and work on remotely. It came with Windows 7 and the obligatory set of crappy trial software and spyware. Also bought a book for some programming practice: GNU/Linux Application Programming

I went with the Ubuntu Linux distribution. Created an installer CD with the 10.04 LTS 64 bit Server Edition.

Installing was a simple(!) process, the installation documentation on the Ubuntu site is pretty good, if verbose. No snags were hit, though because I chose the Server edition it didn't come with the Graphical Installer option, though its not like there were any shell commands you had to run during the install. Since I didn't care about the pre-installed Win 7 OS, I didn't have to bother with creating any partitions, I just overwrote the whole drive as one big Linux partition.

Once it booted up after install it came to the default shell prompt. There is no desktop in the Server edition. A quick google search gave me the command to install the Gnome desktop. This was plugged in

$ sudo apt-get install ubuntu-desktop

That probably took longer than the install itself. In any case it loaded up fine with a snappy new purple themed Ubuntu desktop. From start to end it was probably around 4 hours of time.


Ubuntu Gnome desktop

One odd thing is that during the server install you are prompted for what kind of "server package" you want to set up. I chose Java/Tomcat, though I may not even use it. I can find no evidence that Java was installed so I am not sure what that was supposed to do.

Startup now takes under 10 seconds I would say, it is incredibly smooth.

I tried to connect remotely from my windows PC using PuTTy, but no luck, there was no SSH listener running on the server. You have to enable it by installing the SSH packages.

$ sudo apt-get install ssh

That worked and I could connect via PuTTy SSH over port 22. Trouble is you needed to connect by the IP address of the box, you apparently can't resolve the Linux server's machine name from Windows. Fine, so I had to add an entry into my Hosts file, C:\Windows\System32\Drivers\etc\hosts. Its funny that Windows to Windows doesn't require this to resolve the machine name, but Windows to Linux doesn't work. I noticed that the Linksys router administration site did recognize the Linux server's name in the DHCP Clients Table.

In any case minor issue.

The other thing I've found is that Adobe Flash plugins doesn't seem to install, I tried the .apt and the .deb versions offered by Adobe, neither worked, getting "Architecture Not Supported 'I386'" errors. Great job Linux! I would guess it may have to do with 64-bit vs 32 as I believe Flash doesn't have any native 64 bit versions, at least not on Windows.

Next step is to try to set up VNC in order to make a remote desktop connection from my laptop to the new server. We do this at work with our Linux Oracle database host, so I know it works well.