Saturday, October 04, 2008

Two Recipes

Saturday, April 12, 2008

Completely pointless technology

My manager sent me a meeting invitation via outlook yesterday. Accidentally, autofill managed to fill in my SIP address rather than my email address. I wasn't logged into my SIP account when this happened. When I get back to my desk, I notice that my voice mail indication is on. When I check it, it says there's been a fax sent to voice mail from my manager's phone number and the fax has no attachments. 
Fax with no attachments? Fax to voice mail? An outlook appointment converted to fax? File it under technology that's completely pointless.

Monday, March 31, 2008

XPCOM Proxy and getting access to the GUI from non-GUI thread

It was a frustrating week of pulling out hair trying to get this to work.

First, you'll need to get nsIProxyObjectManager which is not part of the Gecko-sdk but the idl file is part of the Firefox source code. So download the Firefox source code for the Firefox version that you're using. If you are using Firefox 2.0, downloading Firefox 3.0 source code and using the idl included there will not suffice. The UID of the IDL in Firefox 3.0 is different from that of Firefox 2.0. It would've saved me half a week of frsutration had I realized this sooner.

I'm sure there are several ways to proceed from here. I found the IDL in the Firefox source, generated a header file out of it using the xpidl command from Gecko-sdk and included that in my project. You'll find that when you try to compile your project with the nsIProxyObejctManager.h inculded, it'll require other header files as well and so you'll have to find and generate header files from a few other IDLs as well. I think in total it comes out to about 10. Not too frustrating a process, but frustrating enough.

Finally, you'll need to access the method you want via the proxy
Declare the proxy object
nsCOMPtr pmgr;
pmgr=do_GetService("@mozilla.org/xpcomproxy;1",&rv);

Now, i'm trying to write to an RDF file via the proxy. So I'll declare an RDF datasource to access via the proxy
nsCOMPtr proxyObject;

And then try to get proxy access to the nsIRDFDataSource
if (pmgr){
rv = pmgr->GetProxyForObject(NS_UI_THREAD_EVENTQ, NS_GET_IID(nsIRDFDataSource), dsource, 1|4, getter_AddRefs(proxyObject));

Now we have a proxy object for calling all functions declared in nsIRDFDataSource. For instance, to call the assert, we would do
proxyObject->Assert(ns_subject, ns_predicate, ns_literal, PR_TRUE);

Its the same for any other XPCOM Interface. You'll need to get access to it via GetProxyForObject and then you can access all functions to it via the proxy as above. Hope this helped.

Sunday, March 16, 2008

XPCOM and OS X

What I had to do to get an XPCOM component written in C++ compiled and linked on OS X
1. Install Xcode
2. Install Fink
3. At command prompt
cd /sw/bin;
sudo ./apt-get install glib
sudo ./apt-get install libIDL2
sudo cp libIDL-config-2 libIDL-config

4. Download the source of the Firefox version you'll be developing for. The only steps I had to perform that weren't mentioned on
http://developer.mozilla.org/en/docs/Mac_OS_X_Build_Prerequisites
was to add the following directory to my path
/sw/bin

5. change to directory to which Firefox source was downloaded and run the following commands
cp ./obj-ff/dist/bin/libxpcom_core.dylib ./obj-ff/dist/sdk/bin
cp ./obj-ff/dist/bin/libplds4.dylib ./obj-ff/dist/sdk/bin
cp ./obj-ff/dist/bin/libplc4.dylib ./obj-ff/dist/sdk/bin

6. Follow the steps give in
http://rcrowley.org/2007/07/17/cross-platform-xpcom-a-howto/
with Makefile looking like this:

GECKO_SDK := /obj-ff/dist/sdk

DEFINE := -DXP_UNIX -DXP_MACOSX
all: xpt dylib
xpt:
$(GECKO_SDK)/bin/xpidl -m header -I$(GECKO_SDK)/idl foo.idl
$(GECKO_SDK)/bin/xpidl -m typelib -I$(GECKO_SDK)/idl foo.idl
impl:
g++ -w -c -o foo_impl.o -I $(GECKO_SDK)/include $(DEFINE) foo_impl.cpp
module:
g++ -w -c -o foo_module.o -I $(GECKO_SDK)/include $(DEFINE) foo_module.cpp
dylib: impl module
g++ -dynamiclib -o foo.dylib foo_impl.o foo_module.o -L$(GECKO_SDK)/lib \
-L$(GECKO_SDK)/bin -Wl,-executable_path,$(GECKO_SDK)/bin \
-lxpcomglue_s -lxpcom -lnspr4
clean:
rm *.o
rm foo.h
rm foo.xpt
rm foo.dylib

7. Run make. Hopefully, it should work.

Sunday, December 30, 2007

Innovative Minds Don’t Think Alike

http://www.nytimes.com/2007/12/30/business/30know.html?_r=1&oref=slogin
I found this article especially profound, having been away from my engineering job for a few weeks and working on things that have very little to do with engineering. The time away has given me a new perspective on some of the things that have perplexed me over the past year.
I'm surrounded by engineers by education, brilliant ones at that, but conversations are about more or less the same thing and they tend to flow in one direction. Fresh perspectives are tough to come by and even tougher to gain a foot hold if someone has one.

Friday, November 16, 2007

undefined reference to `QApplication::QApplication

Add the following Linker flags: -lQtGui -lQtCore

In Eclipse, it would be under
Under Project -> Properties -> GCC C++ Linker -> Miscellaneous

Wednesday, November 14, 2007

Linker error and sipXtapi

If you get the following error:

Invoking: GCC C++ Linker
g++ -L../../src/.libs/ -L../../src/libs/ -lQtGui -lQtCore -o"my_sipXezPhone" ./fred.o ./main.o ./moc_myqtapp.o ./myqtapp.o

./myqtapp.o: In function `myQtApp::show()':
/root/sipXtapi/sipXcallLib/workspace/my_sipXezPhone/Debug/../myqtapp.cpp:115: undefined reference to `sipxInitialize'
collect2: ld returned 1 exit status

It because the linker cannot find the object file. Do the following

Add the following path to the linker library search path: directory where sipxtapi is installed/sipXcallib/src/.libs/

Add the following entry to the linker libraries: sipXcall

In Eclipse, it would look like this:

A couple of webpages that helped me get to the solution:

http://developer.apple.com/documentation/DeveloperTools/gcc-3.3/gcc/Link-Options.html

Relevant text:

-l library
Search the library named library when linking. (The second alternative with the library as a separate argument is only for POSIX compliance and is not recommended.)

It makes a difference where in the command you write this option; the linker searches and processes libraries and object files in the order they are specified. Thus, foo.o -lz bar.o searches library z after file foo.o but before bar.o. If bar.o refers to functions in z, those functions may not be loaded.

The linker searches a standard list of directories for the library, which is actually a file named liblibrary.a. The linker then uses this file as if it had been specified precisely by name.

The directories searched include several standard system directories plus any that you specify with -L.

Normally the files found this way are library files—archive files whose members are object files. The linker handles an archive file by scanning through it for members which define symbols that have so far been referenced but not defined. But if the file that is found is an ordinary object file, it is linked in the usual fashion. The only difference between using an -l option and specifying a file name is that -l surrounds library with lib and .a and searches several directories.

http://www.parashift.com/c++-faq-lite/mixing-c-and-cpp.html