New fun project: a C++ Web Framework

As a true programmer, I need fun projects to stay alive. Don't get me wrong, my client work fulfills me, and eventhough I've been slacking lately in keeping up with its workload, CakePHP is also a lot of fun. However, true programmers are always looking for a fun project, one they can call their own. Meet CLAPP, a C++ MVC Web Framework.

I am not even close to finishing it, but so far I'm having LOTS of fun. What is amazing is that missing only the M in MVC (the database abstraction layer), CLAPP's performance is already astonishing. Running as FastCGI, it outperforms the most basic PHP file by a ratio of 1000%. Amazing.

So what am I looking to gain from this? Nothing, just having fun going back to my absolute favourite language: C++. In the meantime, I get to play with speed comparisons, which gets particularly interesting as I enable more stuff in the framework. My ideal goal is to include a lot of the you-just-have-to-have-this kind of things available on real, serious frameworks such as CakePHP. This doesn't mean that I will hereon start developing every web application in C++, that would just be dumb (if you are asking why, then that's because you haven't given CakePHP a try). It does mean, however, that I'll be posting about CLAPP every now and then.

To calm your expectations, here's a very, VERY small preview of the Dispatcher, which is directly attached to every controller:

Code:

#ifndef __CLAPP_DISPATCHER_HPP
#define __CLAPP_DISPATCHER_HPP
 
#include <clapp/cgi_stream.h>
#include <clapp/controller.h>
 
namespace clapp {
  template <class C>
  class Dispatcher {
    public:
      Dispatcher();
      ~Dispatcher();
      void dispatch();
 
    private:
#ifdef CLAPP_WITH_FASTCGI
      CgiStreamFastCgi * cgiStream;
#else
      CgiStream * cgiStream;
#endif
 
      void execute();
  };
}
 
template <class C>
clapp::Dispatcher<C>::Dispatcher() {
#ifdef CLAPP_WITH_FASTCGI
  this->cgiStream = new CgiStreamFastCgi();
#else
  this->cgiStream = new CgiStream();
#endif
}
 
template <class C>
clapp::Dispatcher<C>::~Dispatcher() {
  delete this->cgiStream;
}
 
template <class C>
void clapp::Dispatcher<C>::dispatch() {
#ifdef CLAPP_WITH_FASTCGI
  FCGX_Request request;
 
  FCGX_Init();
  FCGX_InitRequest(&request, 0, 0);
 
  while (FCGX_Accept_r(&request) == 0) {
    this->cgiStream->setRequest(request);
    this->execute();
    FCGX_Finish_r(&request);
  }
#else
  this->execute();
#endif
}
 
template <class C>
void clapp::Dispatcher<C>::execute() {
  C *controller = NULL;
 
  try {
    controller = new C();
 
    controller->setStream(this->cgiStream);
    controller->dispatch();
 
    delete controller;
  } catch(...) {
    if (controller != NULL) {
      delete controller;
    }
    throw;
  }
}
 
#endif

As you can guess from the source code, CLAPP can produce FastCGIs and regular CGIs. It uses ClearSilver for its view / layout templates, the FastCGI development kit (when FastCGI mode is enabled), and GNU cgicc as a CGI / FastCGI input wrapper. More news coming soon!