Skip to content

Instantly share code, notes, and snippets.

@fincs
Created May 24, 2012 17:47
Show Gist options
  • Save fincs/2783051 to your computer and use it in GitHub Desktop.
Save fincs/2783051 to your computer and use it in GitHub Desktop.
Very early FOM/FTL preview
#include <stdio.h>
#include <fom.h> // FeOS Object Model header file
#include <ftl.h> // FOM Template Library header file
using namespace FOM;
using namespace FTL;
// Declare some interfaces...
// {65D3561A-7DD0-4740-BD4E-EA82DF1B8E9D}
struct ICat : public IObject
{
FOM_BIND_GUID(0x65D3561A, 0x7DD0, 0x4740, 0xBD, 0x4E, 0xEA, 0x82, 0xDF, 0x1B, 0x8E, 0x9D);
virtual status_t Meow() = 0;
virtual status_t Purr() = 0;
};
// {D7ADEB3B-E6D6-42fd-B6B7-23556A5C9309}
struct IEntertain : public IObject
{
FOM_BIND_GUID(0xD7ADEB3B, 0xE6D6, 0x42FD, 0xB6, 0xB7, 0x23, 0x55, 0x6A, 0x5C, 0x93, 0x9);
virtual status_t Entertain() = 0;
};
// Cat implementation
class CatImpl: public ICat, public IEntertain, public ObjectRoot // ObjectRoot belongs to FTL
{
~CatImpl() { }
public:
FTL_IMPLEMENT_IOBJECT("Meow.Cat"); // This is supposed to be the class name
FTL_BEGIN_IFACE_MAP(CatImpl)
FTL_IFACE_MAP_ENTRY(ICat)
FTL_IFACE_MAP_ENTRY(IEntertain)
FTL_END_IFACE_MAP()
// ICat and IEntertain methods
status_t Meow() { printf("meowwww!\n"); return S_OK; }
status_t Purr() { printf("purrrrrr\n"); return S_OK; }
status_t Entertain() { printf("{the cat makes a cute face}\n"); return S_OK; }
CatImpl() { }
};
// Simple test
void catBasic(IObject* pObj)
{
ICat* pCat = NULL;
if (SUCCEEDED(pObj->QueryInterface(IID_PPV_ARGS(&pCat))))
{
pCat->Meow();
pCat->Purr();
pCat->Release();
}
}
void catEntertain(IObject* pObj)
{
IEntertain* pEntertain = NULL;
if (SUCCEEDED(pObj->QueryInterface(IID_PPV_ARGS(&pEntertain))))
{
pEntertain->Entertain();
pEntertain->Release();
}
}
int main()
{
CatImpl* pCat = new CatImpl;
catBasic(pCat);
catEntertain(pCat);
pCat->Release();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment