Unified Notification Service: Avoid The Wheel Reinvention

August 7, 2009 Matteo Bertozzi | Filed Under Networking | No Comments

Every programmer loves to reinvent the wheel, and reinventing the wheel is still my primary hobby. Sometimes you need to reimplement a Network protocol to use with your favorite language/library, sometimes is only for fun, but if you’re in the Business World maybe is “better” (faster) to use one of the thousand existing libraries.

In the most cases you need to reimplement a Protocol to embed it in your application, and sometimes you have to reimplement two/three protocols that does the same job like IM Protocols (XMPP, AIM, Yahoo…).

A better solution, that avoid you to reinvent the wheel is to use an existent library to handle the protocol(s) that you need, and build an Abstract Interface, with your data format, that allows you to use a generic way to communicate between various provider. Below you can find a graphical example of what I mean.

Unified Notification Service

You can have many providers, written in different languages. These providers talk with the Notification Service providing an abstract interface for the Apps. In this way, the end App has just to say “Write a Mail To X”, “Download Todays Mail”, “Send an IM to X”… and you can intercept notification to displays as a popup on your desktop… or something similar.

This solution will be used in MokoTouch Project, to provide Core Services to the Apps. For more information send me a mail.

A Bit of Distributed Computation…

August 4, 2009 Matteo Bertozzi | Filed Under Networking | No Comments

In the last months I’ve worked on various 2D rendering projects, that requires lots of row power to be executed in smallest time as possible.

The rendering result is an aggregation of components (or better, Group of Components) that can be rendered independently of each other in a  process because each components has its own input data and until the aggregation process starts there’re no dependencies between components. In a few words, foreach input data I’ve to call a Render method that returns the “computed” data, that at the end will be aggregated with all the computed values.

So, how speed-up the rendering? The standard answer is using Threads, to take advantage of multi-core system. But I need lots row power and lots of core to be fast enought. Another solution that doesn’t require to spent a lot of money for a faster computer it to distribute the computation across different machines. And this is my attempt…

Distributed Computation Arch

The Master receive an array of elements as input and splits up it according to the number of the available Nodes (Machines), and foreach node assigns its sub-array and sends an “informative message” to the node.

The Node waits for an “informative message” and when it has received it, starts its computation. Foreach Data Item that fetch runs the Computation and sends back the result.

The Master decompose data into equal-size partitions, so each node has  an equal-size queue to process, but if someone finishes its job and there’re more data to process (in someone else queue) The Master dequeue couple of items from the slower node queue and add to the queue of the one that has finished its job. In this way you’ve done your computation faster then ever, and if one machine crashes (slow one case) its job will be taken by someone else that has finished its own.

And this is just a bit of General Theory, but the implementation is really simple. Maybe I’ll try to reimplement something more generic in the near future (October, November) when I’ll have a bit more of free time. If you’ve any question send me a mail!

MokoTouch: 1st Developer Release!

August 2, 2009 Matteo Bertozzi | Filed Under OpenMoko | No Comments

Today, after a long time (I Still don’t have time, wait for September!)… I’ve released the first Moko Touch (Developer) Snapshot. Below you can see a screenshot of the MokoTouch Website that is available here: http://th30z.netsons.org/mokotouch/.

Moko Touch Web Site

Now you’re able, to develop your app, interact with accelerometers handle some gestures and load it from the homescreen. Now There’s to add a lot of UI Elements, and IPC Services for Notifications and other nice stuff!

Qt4 Imap API

August 1, 2009 Matteo Bertozzi | Filed Under Qt4 | 1 Comment

Pushed in my GitHub repo the first draft of the Qt4 Imap (RFC 3501 Interne Message Access Protocol) Library.
I’ve implemented a sync communication because it’s much easier to use, so if you want to use it in async way you need to implement a thread class that wrap the Imap class and throws the events that you need.

Imap imap;
if (!imap.connectToHost(IMAP_HOST, IMAP_PORT, IMAP_USE_SSL))
   IMAP_MAIN_ABORT("connectToHost()", imap.errorString());

if (!imap.login(IMAP_USERNAME, IMAP_PASSWORD, IMAP_LOGIN_TYPE))
   IMAP_MAIN_ABORT("login()", imap.errorString());

ImapMailbox *mailbox = imap.select("INBOX");
qDebug() << "INBOX";
qDebug() << " - Exists:" << mailbox->exists();
qDebug() << " - Unseen:" << mailbox->unseen();

QList<int> messageList = imap.searchRecentUnseen();
imap.fetch(mailbox, messageList);
foreach (int msgId, messageList) {
   ImapMessage *message = mailbox->findById(msgId);
   if (message == NULL) continue;

   imap.fetchBodyStructure(message);

   qDebug() << "FROM" << message->fromAddress().toString();
   foreach (ImapAddress address, message->toAddresses())
      qDebug() << " - TO" << address.toString();
   qDebug() << "SUBJECT" << message->subject();

   for (int i = 0; i < message->bodyPartCount(); ++i) {
      ImapMessageBodyPart *bodyPart = message->bodyPartAt(i);
      imap.fetchBodyPart(message, i);

      qDebug() << bodyPart->isAttachment() << bodyPart->contentType();
      qDebug() << bodyPart->data();
   }
}

delete mailbox;

imap.logout();
imap.disconnectFromHost();

Qt4 Google Contacts APIs

July 24, 2009 Matteo Bertozzi | Filed Under Qt4 | No Comments

Just pushed at GitHub the first draft of the Qt4 Google Contacts Service…

