Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ design pattern platform specific api

I am working on Windows. I have to see certain set of API's for Windows 2008 and above and different set of API's for other flavors of Windows. I want to know what is the best way to design such kind of stuff, so that my main driver code do not have #ifdef

For Example: In Windows 2008 We have API

EVT_HANDLE WINAPI EvtOpenLog(
  __in  EVT_HANDLE Session,
  __in  LPCWSTR Path,
  __in  DWORD Flags
);

and For Windows 2003 we have another API which does the same.

HANDLE OpenEventLog(
  __in  LPCTSTR lpUNCServerName,
  __in  LPCTSTR lpSourceName
);

What I am looking for is having some kind of wrapper API in my code which internally handles these calls.

like image 943
Avinash Avatar asked Jul 29 '11 05:07

Avinash


1 Answers

You can write an Platform Abstraction Layer, which will expose a common interface for all api types and for each port then you can implement the interface. You can provide the abstraction as an separate library for each port which ensures that your calling application remains the same only the library to be linked changes.

like image 97
Alok Save Avatar answered Sep 18 '22 03:09

Alok Save