Contacts APIs allows client applications to view and update Contacts content in the form of Google Data API feeds. Your client application can request a list of a user’s contacts, edit or delete content in an existing contact.

// Setup Contact
THGoogleContact *contact = new THGoogleContact;
contact->setFullName("John Doe");

THGoogleIm *im = new THGoogleIm;
im->setRel(THGoogleIm::relWork());
im->setAddress("john.doe@aim.com");
im->setProtocol(THGoogleIm::protocolAim());
contact->addImAddress(im);

THGoogleEmail *email = new THGoogleEmail;
email->setAddress("john.doe@mail.com");
email->setRel(THGoogleEmail::relWork());
contact->addEmailAddress(email);

// Insert Contact
THGoogleContactsService *gContacts = new THGoogleContactsService;
gContacts->setAuthToken(...);
gContacts->insertContact(contact);


Take a look at contacttest.cpp for a more complete usage example.

Moko Touch 1st Keyboard Concept

July 18, 2009 Matteo Bertozzi | Filed Under OpenMoko | 3 Comments

Today, I’ve spent half of my day to do something for the “Moko Touch” Project. I need a simple keyboard that I can use without use a stylus or a toothpick. I need something “Bigger”, so I’ve made a couple of experiments and this is the “best” result. Maybe it hasn’t a great look’n feel now but it’s really usable.

Moko Touch Vertical Keyboard Concept 1

Vertical Keyboard (480x295 px)

The concept is really simple. Use less space as possible for the keyboard and use the “Maximum Size” available for the buttons. And as you can see with just 12 buttons you’ve all your Letters, numbers and Symbols in the smallest usable space (480×295 px for the Vertical Keyboard and 640×195 px for the Horizontal Keyboard).

Horizontal Keyboard (640x295 px)

Horizontal Keyboard (640x195 px)

But as always there’s a “Bad side”. You’ve to tap twice to pike on key, for Example: Tap on “QWER” button on the “12 keys keyboard” a 4×4 box will appear, and you’ll have to tap on the key to select it. So for each letter you’ve to tap twice. But maybe there’s no type mistake even if you’re using your phone while you’re running :D

This is just the 1st concept of the Moko Touch Keyboard. If you’ve ideas to improve it, send a comment or a mail. It will be really appreciated. Thanks!

OpenGL: 3D Cube, Rotation, Translation and Texts

July 14, 2009 Matteo Bertozzi | Filed Under OpenGL | No Comments

Second hour with OpenGL, last time I’ve written a simple 2D example to learn what Vertex are, and now a little step forward using 3D, Rotation, Translation and Texts.

OpenGL 3D Cube

Using GLUT writing 2D texts is really simple, and here is how to do it. Setup Text Color, X and Y Location, pick up a font and set your string, and it’s done.

glColor3f(1.0, 0.0, 0.0);
glRasterPos2f(-4.6, 2.3);
glutBitmapString(GLUT_BITMAP_TIMES_ROMAN_24, 'Hello Text');


To handle left, right, up, down keys to move the cube use the glutSpecialFunc() that allows you to handle GLUT_KEY_LEFT, GLUT_KEY_RIGHT, GLUT_KEY_UP, GLUT_KEY_DOWN keys and others. Translation and rotation are made using glTranslatef() and glRotatef().

The source code is available here: Python OpenGL 3D Cube Source Code.

OpenGL: First Test – 2D Example

July 12, 2009 Matteo Bertozzi | Filed Under OpenGL | No Comments

I’m not a Computer Graphics fan, but I’ve spent my the last year working on Report Engine, and User Interfaces… drawLine, drawRect.. setLocation… (I don’t know.. I’m a malloc/memset boy).

But I need to learn more about Computer Graphics for the future, and today I’ve started playing with OpenGL… No more 2D points!!! :D

OpenGL 2d 1st Test

Below you can see a couple of lines of code that draws the example above…

static void drawTriangle (void) {
    glColor3f(0.0f, 0.0f, 1.0f);
    glBegin(GL_TRIANGLES);

   glVertex3f( 0.0f,  0.6f, 0.0f);
   glVertex3f(-0.2f, -0.3f, 0.0f);
   glVertex3f( 0.2f, -0.3f, 0.0f);

   glEnd();
}

static void drawSquare (void) {
    glColor3f(1.0f, 0.0f, 0.0f);
    glBegin(GL_TRIANGLE_FAN);

    glVertex3f(0.0f, 0.0f, 0.0f);
    glVertex3f(0.5f, 0.0f, 0.0f);
    glVertex3f(0.5f, 0.5f, 0.0f);
    glVertex3f(0.0f, 0.5f, 0.0f);

    glEnd();
}

static void drawSquareMode2 (void) {
    const GLfloat squareVertices[] = {
        -0.2,  0.2, 0.2,
        -0.2, -0.2, 0.2,
         0.2, -0.2, 0.2,
         0.2,  0.2, 0.2
    };

    glColor3f(0.0f, 1.0f, 0.0f);
    glVertexPointer(3, GL_FLOAT, 0, squareVertices);
    glEnableClientState(GL_VERTEX_ARRAY);
    glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
}


I’ve used NSOpenGLView to display the GL, so the drawing code is inside a drawRect method.

- (void)drawRect:(NSRect)bounds {
    glClearColor(0, 0, 0, 0);
    glClear(GL_COLOR_BUFFER_BIT);

    glTranslatef(-0.2f, 0.0f, 0.0f);
    drawTriangle();

    glTranslatef(0.2f, 0.0f, 0.0f);
    drawSquare();
    drawSquareMode2();

    glFlush();
}

« Previous PageNext Page »