LayerManagement: fixed issues detected by valgrind
[profile/ivi/layer-management.git] / LayerManagerPlugins / Communicators / GenericCommunicator / src / GenericCommunicator.cpp
index a9c6938..8386cd1 100644 (file)
 
 #include "GenericCommunicator.h"
 #include "ilm_types.h"
+#include "LmScreen.h"
 #include "Log.h"
+#include "Configuration.h"
 
 #include "ICommandExecutor.h"
 #include "CommitCommand.h"
 #include "LayerCreateCommand.h"
-#include "LayergroupCreateCommand.h"
 #include "SurfaceCreateCommand.h"
-#include "SurfacegroupCreateCommand.h"
 #include "SurfaceGetDimensionCommand.h"
 #include "LayerGetDimensionCommand.h"
 #include "SurfaceGetOpacityCommand.h"
 #include "LayerRemoveSurfaceCommand.h"
 #include "LayerRemoveCommand.h"
 #include "SurfaceRemoveCommand.h"
-#include "LayergroupRemoveCommand.h"
-#include "SurfacegroupRemoveCommand.h"
 #include "SurfaceGetOrientationCommand.h"
 #include "LayerGetOrientationCommand.h"
-#include "LayergroupAddLayerCommand.h"
-#include "LayergroupRemoveLayerCommand.h"
 #include "LayerSetDestinationRectangleCommand.h"
 #include "SurfaceSetDestinationRectangleCommand.h"
 #include "LayerSetOpacityCommand.h"
-#include "LayergroupSetOpacityCommand.h"
 #include "SurfaceSetOpacityCommand.h"
-#include "SurfacegroupSetOpacityCommand.h"
 #include "LayerSetSourceRectangleCommand.h"
 #include "SurfaceSetSourceRectangleCommand.h"
 #include "LayerSetOrientationCommand.h"
 #include "SurfaceSetOrientationCommand.h"
-#include "SurfacegroupAddSurfaceCommand.h"
-#include "SurfacegroupRemoveSurfaceCommand.h"
 #include "LayerSetVisibilityCommand.h"
 #include "SurfaceSetVisibilityCommand.h"
-#include "LayergroupSetVisibilityCommand.h"
-#include "SurfacegroupSetVisibilityCommand.h"
 #include "DebugCommand.h"
 #include "ExitCommand.h"
 #include "ScreenSetRenderOrderCommand.h"
 #include "SurfaceUpdateInputEventAcceptance.h"
 #include "SurfaceSetChromaKeyCommand.h"
 #include "LayerSetChromaKeyCommand.h"
-
+#include "SetOptimizationModeCommand.h"
+#include "GetOptimizationModeCommand.h"
+#include "SetSynchronizedSurfacesCommand.h"
+#include "RemoveSynchronizedSurfacesCommand.h"
 #include <stdbool.h>
 #include <unistd.h>
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
 #include <string>
+#include <pthread.h>
+#include <signal.h>
+#include <vector>
 
 #define DEFAULT_SCREEN 0
 
-const char* RESOURCE_ALREADY_INUSE = "Ressource already in use";
-const char* INVALID_ARGUMENT = "Invalid argument";
-const char* RESOURCE_NOT_FOUND = "Ressource not found";
-const char* NOT_IMPLEMENTED = "Feature not implemented";
-
-
-GenericCommunicator::GenericCommunicator(ICommandExecutor* executor)
-: ICommunicator(executor)
+GenericCommunicator::GenericCommunicator(ICommandExecutor& executor, Configuration& config)
+: ICommunicator(&executor)
+, PluginBase(executor, config, Communicator_Api_v1)
 , m_running(ILM_FALSE)
 {
     MethodTable manager_methods[] =
     {
-        { "ServiceConnect",                   &GenericCommunicator::ServiceConnect },
-        { "ServiceDisconnect",                &GenericCommunicator::ServiceDisconnect },
-        { "Debug",                            &GenericCommunicator::Debug },
-        { "ScreenShot",                       &GenericCommunicator::ScreenShot },
-        { "ScreenShotOfLayer",                &GenericCommunicator::ScreenShotOfLayer },
-        { "ScreenShotOfSurface",              &GenericCommunicator::ScreenShotOfSurface },
-        { "GetScreenResolution",              &GenericCommunicator::GetScreenResolution },
-        { "GetNumberOfHardwareLayers",        &GenericCommunicator::GetNumberOfHardwareLayers },
-        { "GetScreenIDs",                     &GenericCommunicator::GetScreenIDs },
-        { "ListAllLayerIDS",                  &GenericCommunicator::ListAllLayerIDS },
-        { "ListAllLayerIDsOnScreen",          &GenericCommunicator::ListAllLayerIDsOnScreen },
-        { "ListAllSurfaceIDS",                &GenericCommunicator::ListAllSurfaceIDS },
-        { "ListAllLayerGroupIDS",             &GenericCommunicator::ListAllLayerGroupIDS },
-        { "ListAllSurfaceGroupIDS",           &GenericCommunicator::ListAllSurfaceGroupIDS },
-        { "ListSurfacesOfSurfacegroup",       &GenericCommunicator::ListSurfacesOfSurfacegroup },
-        { "ListLayersOfLayergroup",           &GenericCommunicator::ListLayersOfLayergroup },
-        { "ListSurfaceofLayer",               &GenericCommunicator::ListSurfaceofLayer },
-        { "GetPropertiesOfSurface",           &GenericCommunicator::GetPropertiesOfSurface },
-        { "GetPropertiesOfLayer",             &GenericCommunicator::GetPropertiesOfLayer },
-        { "CreateSurface",                    &GenericCommunicator::CreateSurface },
-        { "CreateSurfaceFromId",              &GenericCommunicator::CreateSurfaceFromId },
-        { "InitializeSurface",                &GenericCommunicator::InitializeSurface },
-        { "InitializeSurfaceFromId",          &GenericCommunicator::InitializeSurfaceFromId },
-        { "SetSurfaceNativeContent",          &GenericCommunicator::SetSurfaceNativeContent },
-        { "RemoveSurfaceNativeContent",       &GenericCommunicator::RemoveSurfaceNativeContent },
-        { "RemoveSurface",                    &GenericCommunicator::RemoveSurface },
-        { "CreateLayer",                      &GenericCommunicator::CreateLayer },
-        { "CreateLayerFromId",                &GenericCommunicator::CreateLayerFromId },
-        { "CreateLayerWithDimension",         &GenericCommunicator::CreateLayerWithDimension },
-        { "CreateLayerFromIdWithDimension",   &GenericCommunicator::CreateLayerFromIdWithDimension },
-        { "RemoveLayer",                      &GenericCommunicator::RemoveLayer },
-        { "AddSurfaceToSurfaceGroup",         &GenericCommunicator::AddSurfaceToSurfaceGroup },
-        { "RemoveSurfaceFromSurfaceGroup",    &GenericCommunicator::RemoveSurfaceFromSurfaceGroup },
-        { "AddLayerToLayerGroup",             &GenericCommunicator::AddLayerToLayerGroup },
-        { "RemoveLayerFromLayerGroup",        &GenericCommunicator::RemoveLayerFromLayerGroup },
-        { "AddSurfaceToLayer",                &GenericCommunicator::AddSurfaceToLayer },
-        { "RemoveSurfaceFromLayer",           &GenericCommunicator::RemoveSurfaceFromLayer },
-        { "CreateSurfaceGroup",               &GenericCommunicator::CreateSurfaceGroup },
-        { "CreateSurfaceGroupFromId",         &GenericCommunicator::CreateSurfaceGroupFromId },
-        { "RemoveSurfaceGroup",               &GenericCommunicator::RemoveSurfaceGroup },
-        { "CreateLayerGroup",                 &GenericCommunicator::CreateLayerGroup },
-        { "CreateLayerGroupFromId",           &GenericCommunicator::CreateLayerGroupFromId },
-        { "RemoveLayerGroup",                 &GenericCommunicator::RemoveLayerGroup },
-        { "SetSurfaceSourceRegion",           &GenericCommunicator::SetSurfaceSourceRegion },
-        { "SetLayerSourceRegion",             &GenericCommunicator::SetLayerSourceRegion },
-        { "SetSurfaceDestinationRegion",      &GenericCommunicator::SetSurfaceDestinationRegion },
-        { "SetSurfacePosition",               &GenericCommunicator::SetSurfacePosition },
-        { "GetSurfacePosition",               &GenericCommunicator::GetSurfacePosition },
-        { "SetSurfaceDimension",              &GenericCommunicator::SetSurfaceDimension },
-        { "SetLayerDestinationRegion",        &GenericCommunicator::SetLayerDestinationRegion },
-        { "SetLayerPosition",                 &GenericCommunicator::SetLayerPosition },
-        { "GetLayerPosition",                 &GenericCommunicator::GetLayerPosition },
-        { "SetLayerDimension",                &GenericCommunicator::SetLayerDimension },
-        { "GetLayerDimension",                &GenericCommunicator::GetLayerDimension },
-        { "GetSurfaceDimension",              &GenericCommunicator::GetSurfaceDimension },
-        { "SetSurfaceOpacity",                &GenericCommunicator::SetSurfaceOpacity },
-        { "SetLayerOpacity",                  &GenericCommunicator::SetLayerOpacity },
-        { "SetSurfacegroupOpacity",           &GenericCommunicator::SetSurfacegroupOpacity },
-        { "SetLayergroupOpacity",             &GenericCommunicator::SetLayergroupOpacity },
-        { "GetSurfaceOpacity",                &GenericCommunicator::GetSurfaceOpacity },
-        { "GetLayerOpacity",                  &GenericCommunicator::GetLayerOpacity },
-        { "SetSurfaceOrientation",            &GenericCommunicator::SetSurfaceOrientation },
-        { "GetSurfaceOrientation",            &GenericCommunicator::GetSurfaceOrientation },
-        { "SetLayerOrientation",              &GenericCommunicator::SetLayerOrientation },
-        { "GetLayerOrientation",              &GenericCommunicator::GetLayerOrientation },
-        { "GetSurfacePixelformat",            &GenericCommunicator::GetSurfacePixelformat },
-        { "SetSurfaceVisibility",             &GenericCommunicator::SetSurfaceVisibility },
-        { "SetLayerVisibility",               &GenericCommunicator::SetLayerVisibility },
-        { "GetSurfaceVisibility",             &GenericCommunicator::GetSurfaceVisibility },
-        { "GetLayerVisibility",               &GenericCommunicator::GetLayerVisibility },
-        { "SetSurfacegroupVisibility",        &GenericCommunicator::SetSurfacegroupVisibility },
-        { "SetLayergroupVisibility",          &GenericCommunicator::SetLayergroupVisibility },
-        { "SetRenderOrderOfLayers",           &GenericCommunicator::SetRenderOrderOfLayers },
+        { "ServiceConnect", &GenericCommunicator::ServiceConnect },
+        { "ServiceDisconnect", &GenericCommunicator::ServiceDisconnect },
+        { "Debug", &GenericCommunicator::Debug },
+        { "ScreenShot", &GenericCommunicator::ScreenShot },
+        { "ScreenShotOfLayer", &GenericCommunicator::ScreenShotOfLayer },
+        { "ScreenShotOfSurface", &GenericCommunicator::ScreenShotOfSurface },
+        { "GetScreenResolution", &GenericCommunicator::GetScreenResolution },
+        { "GetNumberOfHardwareLayers", &GenericCommunicator::GetNumberOfHardwareLayers },
+        { "GetScreenIDs", &GenericCommunicator::GetScreenIDs },
+        { "ListAllLayerIDS", &GenericCommunicator::ListAllLayerIDS },
+        { "ListAllLayerIDsOnScreen", &GenericCommunicator::ListAllLayerIDsOnScreen },
+        { "ListAllSurfaceIDS", &GenericCommunicator::ListAllSurfaceIDS },
+        { "ListSurfaceofLayer", &GenericCommunicator::ListSurfaceofLayer },
+        { "GetPropertiesOfSurface", &GenericCommunicator::GetPropertiesOfSurface },
+        { "GetPropertiesOfLayer", &GenericCommunicator::GetPropertiesOfLayer },
+        { "CreateSurface", &GenericCommunicator::CreateSurface },
+        { "CreateSurfaceFromId", &GenericCommunicator::CreateSurfaceFromId },
+        { "InitializeSurface", &GenericCommunicator::InitializeSurface },
+        { "InitializeSurfaceFromId", &GenericCommunicator::InitializeSurfaceFromId },
+        { "SetSurfaceNativeContent", &GenericCommunicator::SetSurfaceNativeContent },
+        { "RemoveSurfaceNativeContent", &GenericCommunicator::RemoveSurfaceNativeContent },
+        { "RemoveSurface", &GenericCommunicator::RemoveSurface },
+        { "CreateLayer", &GenericCommunicator::CreateLayer },
+        { "CreateLayerFromId", &GenericCommunicator::CreateLayerFromId },
+        { "CreateLayerWithDimension", &GenericCommunicator::CreateLayerWithDimension },
+        { "CreateLayerFromIdWithDimension", &GenericCommunicator::CreateLayerFromIdWithDimension },
+        { "RemoveLayer", &GenericCommunicator::RemoveLayer },
+        { "AddSurfaceToLayer", &GenericCommunicator::AddSurfaceToLayer },
+        { "RemoveSurfaceFromLayer", &GenericCommunicator::RemoveSurfaceFromLayer },
+        { "SetSurfaceSourceRegion", &GenericCommunicator::SetSurfaceSourceRegion },
+        { "SetLayerSourceRegion", &GenericCommunicator::SetLayerSourceRegion },
+        { "SetSurfaceDestinationRegion", &GenericCommunicator::SetSurfaceDestinationRegion },
+        { "SetSurfacePosition", &GenericCommunicator::SetSurfacePosition },
+        { "GetSurfacePosition", &GenericCommunicator::GetSurfacePosition },
+        { "SetSurfaceDimension", &GenericCommunicator::SetSurfaceDimension },
+        { "SetLayerDestinationRegion", &GenericCommunicator::SetLayerDestinationRegion },
+        { "SetLayerPosition", &GenericCommunicator::SetLayerPosition },
+        { "GetLayerPosition", &GenericCommunicator::GetLayerPosition },
+        { "SetLayerDimension", &GenericCommunicator::SetLayerDimension },
+        { "GetLayerDimension", &GenericCommunicator::GetLayerDimension },
+        { "GetSurfaceDimension", &GenericCommunicator::GetSurfaceDimension },
+        { "SetSurfaceOpacity", &GenericCommunicator::SetSurfaceOpacity },
+        { "SetLayerOpacity", &GenericCommunicator::SetLayerOpacity },
+        { "GetSurfaceOpacity", &GenericCommunicator::GetSurfaceOpacity },
+        { "GetLayerOpacity", &GenericCommunicator::GetLayerOpacity },
+        { "SetSurfaceOrientation", &GenericCommunicator::SetSurfaceOrientation },
+        { "GetSurfaceOrientation", &GenericCommunicator::GetSurfaceOrientation },
+        { "SetLayerOrientation", &GenericCommunicator::SetLayerOrientation },
+        { "GetLayerOrientation", &GenericCommunicator::GetLayerOrientation },
+        { "GetSurfacePixelformat", &GenericCommunicator::GetSurfacePixelformat },
+        { "SetSurfaceVisibility", &GenericCommunicator::SetSurfaceVisibility },
+        { "SetLayerVisibility", &GenericCommunicator::SetLayerVisibility },
+        { "GetSurfaceVisibility", &GenericCommunicator::GetSurfaceVisibility },
+        { "GetLayerVisibility", &GenericCommunicator::GetLayerVisibility },
+        { "SetRenderOrderOfLayers", &GenericCommunicator::SetRenderOrderOfLayers },
         { "SetSurfaceRenderOrderWithinLayer", &GenericCommunicator::SetSurfaceRenderOrderWithinLayer },
-        { "GetLayerType",                     &GenericCommunicator::GetLayerType },
-        { "GetLayertypeCapabilities",         &GenericCommunicator::GetLayertypeCapabilities },
-        { "GetLayerCapabilities",             &GenericCommunicator::GetLayerCapabilities },
-        { "Exit",                             &GenericCommunicator::Exit },
-        { "CommitChanges",                    &GenericCommunicator::CommitChanges },
-        { "CreateShader",                     &GenericCommunicator::CreateShader },
-        { "DestroyShader",                    &GenericCommunicator::DestroyShader },
-        { "SetShader",                        &GenericCommunicator::SetShader },
-        { "SetUniforms",                      &GenericCommunicator::SetUniforms },
-        { "SetKeyboardFocusOn",               &GenericCommunicator::SetKeyboardFocusOn },
-        { "GetKeyboardFocusSurfaceId",        &GenericCommunicator::GetKeyboardFocusSurfaceId },
-        { "UpdateInputEventAcceptanceOn",     &GenericCommunicator::UpdateInputEventAcceptanceOn },
-        { "SetSurfaceChromaKey",              &GenericCommunicator::SetSurfaceChromaKey },
-        { "SetLayerChromaKey",                &GenericCommunicator::SetLayerChromaKey },
-        { "LayerAddNotification",             &GenericCommunicator::LayerAddNotification },
-        { "SurfaceAddNotification",           &GenericCommunicator::SurfaceAddNotification },
-        { "LayerRemoveNotification",          &GenericCommunicator::LayerRemoveNotification },
-        { "SurfaceRemoveNotification",        &GenericCommunicator::SurfaceRemoveNotification }
+        { "GetLayerType", &GenericCommunicator::GetLayerType },
+        { "GetLayertypeCapabilities", &GenericCommunicator::GetLayertypeCapabilities },
+        { "GetLayerCapabilities", &GenericCommunicator::GetLayerCapabilities },
+        { "Exit", &GenericCommunicator::Exit },
+        { "CommitChanges", &GenericCommunicator::CommitChanges },
+        { "CreateShader", &GenericCommunicator::CreateShader },
+        { "DestroyShader", &GenericCommunicator::DestroyShader },
+        { "SetShader", &GenericCommunicator::SetShader },
+        { "SetUniforms", &GenericCommunicator::SetUniforms },
+        { "SetKeyboardFocusOn", &GenericCommunicator::SetKeyboardFocusOn },
+        { "GetKeyboardFocusSurfaceId", &GenericCommunicator::GetKeyboardFocusSurfaceId },
+        { "UpdateInputEventAcceptanceOn", &GenericCommunicator::UpdateInputEventAcceptanceOn },
+        { "SetSurfaceChromaKey", &GenericCommunicator::SetSurfaceChromaKey },
+        { "SetLayerChromaKey", &GenericCommunicator::SetLayerChromaKey },
+        { "LayerAddNotification", &GenericCommunicator::LayerAddNotification },
+        { "SurfaceAddNotification", &GenericCommunicator::SurfaceAddNotification },
+        { "LayerRemoveNotification", &GenericCommunicator::LayerRemoveNotification },
+        { "SurfaceRemoveNotification", &GenericCommunicator::SurfaceRemoveNotification },
+        { "SetOptimizationMode", &GenericCommunicator::SetOptimizationMode },
+        { "GetOptimizationMode", &GenericCommunicator::GetOptimizationMode },
+        { "GetPropertiesOfScreen", &GenericCommunicator::GetPropertiesOfScreen },
+        { "SetSynchronizedSurfaces", &GenericCommunicator::SetSynchronizedSurfaces },
+        { "RemoveSynchronizedSurfaces", &GenericCommunicator::RemoveSynchronizedSurfaces }
     };
 
     int entryCount = sizeof(manager_methods) / sizeof(MethodTable);
@@ -213,6 +191,8 @@ GenericCommunicator::GenericCommunicator(ICommandExecutor* executor)
     }
 
     memset(&m_ipcModule, 0, sizeof(m_ipcModule));
+
+    mThreadId = pthread_self();
 }
 
 bool GenericCommunicator::start()
@@ -234,18 +214,26 @@ bool GenericCommunicator::start()
     LOG_DEBUG("GenericCommunicator", "Initializing IpcModule success.");
 
     m_running = ILM_TRUE;
+    pluginSetHealth(HealthRunning);
+
+    threadCreate();
+    threadInit();
+    threadStart();
 
     return ILM_TRUE;
 }
 
 void GenericCommunicator::stop()
 {
-    LOG_INFO("GenericCommunicator","stopping");
+    LOG_INFO("GenericCommunicator", "stopping");
+
+    threadStop();
 
     if (m_running)
     {
         m_ipcModule.destroy();
     }
+    pluginSetHealth(HealthStopped);
 }
 
 void GenericCommunicator::process(int timeout_ms)
@@ -258,34 +246,39 @@ void GenericCommunicator::process(int timeout_ms)
 
     t_ilm_message_type messageType = m_ipcModule.getMessageType(message);
     t_ilm_const_string name = m_ipcModule.getMessageName(message);
-    t_ilm_const_string sender = m_ipcModule.getSenderName(message);
     t_ilm_client_handle senderHandle = m_ipcModule.getSenderHandle(message);
 
-    switch(messageType)
+    switch (messageType)
     {
     case IpcMessageTypeCommand:
         if (m_callBackTable.end() != m_callBackTable.find(name))
         {
-            LOG_DEBUG("GenericCommunicator", "Received command " << name << " from " << sender);
+            LOG_DEBUG("GenericCommunicator", "received: " << name << " from "
+                        << m_executor->getSenderName(senderHandle)
+                        << "(" << m_executor->getSenderPid(senderHandle) << ")");
             CallBackMethod method = m_callBackTable[name].function;
             (this->*method)(message);
         }
         else
         {
-            LOG_WARNING("GenericCommunicator", "Received unknown command " << name << " from " << sender);
+            LOG_WARNING("GenericCommunicator", "Received unknown command " << name
+                    << " from " << m_executor->getSenderName(senderHandle)
+                    << "(pid " << m_executor->getSenderPid(senderHandle) << ")");
         }
         processNotificationQueue();
         break;
 
     case IpcMessageTypeConnect:
-        LOG_DEBUG("GenericCommunicator", "client " << sender << " connected");
+        LOG_DEBUG("GenericCommunicator", "client " << m_executor->getSenderName(senderHandle)
+                    << "(pid " << m_executor->getSenderPid(senderHandle) << ") connected");
         break;
 
     case IpcMessageTypeDisconnect:
-        LOG_DEBUG("GenericCommunicator", "client " << sender << " disconnected");
+        LOG_DEBUG("GenericCommunicator", "client " << m_executor->getSenderName(senderHandle)
+                    << "(pid " << m_executor->getSenderPid(senderHandle) << ") disconnected");
         {
             const LayerMap& layers = m_executor->getScene()->getAllLayers();
-            LayerMapConstIterator layerIter =  layers.begin();
+            LayerMapConstIterator layerIter = layers.begin();
             LayerMapConstIterator layerIterEnd = layers.end();
             for (; layerIter != layerIterEnd; ++layerIter)
             {
@@ -294,18 +287,21 @@ void GenericCommunicator::process(int timeout_ms)
             }
 
             const SurfaceMap& surfaces = m_executor->getScene()->getAllSurfaces();
-            SurfaceMapConstIterator surfaceIter =  surfaces.begin();
+            SurfaceMapConstIterator surfaceIter = surfaces.begin();
             SurfaceMapConstIterator surfaceIterEnd = surfaces.end();
             for (; surfaceIter != surfaceIterEnd; ++surfaceIter)
             {
                 Surface* surface = surfaceIter->second;
                 surface->removeNotification(senderHandle);
             }
+            m_executor->removeApplicationReference(senderHandle);
         }
         break;
 
     case IpcMessageTypeError:
-        LOG_DEBUG("GenericCommunicator", "Received error message " << name << " from " << sender);
+        LOG_DEBUG("GenericCommunicator", "Received error message " << name << " from "
+                    << m_executor->getSenderName(senderHandle)
+                    << "(pid " << m_executor->getSenderPid(senderHandle) << ")");
         break;
 
     case IpcMessageTypeShutdown:
@@ -314,7 +310,8 @@ void GenericCommunicator::process(int timeout_ms)
 
     default:
         LOG_DEBUG("GenericCommunicator", "Received unknown data from "
-                  << sender << "(Message type: " << messageType << ")");
+                    << m_executor->getSenderName(senderHandle)
+                    << "(pid " << m_executor->getSenderPid(senderHandle) << "), Message type: " << messageType);
         break;
     }
     m_ipcModule.destroyMessage(message);
@@ -325,18 +322,32 @@ void GenericCommunicator::setdebug(bool onoff)
     (void)onoff; // TODO: remove, only prevents warning
 }
 
-void GenericCommunicator::ServiceConnect(t_ilm_message message)
+t_ilm_bool GenericCommunicator::threadMainLoop()
+{
+    process(-1);
+    return ILM_TRUE;
+}
+
+t_ilm_const_string GenericCommunicator::pluginGetName() const
 {
-    LOG_DEBUG("GenericCommunicator", "ServiceConnect called");
+    return "GenericCommunicator";
+}
 
+void GenericCommunicator::ServiceConnect(t_ilm_message message)
+{
     t_ilm_message response;
     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    unsigned int processId = 0;
 
+    unsigned int processId = 0;
+    char processName[1024];
     m_ipcModule.getUint(message, &processId);
-    char* owner = strdup(m_ipcModule.getSenderName(message));
+    m_ipcModule.getString(message, processName);
 
-    m_executor->addApplicationReference(new IApplicationReference(owner,processId));
+    m_executor->addApplicationReference(clientHandle, new IApplicationReference(processName, processId));
+
+    LOG_DEBUG("GenericCommunicator", "ServiceConnect called from "
+                << m_executor->getSenderName(clientHandle)
+                << "(" << m_executor->getSenderPid(clientHandle) << ")");
 
     response = m_ipcModule.createResponse(message);
     m_ipcModule.sendToClients(response, &clientHandle, 1);
@@ -345,22 +356,14 @@ void GenericCommunicator::ServiceConnect(t_ilm_message message)
 
 void GenericCommunicator::ServiceDisconnect(t_ilm_message message)
 {
-    LOG_DEBUG("GenericCommunicator", "ServiceDisconnect called");
-
     t_ilm_message response;
     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    char* owner = strdup(m_ipcModule.getSenderName(message));
-    long int ownerHash = IApplicationReference::generateApplicationHash(owner);
-    ApplicationReferenceMap* refmap = m_executor->getApplicationReferenceMap();
 
-    ApplicationReferenceMapIterator iter = refmap->find(ownerHash);
-    ApplicationReferenceMapIterator iterEnd = refmap->end();
+    LOG_DEBUG("GenericCommunicator", "ServiceDisconnect called from "
+                << m_executor->getSenderName(clientHandle)
+                << "(" << m_executor->getSenderPid(clientHandle) << ")");
 
-    for (; iter != iterEnd; ++iter)
-    {
-        IApplicationReference* registeredApp = (*iter).second;
-        m_executor->removeApplicationReference(registeredApp);
-    }
+    m_executor->removeApplicationReference(clientHandle);
 
     response = m_ipcModule.createResponse(message);
     m_ipcModule.sendToClients(response, &clientHandle, 1);
@@ -371,20 +374,23 @@ void GenericCommunicator::Debug(t_ilm_message message)
 {
     t_ilm_message response;
     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     t_ilm_bool param = ILM_FALSE;
     m_ipcModule.getBool(message, &param);
 
-    t_ilm_bool status = m_executor->execute(new DebugCommand(param));
+    t_ilm_bool status = m_executor->execute(new DebugCommand(clientPid, param));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, INVALID_ARGUMENT);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_INVALID_ARGUMENTS);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::GetScreenResolution(t_ilm_message message)
@@ -398,33 +404,42 @@ void GenericCommunicator::GetScreenResolution(t_ilm_message message)
     response = m_ipcModule.createResponse(message);
     m_ipcModule.appendUint(response, resolution[0]);
     m_ipcModule.appendUint(response, resolution[1]);
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
+
+    delete [] resolution;
 }
 
 void GenericCommunicator::GetNumberOfHardwareLayers(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
     uint screenid = 0;
     m_ipcModule.getUint(message, &screenid);
     uint numberOfHardwareLayers = m_executor->getNumberOfHardwareLayers(screenid);
     response = m_ipcModule.createResponse(message);
     m_ipcModule.appendUint(response, numberOfHardwareLayers);
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::GetScreenIDs(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
     uint length = 0;
     uint* IDs = m_executor->getScreenIDs(&length);
     response = m_ipcModule.createResponse(message);
     m_ipcModule.appendUintArray(response, IDs, length);
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
+    delete [] IDs;
 }
 
 void GenericCommunicator::ScreenShot(t_ilm_message message)
 {
     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     t_ilm_message response;
     uint screenid = 0;
     char filename[1024];
@@ -432,7 +447,7 @@ void GenericCommunicator::ScreenShot(t_ilm_message message)
     m_ipcModule.getUint(message, &screenid);
     m_ipcModule.getString(message, filename);
 
-    t_ilm_bool status = m_executor->execute(new ScreenDumpCommand(filename, screenid));
+    t_ilm_bool status = m_executor->execute(new ScreenDumpCommand(clientPid, filename, screenid));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
@@ -440,7 +455,7 @@ void GenericCommunicator::ScreenShot(t_ilm_message message)
     else
     {
         response = m_ipcModule.createErrorResponse(message);
-        m_ipcModule.appendString(response, INVALID_ARGUMENT);
+        m_ipcModule.appendUint(response, ILM_ERROR_INVALID_ARGUMENTS);
     }
 
     m_ipcModule.sendToClients(response, &clientHandle, 1);
@@ -449,48 +464,57 @@ void GenericCommunicator::ScreenShot(t_ilm_message message)
 
 void GenericCommunicator::ScreenShotOfLayer(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     char filename[1024];
     m_ipcModule.getString(message, filename);
     uint layerid = 0;
     m_ipcModule.getUint(message, &layerid);
 
-    t_ilm_bool status = m_executor->execute(new LayerDumpCommand(filename, layerid));
+    t_ilm_bool status = m_executor->execute(new LayerDumpCommand(clientPid, filename, layerid));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::ScreenShotOfSurface(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     char filename[1024];
     m_ipcModule.getString(message, filename);
     uint id = 0;
     m_ipcModule.getUint(message, &id);
-    t_ilm_bool status = m_executor->execute(new SurfaceDumpCommand(filename, id));
+    t_ilm_bool status = m_executor->execute(new SurfaceDumpCommand(clientPid, filename, id));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::ListAllLayerIDS(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
     uint* array = NULL;
     uint length = 0;
     m_executor->getScene()->lockScene();
@@ -498,12 +522,14 @@ void GenericCommunicator::ListAllLayerIDS(t_ilm_message message)
     m_executor->getScene()->unlockScene();
     response = m_ipcModule.createResponse(message);
     m_ipcModule.appendUintArray(response, array, length);
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::ListAllLayerIDsOnScreen(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
     uint screenID = 0;
     m_ipcModule.getUint(message, &screenID);
 
@@ -519,15 +545,20 @@ void GenericCommunicator::ListAllLayerIDsOnScreen(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, INVALID_ARGUMENT);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_INVALID_ARGUMENTS);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
+
+    delete [] array;
 }
 
 void GenericCommunicator::ListAllSurfaceIDS(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
     uint* array = NULL;
     uint length = 0;
     m_executor->getScene()->lockScene();
@@ -535,107 +566,14 @@ void GenericCommunicator::ListAllSurfaceIDS(t_ilm_message message)
     m_executor->getScene()->unlockScene();
     response = m_ipcModule.createResponse(message);
     m_ipcModule.appendUintArray(response, array, length);
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
-}
-
-void GenericCommunicator::ListAllLayerGroupIDS(t_ilm_message message)
-{
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    uint* array = NULL;
-    uint length = 0;
-    m_executor->getScene()->lockScene();
-    m_executor->getScene()->getLayerGroupIDs(&length, &array);
-    m_executor->getScene()->unlockScene();
-    response = m_ipcModule.createResponse(message);
-    m_ipcModule.appendUintArray(response, array, length);
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
-}
-
-void GenericCommunicator::ListAllSurfaceGroupIDS(t_ilm_message message)
-{
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    uint* array = NULL;
-    uint length = 0;
-    m_executor->getScene()->lockScene();
-    m_executor->getScene()->getSurfaceGroupIDs(&length, &array);
-    m_executor->getScene()->unlockScene();
-    response = m_ipcModule.createResponse(message);
-    m_ipcModule.appendUintArray(response, array, length);
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
-}
-
-void GenericCommunicator::ListSurfacesOfSurfacegroup(t_ilm_message message)
-{
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    uint id = 0;
-    m_ipcModule.getUint(message, &id);
-    m_executor->getScene()->lockScene();
-    SurfaceGroup* sg = m_executor->getScene()->getSurfaceGroup(id);
-    if (NULL != sg)
-    {
-        std::list<Surface*> surfaces = sg->getList();
-        uint length = surfaces.size();
-        uint* array = new uint[length];
-        uint arrayPos = 0;
-
-        for (std::list<Surface*>::const_iterator it = surfaces.begin(); it != surfaces.end(); ++it)
-        {
-            Surface* s = *it;
-            array[arrayPos] = s->getID();
-            ++arrayPos;
-        }
-        m_executor->getScene()->unlockScene();
-
-        response = m_ipcModule.createResponse(message);
-        m_ipcModule.appendUintArray(response, array, length);
-    }
-    else
-    {
-        m_executor->getScene()->unlockScene();
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
-    }
-
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
-}
-
-void GenericCommunicator::ListLayersOfLayergroup(t_ilm_message message)
-{
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    uint id = 0;
-    m_ipcModule.getUint(message, &id);
-    m_executor->getScene()->lockScene();
-    LayerGroup* sg = m_executor->getScene()->getLayerGroup(id);
-    if (NULL != sg)
-    {
-        std::list<Layer*> layers = sg->getList();
-
-        uint length = layers.size();
-        uint* array = new uint[length];
-        uint arrayPos = 0;
-
-        for (std::list<Layer*>::const_iterator it = layers.begin(); it != layers.end(); ++it)
-        {
-            Layer* l = *it;
-            array[arrayPos] = l->getID();
-            ++arrayPos;
-        }
-        m_executor->getScene()->unlockScene();
-
-        response = m_ipcModule.createResponse(message);
-        m_ipcModule.appendUintArray(response, array, length);
-    }
-    else
-    {
-        m_executor->getScene()->unlockScene();
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
-    }
-
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::ListSurfaceofLayer(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
     uint id = 0;
     m_ipcModule.getUint(message, &id);
     m_executor->getScene()->lockScene();
@@ -658,19 +596,23 @@ void GenericCommunicator::ListSurfaceofLayer(t_ilm_message message)
 
         response = m_ipcModule.createResponse(message);
         m_ipcModule.appendUintArray(response, array, length);
+        delete [] array;
     }
     else
     {
         m_executor->getScene()->unlockScene();
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::GetPropertiesOfSurface(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
     uint id = 0;
     m_ipcModule.getUint(message, &id);
 
@@ -709,18 +651,22 @@ void GenericCommunicator::GetPropertiesOfSurface(t_ilm_message message)
         m_ipcModule.appendUint(response, chromaKeyRed);
         m_ipcModule.appendUint(response, chromaKeyGreen);
         m_ipcModule.appendUint(response, chromaKeyBlue);
+        m_ipcModule.appendInt(response, surface->getCreatorPid());
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::GetPropertiesOfLayer(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
     uint id = 0;
     m_ipcModule.getUint(message, &id);
 
@@ -754,18 +700,23 @@ void GenericCommunicator::GetPropertiesOfLayer(t_ilm_message message)
         m_ipcModule.appendUint(response, chromaKeyRed);
         m_ipcModule.appendUint(response, chromaKeyGreen);
         m_ipcModule.appendUint(response, chromaKeyBlue);
+        m_ipcModule.appendInt(response, layer->getCreatorPid());
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::CreateSurface(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint handle = 0;
     uint width = 0;
     uint height = 0;
@@ -780,12 +731,11 @@ void GenericCommunicator::CreateSurface(t_ilm_message message)
 
     pf = (PixelFormat) pixelformat;
 
-
     // First of all create the surface
-    t_ilm_bool status = m_executor->execute(new SurfaceCreateCommand(&id));
+    t_ilm_bool status = m_executor->execute(new SurfaceCreateCommand(clientPid, &id));
 
     // after that apply the native content
-    status &= m_executor->execute(new SurfaceSetNativeContentCommand(id, handle, pf, width, height));
+    status &= m_executor->execute(new SurfaceSetNativeContentCommand(clientPid, id, handle, pf, width, height));
 
     if (status)
     {
@@ -794,15 +744,19 @@ void GenericCommunicator::CreateSurface(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_ALREADY_INUSE);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::CreateSurfaceFromId(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint handle = 0;
     uint width = 0;
     uint height = 0;
@@ -819,10 +773,10 @@ void GenericCommunicator::CreateSurfaceFromId(t_ilm_message message)
     pf = (PixelFormat) pixelformat;
 
     // First of all create the surface
-    t_ilm_bool status = m_executor->execute(new SurfaceCreateCommand(&id));
+    t_ilm_bool status = m_executor->execute(new SurfaceCreateCommand(clientPid, &id));
 
     // after that apply the native content
-    status &= m_executor->execute(new SurfaceSetNativeContentCommand(id, handle, pf, width, height));
+    status &= m_executor->execute(new SurfaceSetNativeContentCommand(clientPid, id, handle, pf, width, height));
 
     if (status)
     {
@@ -831,18 +785,22 @@ void GenericCommunicator::CreateSurfaceFromId(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_ALREADY_INUSE);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::InitializeSurface(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = GraphicalObject::INVALID_ID;
 
-    t_ilm_bool status = m_executor->execute(new SurfaceCreateCommand(&id));
+    t_ilm_bool status = m_executor->execute(new SurfaceCreateCommand(clientPid, &id));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
@@ -850,18 +808,22 @@ void GenericCommunicator::InitializeSurface(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_ALREADY_INUSE);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::InitializeSurfaceFromId(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = 0;
     m_ipcModule.getUint(message, &id);
-    t_ilm_bool status = m_executor->execute(new SurfaceCreateCommand(&id));
+    t_ilm_bool status = m_executor->execute(new SurfaceCreateCommand(clientPid, &id));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
@@ -869,15 +831,19 @@ void GenericCommunicator::InitializeSurfaceFromId(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_ALREADY_INUSE);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::SetSurfaceNativeContent(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = 0;
     uint handle = 0;
     uint width = 0;
@@ -893,63 +859,75 @@ void GenericCommunicator::SetSurfaceNativeContent(t_ilm_message message)
 
     pf = (PixelFormat) pixelformat;
 
-    t_ilm_bool status = m_executor->execute(new SurfaceSetNativeContentCommand(id, handle, pf, width, height));
+    t_ilm_bool status = m_executor->execute(new SurfaceSetNativeContentCommand(clientPid, id, handle, pf, width, height));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_ALREADY_INUSE);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::RemoveSurfaceNativeContent(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = 0;
     m_ipcModule.getUint(message, &id);
 
-    t_ilm_bool status = m_executor->execute(new SurfaceRemoveNativeContentCommand(id));
+    t_ilm_bool status = m_executor->execute(new SurfaceRemoveNativeContentCommand(clientPid, id));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_ALREADY_INUSE);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::RemoveSurface(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint param = 0;
     m_ipcModule.getUint(message, &param);
-    t_ilm_bool status = m_executor->execute(new SurfaceRemoveCommand(param));
+    t_ilm_bool status = m_executor->execute(new SurfaceRemoveCommand(clientPid, param));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_ALREADY_INUSE);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::CreateLayer(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = GraphicalObject::INVALID_ID;
     // use resolution of default screen as default width and height of layers
     uint* resolution = m_executor->getScreenResolution(DEFAULT_SCREEN);
-    t_ilm_bool status = m_executor->execute(new LayerCreateCommand(resolution[0], resolution[1], &id));
+    t_ilm_bool status = m_executor->execute(new LayerCreateCommand(clientPid, resolution[0], resolution[1], &id));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
@@ -957,21 +935,25 @@ void GenericCommunicator::CreateLayer(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_ALREADY_INUSE);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::CreateLayerFromId(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = GraphicalObject::INVALID_ID;
 
     m_ipcModule.getUint(message, &id);
     // use resolution of default screen as default width and height of layers
     uint* resolution = m_executor->getScreenResolution(DEFAULT_SCREEN);
-    t_ilm_bool status = m_executor->execute(new LayerCreateCommand(resolution[0], resolution[1], &id));
+    t_ilm_bool status = m_executor->execute(new LayerCreateCommand(clientPid, resolution[0], resolution[1], &id));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
@@ -979,23 +961,29 @@ void GenericCommunicator::CreateLayerFromId(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_ALREADY_INUSE);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
+
+    delete [] resolution;
 }
 
 
 void GenericCommunicator::CreateLayerWithDimension(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint width = 0;
     m_ipcModule.getUint(message, &width);
     uint height = 0;
     m_ipcModule.getUint(message, &height);
 
     uint id = GraphicalObject::INVALID_ID;
-    t_ilm_bool status = m_executor->execute(new LayerCreateCommand(width, height, &id));
+    t_ilm_bool status = m_executor->execute(new LayerCreateCommand(clientPid, width, height, &id));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
@@ -1003,15 +991,19 @@ void GenericCommunicator::CreateLayerWithDimension(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::CreateLayerFromIdWithDimension(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = GraphicalObject::INVALID_ID;
     uint width = 0;
     uint height = 0;
@@ -1021,7 +1013,7 @@ void GenericCommunicator::CreateLayerFromIdWithDimension(t_ilm_message message)
     m_ipcModule.getUint(message, &width);
     m_ipcModule.getUint(message, &height);
 
-    status = m_executor->execute(new LayerCreateCommand(width, height, &id));
+    status = m_executor->execute(new LayerCreateCommand(clientPid, width, height, &id));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
@@ -1029,338 +1021,156 @@ void GenericCommunicator::CreateLayerFromIdWithDimension(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_ALREADY_INUSE);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::RemoveLayer(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint param = 0;
     m_ipcModule.getUint(message, &param);
-    t_ilm_bool status = m_executor->execute(new LayerRemoveCommand(param));
+    t_ilm_bool status = m_executor->execute(new LayerRemoveCommand(clientPid, param));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
-void GenericCommunicator::AddSurfaceToSurfaceGroup(t_ilm_message message)
+void GenericCommunicator::AddSurfaceToLayer(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint surfaceid = 0;
-    uint surfacegroupid = 0;
+    uint layer = 0;
 
     m_ipcModule.getUint(message, &surfaceid);
-    m_ipcModule.getUint(message, &surfacegroupid);
+    m_ipcModule.getUint(message, &layer);
 
-    t_ilm_bool status = m_executor->execute(new SurfacegroupAddSurfaceCommand(surfacegroupid, surfaceid));
+    t_ilm_bool status = m_executor->execute(new LayerAddSurfaceCommand(clientPid, layer, surfaceid));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_ALREADY_INUSE);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
-void GenericCommunicator::RemoveSurfaceFromSurfaceGroup(t_ilm_message message)
+void GenericCommunicator::RemoveSurfaceFromLayer(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint surfaceid = 0;
-    uint surfacegroupid = 0;
-
+    uint layerid = 0;
     m_ipcModule.getUint(message, &surfaceid);
-    m_ipcModule.getUint(message, &surfacegroupid);
+    m_ipcModule.getUint(message, &layerid);
 
-    t_ilm_bool status = m_executor->execute(new SurfacegroupRemoveSurfaceCommand(surfacegroupid, surfaceid));
+    t_ilm_bool status = m_executor->execute(new LayerRemoveSurfaceCommand(clientPid, layerid, surfaceid));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
-void GenericCommunicator::AddLayerToLayerGroup(t_ilm_message message)
+void GenericCommunicator::SetSurfaceSourceRegion(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    uint layerid = 0;
-    uint layergroupid = 0;
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
+    uint id = 0;
+    uint x = 0;
+    uint y = 0;
+    uint width = 0;
+    uint height = 0;
 
-    m_ipcModule.getUint(message, &layerid);
-    m_ipcModule.getUint(message, &layergroupid);
+    m_ipcModule.getUint(message, &id);
+    m_ipcModule.getUint(message, &x);
+    m_ipcModule.getUint(message, &y);
+    m_ipcModule.getUint(message, &width);
+    m_ipcModule.getUint(message, &height);
 
-    t_ilm_bool status = m_executor->execute(new LayergroupAddLayerCommand(layergroupid, layerid));
+    t_ilm_bool status = m_executor->execute(new SurfaceSetSourceRectangleCommand(clientPid, id, x, y, width, height));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
-void GenericCommunicator::RemoveLayerFromLayerGroup(t_ilm_message message)
+void GenericCommunicator::SetLayerSourceRegion(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    uint layerid = 0;
-    uint layergroupid = 0;
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
+    uint id = 0;
+    uint x = 0;
+    uint y = 0;
+    uint width = 0;
+    uint height = 0;
 
-    m_ipcModule.getUint(message, &layerid);
-    m_ipcModule.getUint(message, &layergroupid);
+    m_ipcModule.getUint(message, &id);
+    m_ipcModule.getUint(message, &x);
+    m_ipcModule.getUint(message, &y);
+    m_ipcModule.getUint(message, &width);
+    m_ipcModule.getUint(message, &height);
 
-    t_ilm_bool status = m_executor->execute(new LayergroupRemoveLayerCommand(layergroupid, layerid));
+    t_ilm_bool status = m_executor->execute(new LayerSetSourceRectangleCommand(clientPid, id, x, y, width, height));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
-}
-
-void GenericCommunicator::AddSurfaceToLayer(t_ilm_message message)
-{
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    uint surfaceid = 0;
-    uint layer = 0;
-
-    m_ipcModule.getUint(message, &surfaceid);
-    m_ipcModule.getUint(message, &layer);
-
-    t_ilm_bool status = m_executor->execute(new LayerAddSurfaceCommand(layer, surfaceid));
-    if (status)
-    {
-        response = m_ipcModule.createResponse(message);
-    }
-    else
-    {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
-    }
-
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
-}
-
-void GenericCommunicator::RemoveSurfaceFromLayer(t_ilm_message message)
-{
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    uint surfaceid = 0;
-    uint layerid = 0;
-    m_ipcModule.getUint(message, &surfaceid);
-    m_ipcModule.getUint(message, &layerid);
-
-    t_ilm_bool status = m_executor->execute(new LayerRemoveSurfaceCommand(layerid, surfaceid));
-    if (status)
-    {
-        response = m_ipcModule.createResponse(message);
-    }
-    else
-    {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
-    }
-
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
-}
-
-void GenericCommunicator::CreateSurfaceGroup(t_ilm_message message)
-{
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    uint newID = GraphicalObject::INVALID_ID;
-
-    t_ilm_bool status = m_executor->execute(new SurfacegroupCreateCommand(&newID));
-    if (status)
-    {
-        response = m_ipcModule.createResponse(message);
-        m_ipcModule.appendUint(response, newID);
-    }
-    else
-    {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
-    }
-
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
-}
-
-void GenericCommunicator::CreateSurfaceGroupFromId(t_ilm_message message)
-{
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    uint newID = GraphicalObject::INVALID_ID;
-
-    m_ipcModule.getUint(message, &newID);
-
-    t_ilm_bool status = m_executor->execute(new SurfacegroupCreateCommand(&newID));
-    if (status)
-    {
-        response = m_ipcModule.createResponse(message);
-        m_ipcModule.appendUint(response, newID);
-    }
-    else
-    {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
-    }
-
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
-}
-
-void GenericCommunicator::RemoveSurfaceGroup(t_ilm_message message)
-{
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    uint param = 0;
-    m_ipcModule.getUint(message, &param);
-
-    t_ilm_bool status = m_executor->execute(new SurfacegroupRemoveCommand(param));
-    if (status)
-    {
-        response = m_ipcModule.createResponse(message);
-    }
-    else
-    {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
-    }
-
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
-}
-
-void GenericCommunicator::CreateLayerGroup(t_ilm_message message)
-{
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    uint newID = GraphicalObject::INVALID_ID;
-
-    t_ilm_bool status = m_executor->execute(new LayergroupCreateCommand(&newID));
-    if (status)
-    {
-        response = m_ipcModule.createResponse(message);
-        m_ipcModule.appendUint(response, newID);
-    }
-    else
-    {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
-    }
-
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
-}
-
-void GenericCommunicator::CreateLayerGroupFromId(t_ilm_message message)
-{
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    uint newID = GraphicalObject::INVALID_ID;
-
-    m_ipcModule.getUint(message, &newID);
-
-    t_ilm_bool status = m_executor->execute(new LayergroupCreateCommand(&newID));
-    if (status)
-    {
-        response = m_ipcModule.createResponse(message);
-        m_ipcModule.appendUint(response, newID);
-    }
-    else
-    {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_ALREADY_INUSE);
-    }
-
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
-}
-
-void GenericCommunicator::RemoveLayerGroup(t_ilm_message message)
-{
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    uint param = 0;
-    m_ipcModule.getUint(message, &param);
-
-    t_ilm_bool status = m_executor->execute(new LayergroupRemoveCommand(param));
-    if (status)
-    {
-        response = m_ipcModule.createResponse(message);
-    }
-    else
-    {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
-    }
-
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
-}
-
-void GenericCommunicator::SetSurfaceSourceRegion(t_ilm_message message)
-{
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    uint id = 0;
-    uint x = 0;
-    uint y = 0;
-    uint width = 0;
-    uint height = 0;
-
-    m_ipcModule.getUint(message, &id);
-    m_ipcModule.getUint(message, &x);
-    m_ipcModule.getUint(message, &y);
-    m_ipcModule.getUint(message, &width);
-    m_ipcModule.getUint(message, &height);
-
-    t_ilm_bool status = m_executor->execute(new SurfaceSetSourceRectangleCommand(id, x, y, width, height));
-    if (status)
-    {
-        response = m_ipcModule.createResponse(message);
-    }
-    else
-    {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
-    }
-
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
-}
-
-void GenericCommunicator::SetLayerSourceRegion(t_ilm_message message)
-{
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    uint id = 0;
-    uint x = 0;
-    uint y = 0;
-    uint width = 0;
-    uint height = 0;
-
-    m_ipcModule.getUint(message, &id);
-    m_ipcModule.getUint(message, &x);
-    m_ipcModule.getUint(message, &y);
-    m_ipcModule.getUint(message, &width);
-    m_ipcModule.getUint(message, &height);
-
-    t_ilm_bool status = m_executor->execute(new LayerSetSourceRectangleCommand(id, x, y, width, height));
-    if (status)
-    {
-        response = m_ipcModule.createResponse(message);
-    }
-    else
-    {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
-    }
-
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::SetSurfaceDestinationRegion(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = 0;
     uint x = 0;
     uint y = 0;
@@ -1373,22 +1183,26 @@ void GenericCommunicator::SetSurfaceDestinationRegion(t_ilm_message message)
     m_ipcModule.getUint(message, &width);
     m_ipcModule.getUint(message, &height);
 
-    t_ilm_bool status = m_executor->execute(new SurfaceSetDestinationRectangleCommand(id, x, y, width, height));
+    t_ilm_bool status = m_executor->execute(new SurfaceSetDestinationRectangleCommand(clientPid, id, x, y, width, height));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::SetSurfacePosition(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = 0;
     uint x = 0;
     uint y = 0;
@@ -1397,29 +1211,33 @@ void GenericCommunicator::SetSurfacePosition(t_ilm_message message)
     m_ipcModule.getUint(message, &x);
     m_ipcModule.getUint(message, &y);
 
-    t_ilm_bool status = m_executor->execute(new SurfaceSetPositionCommand(id, x, y));
+    t_ilm_bool status = m_executor->execute(new SurfaceSetPositionCommand(clientPid, id, x, y));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::GetSurfacePosition(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = 0;
     uint x = 0;
     uint y = 0;
 
     m_ipcModule.getUint(message, &id);
 
-    t_ilm_bool status = m_executor->execute(new SurfaceGetPositionCommand(id, &x, &y));
+    t_ilm_bool status = m_executor->execute(new SurfaceGetPositionCommand(clientPid, id, &x, &y));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
@@ -1428,15 +1246,19 @@ void GenericCommunicator::GetSurfacePosition(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::SetSurfaceDimension(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = 0;
     uint width = 0;
     uint height = 0;
@@ -1445,22 +1267,26 @@ void GenericCommunicator::SetSurfaceDimension(t_ilm_message message)
     m_ipcModule.getUint(message, &width);
     m_ipcModule.getUint(message, &height);
 
-    t_ilm_bool status = m_executor->execute(new SurfaceSetDimensionCommand(id, width, height));
+    t_ilm_bool status = m_executor->execute(new SurfaceSetDimensionCommand(clientPid, id, width, height));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::SetLayerDestinationRegion(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = 0;
     uint x = 0;
     uint y = 0;
@@ -1473,22 +1299,26 @@ void GenericCommunicator::SetLayerDestinationRegion(t_ilm_message message)
     m_ipcModule.getUint(message, &width);
     m_ipcModule.getUint(message, &height);
 
-    t_ilm_bool status = m_executor->execute(new LayerSetDestinationRectangleCommand(id, x, y, width, height));
+    t_ilm_bool status = m_executor->execute(new LayerSetDestinationRectangleCommand(clientPid, id, x, y, width, height));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::SetLayerPosition(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = 0;
     uint x = 0;
     uint y = 0;
@@ -1497,29 +1327,33 @@ void GenericCommunicator::SetLayerPosition(t_ilm_message message)
     m_ipcModule.getUint(message, &x);
     m_ipcModule.getUint(message, &y);
 
-    t_ilm_bool status = m_executor->execute(new LayerSetPositionCommand(id, x, y));
+    t_ilm_bool status = m_executor->execute(new LayerSetPositionCommand(clientPid, id, x, y));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::GetLayerPosition(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = 0;
     uint x = 0;
     uint y = 0;
 
     m_ipcModule.getUint(message, &id);
 
-    t_ilm_bool status = m_executor->execute(new LayerGetPositionCommand(id, &x, &y));
+    t_ilm_bool status = m_executor->execute(new LayerGetPositionCommand(clientPid, id, &x, &y));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
@@ -1528,15 +1362,19 @@ void GenericCommunicator::GetLayerPosition(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::SetLayerDimension(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = 0;
     uint width = 0;
     uint height = 0;
@@ -1545,29 +1383,33 @@ void GenericCommunicator::SetLayerDimension(t_ilm_message message)
     m_ipcModule.getUint(message, &width);
     m_ipcModule.getUint(message, &height);
 
-    t_ilm_bool status = m_executor->execute(new LayerSetDimensionCommand(id, width, height));
+    t_ilm_bool status = m_executor->execute(new LayerSetDimensionCommand(clientPid, id, width, height));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::GetLayerDimension(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = 0;
     uint width = 0;
     uint height = 0;
 
     m_ipcModule.getUint(message, &id);
 
-    t_ilm_bool status = m_executor->execute(new LayerGetDimensionCommand(id, &width, &height));
+    t_ilm_bool status = m_executor->execute(new LayerGetDimensionCommand(clientPid, id, &width, &height));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
@@ -1576,22 +1418,26 @@ void GenericCommunicator::GetLayerDimension(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::GetSurfaceDimension(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = 0;
     uint width = 0;
     uint height = 0;
 
     m_ipcModule.getUint(message, &id);
 
-    t_ilm_bool status = m_executor->execute(new SurfaceGetDimensionCommand(id, &width, &height));
+    t_ilm_bool status = m_executor->execute(new SurfaceGetDimensionCommand(clientPid, id, &width, &height));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
@@ -1600,109 +1446,77 @@ void GenericCommunicator::GetSurfaceDimension(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::SetSurfaceOpacity(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = 0;
     double param = 0.0;
 
     m_ipcModule.getUint(message, &id);
     m_ipcModule.getDouble(message, &param);
 
-    t_ilm_bool status = m_executor->execute(new SurfaceSetOpacityCommand(id, param));
+    t_ilm_bool status = m_executor->execute(new SurfaceSetOpacityCommand(clientPid, id, param));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::SetLayerOpacity(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    uint id = 0;
-    double param = 0.0;
-
-    m_ipcModule.getUint(message, &id);
-    m_ipcModule.getDouble(message, &param);
-
-    t_ilm_bool status = m_executor->execute(new LayerSetOpacityCommand(id, param));
-    if (status)
-    {
-        response = m_ipcModule.createResponse(message);
-    }
-    else
-    {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
-    }
-
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
-}
-
-void GenericCommunicator::SetSurfacegroupOpacity(t_ilm_message message)
-{
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    uint id = 0;
-    double param = 0.0;
-
-    m_ipcModule.getUint(message, &id);
-    m_ipcModule.getDouble(message, &param);
-
-    t_ilm_bool status = m_executor->execute(new SurfacegroupSetOpacityCommand(id, param));
-    if (status)
-    {
-        response = m_ipcModule.createResponse(message);
-    }
-    else
-    {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
-    }
-
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
-}
-
-void GenericCommunicator::SetLayergroupOpacity(t_ilm_message message)
-{
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = 0;
     double param = 0.0;
 
     m_ipcModule.getUint(message, &id);
     m_ipcModule.getDouble(message, &param);
 
-    t_ilm_bool status = m_executor->execute(new LayergroupSetOpacityCommand(id, param));
+    t_ilm_bool status = m_executor->execute(new LayerSetOpacityCommand(clientPid, id, param));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::GetSurfaceOpacity(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = 0;
     double param = 0.0;
 
     m_ipcModule.getUint(message, &id);
 
-    t_ilm_bool status = m_executor->execute(new SurfaceGetOpacityCommand(id, &param));
+    t_ilm_bool status = m_executor->execute(new SurfaceGetOpacityCommand(clientPid, id, &param));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
@@ -1710,21 +1524,25 @@ void GenericCommunicator::GetSurfaceOpacity(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::GetLayerOpacity(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = 0;
     double param = 0.0;
 
     m_ipcModule.getUint(message, &id);
 
-    t_ilm_bool status = m_executor->execute(new LayerGetOpacityCommand(id, &param));
+    t_ilm_bool status = m_executor->execute(new LayerGetOpacityCommand(clientPid, id, &param));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
@@ -1732,15 +1550,19 @@ void GenericCommunicator::GetLayerOpacity(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::SetSurfaceOrientation(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = 0;
     uint param = 0;
     OrientationType o = Zero;
@@ -1750,28 +1572,32 @@ void GenericCommunicator::SetSurfaceOrientation(t_ilm_message message)
 
     o = (OrientationType) param;
 
-    t_ilm_bool status = m_executor->execute(new SurfaceSetOrientationCommand(id, o));
+    t_ilm_bool status = m_executor->execute(new SurfaceSetOrientationCommand(clientPid, id, o));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::GetSurfaceOrientation(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = 0;
     OrientationType o;
 
     m_ipcModule.getUint(message, &id);
 
-    t_ilm_bool status = m_executor->execute(new SurfaceGetOrientationCommand(id, &o));
+    t_ilm_bool status = m_executor->execute(new SurfaceGetOrientationCommand(clientPid, id, &o));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
@@ -1779,15 +1605,19 @@ void GenericCommunicator::GetSurfaceOrientation(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::SetLayerOrientation(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = 0;
     uint param = 0;
     OrientationType o = Zero;
@@ -1797,28 +1627,32 @@ void GenericCommunicator::SetLayerOrientation(t_ilm_message message)
 
     o = (OrientationType) param;
 
-    t_ilm_bool status = m_executor->execute(new LayerSetOrientationCommand(id, o));
+    t_ilm_bool status = m_executor->execute(new LayerSetOrientationCommand(clientPid, id, o));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::GetLayerOrientation(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = 0;
     OrientationType o;
 
     m_ipcModule.getUint(message, &id);
 
-    t_ilm_bool status = m_executor->execute(new LayerGetOrientationCommand(id, &o));
+    t_ilm_bool status = m_executor->execute(new LayerGetOrientationCommand(clientPid, id, &o));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
@@ -1826,21 +1660,25 @@ void GenericCommunicator::GetLayerOrientation(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::GetSurfacePixelformat(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = 0;
-    PixelFormat pixelFormat;
+    PixelFormat pixelFormat = (PixelFormat)ILM_PIXEL_FORMAT_UNKNOWN;
 
     m_ipcModule.getUint(message, &id);
 
-    t_ilm_bool status = m_executor->execute(new SurfaceGetPixelformatCommand(id, &pixelFormat));
+    t_ilm_bool status = m_executor->execute(new SurfaceGetPixelformatCommand(clientPid, id, &pixelFormat));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
@@ -1848,65 +1686,77 @@ void GenericCommunicator::GetSurfacePixelformat(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::SetSurfaceVisibility(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint surfaceid = 0;
     t_ilm_bool newVis = ILM_FALSE;
 
     m_ipcModule.getUint(message, &surfaceid);
     m_ipcModule.getBool(message, &newVis);
 
-    t_ilm_bool status = m_executor->execute(new SurfaceSetVisibilityCommand(surfaceid, newVis));
+    t_ilm_bool status = m_executor->execute(new SurfaceSetVisibilityCommand(clientPid, surfaceid, newVis));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::SetLayerVisibility(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint layerid = 0;
     t_ilm_bool myparam = ILM_FALSE;
 
     m_ipcModule.getUint(message, &layerid);
     m_ipcModule.getBool(message, &myparam);
 
-    t_ilm_bool status = m_executor->execute(new LayerSetVisibilityCommand(layerid, myparam));
+    t_ilm_bool status = m_executor->execute(new LayerSetVisibilityCommand(clientPid, layerid, myparam));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::GetSurfaceVisibility(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = 0;
-    bool visibility;
+    bool visibility = false;
 
     m_ipcModule.getUint(message, &id);
 
-    t_ilm_bool status = m_executor->execute(new SurfaceGetVisibilityCommand(id, &visibility));
+    t_ilm_bool status = m_executor->execute(new SurfaceGetVisibilityCommand(clientPid, id, &visibility));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
@@ -1914,21 +1764,25 @@ void GenericCommunicator::GetSurfaceVisibility(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::GetLayerVisibility(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = 0;
-    bool visibility;
+    bool visibility = false;
 
     m_ipcModule.getUint(message, &id);
 
-    t_ilm_bool status = m_executor->execute(new LayerGetVisibilityCommand(id, &visibility));
+    t_ilm_bool status = m_executor->execute(new LayerGetVisibilityCommand(clientPid, id, &visibility));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
@@ -1936,104 +1790,157 @@ void GenericCommunicator::GetLayerVisibility(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
-void GenericCommunicator::SetSurfacegroupVisibility(t_ilm_message message)
+void GenericCommunicator::SetSynchronizedSurfaces(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    uint groupid = 0;
-    t_ilm_bool myparam = ILM_FALSE;
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
 
-    m_ipcModule.getUint(message, &groupid);
-    m_ipcModule.getBool(message, &myparam);
+    // ipcArray was created in ipcModule using malloc (it's implemented C)
+    // so we copy it to a buffer created with new() and discard
+    // the ipcArray using free() to avoid memory corruption
+    uint* ipcArray = NULL;
+    uint* array = NULL;
+    int length = 0;
+    m_ipcModule.getUintArray(message, &ipcArray, &length);
+    array = new uint[length];
+    memset(array, 0, length * sizeof(uint));
+    memcpy(array, ipcArray, length * sizeof(uint));
+    free(ipcArray);
 
-    t_ilm_bool status = m_executor->execute(new SurfacegroupSetVisibilityCommand(groupid, myparam));
+    t_ilm_bool status = m_executor->execute(new SetSynchronizedSurfacesCommand(clientPid, array, length));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
-void GenericCommunicator::SetLayergroupVisibility(t_ilm_message message)
+void GenericCommunicator::RemoveSynchronizedSurfaces(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    uint groupid = 0;
-    t_ilm_bool myparam = ILM_FALSE;
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
 
-    m_ipcModule.getUint(message, &groupid);
-    m_ipcModule.getBool(message, &myparam);
+    // ipcArray was created in ipcModule using malloc (it's implemented C)
+    // so we copy it to a buffer created with new() and discard
+    // the ipcArray using free() to avoid memory corruption
+    uint* ipcArray = NULL;
+    uint* array = NULL;
+    int length = 0;
+    m_ipcModule.getUintArray(message, &ipcArray, &length);
+    array = new uint[length];
+    memset(array, 0, length * sizeof(uint));
+    memcpy(array, ipcArray, length * sizeof(uint));
+    free(ipcArray);
 
-    t_ilm_bool status = m_executor->execute(new LayergroupSetVisibilityCommand(groupid, myparam));
+    t_ilm_bool status = m_executor->execute(new RemoveSynchronizedSurfacesCommand(clientPid, array, length));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
-
 void GenericCommunicator::SetRenderOrderOfLayers(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
+
+    // ipcArray was created in ipcModule using malloc (it's implemented C)
+    // so we copy it to a buffer created with new() and discard
+    // the ipcArray using free() to avoid memory corruption
+    uint* ipcArray = NULL;
     uint* array = NULL;
     int length = 0;
+    m_ipcModule.getUintArray(message, &ipcArray, &length);
+    array = new uint[length];
+    memset(array, 0, length * sizeof(uint));
+    memcpy(array, ipcArray, length * sizeof(uint));
+    free(ipcArray);
 
-    m_ipcModule.getUintArray(message, &array, &length);
+    uint screenID = 0;
+
+    m_ipcModule.getUint(message, &screenID);
 
-    t_ilm_bool status = m_executor->execute(new ScreenSetRenderOrderCommand(array, length));
+    t_ilm_bool status = m_executor->execute(new ScreenSetRenderOrderCommand(clientPid, screenID, array, length));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::SetSurfaceRenderOrderWithinLayer(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    uint* array = NULL;
-    int length = 0;
-    uint layerid = 0;
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
 
+    uint layerid = 0;
     m_ipcModule.getUint(message, &layerid);
-    m_ipcModule.getUintArray(message, &array, &length);
 
-    t_ilm_bool status = m_executor->execute(new LayerSetRenderOrderCommand(layerid, array, length));
+    // ipcArray was created in ipcModule using malloc (it's implemented C)
+    // so we copy it to a buffer created with new() and discard
+    // the ipcArray using free() to avoid memory corruption
+    uint* ipcArray = NULL;
+    uint* array = NULL;
+    int length = 0;
+    m_ipcModule.getUintArray(message, &ipcArray, &length);
+    array = new uint[length];
+    memset(array, 0, length * sizeof(uint));
+    memcpy(array, ipcArray, length * sizeof(uint));
+    free(ipcArray);
+
+    t_ilm_bool status = m_executor->execute(new LayerSetRenderOrderCommand(clientPid, layerid, array, length));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::GetLayerType(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
     uint id = 0;
     m_ipcModule.getUint(message, &id);
 
@@ -2045,15 +1952,18 @@ void GenericCommunicator::GetLayerType(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::GetLayertypeCapabilities(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
     uint id = 0;
     LayerType type = Unknown;
 
@@ -2064,12 +1974,14 @@ void GenericCommunicator::GetLayertypeCapabilities(t_ilm_message message)
     uint capabilities = m_executor->getLayerTypeCapabilities(type);
     response = m_ipcModule.createResponse(message);
     m_ipcModule.appendUint(response, capabilities);
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::GetLayerCapabilities(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
     uint id = 0;
     m_ipcModule.getUint(message, &id);
 
@@ -2081,68 +1993,89 @@ void GenericCommunicator::GetLayerCapabilities(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::FadeIn(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, NOT_IMPLEMENTED);
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    response = m_ipcModule.createErrorResponse(message);
+    m_ipcModule.appendUint(response, ILM_ERROR_NOT_IMPLEMENTED);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::SynchronizedFade(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, NOT_IMPLEMENTED);
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    response = m_ipcModule.createErrorResponse(message);
+    m_ipcModule.appendUint(response, ILM_ERROR_NOT_IMPLEMENTED);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::FadeOut(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, NOT_IMPLEMENTED);
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    response = m_ipcModule.createErrorResponse(message);
+    m_ipcModule.appendUint(response, ILM_ERROR_NOT_IMPLEMENTED);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::Exit(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    t_ilm_bool status = m_executor->execute(new ExitCommand());
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
+    t_ilm_bool status = m_executor->execute(new ExitCommand(clientPid));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, INVALID_ARGUMENT);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_INVALID_ARGUMENTS);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::CommitChanges(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
-    t_ilm_bool status = m_executor->execute(new CommitCommand());
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
+    t_ilm_bool status = m_executor->execute(new CommitCommand(clientPid));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, INVALID_ARGUMENT);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_INVALID_ARGUMENTS);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::CreateShader(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     char vertname[1024];
     char fragname[1024];
     uint id = 0;
@@ -2150,7 +2083,7 @@ void GenericCommunicator::CreateShader(t_ilm_message message)
     m_ipcModule.getString(message, vertname);
     m_ipcModule.getString(message, fragname);
 
-    t_ilm_bool status = m_executor->execute(new ShaderCreateCommand(vertname, fragname, &id));
+    t_ilm_bool status = m_executor->execute(new ShaderCreateCommand(clientPid, vertname, fragname, &id));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
@@ -2158,57 +2091,69 @@ void GenericCommunicator::CreateShader(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::DestroyShader(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint shaderid = 0;
 
     m_ipcModule.getUint(message, &shaderid);
 
-    t_ilm_bool status = m_executor->execute(new ShaderDestroyCommand(shaderid));
+    t_ilm_bool status = m_executor->execute(new ShaderDestroyCommand(clientPid, shaderid));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::SetShader(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint surfaceId = 0;
     uint shaderid = 0;
 
     m_ipcModule.getUint(message, &surfaceId);
     m_ipcModule.getUint(message, &shaderid);
 
-    t_ilm_bool status = m_executor->execute(new SurfaceSetShaderCommand(surfaceId, shaderid));
+    t_ilm_bool status = m_executor->execute(new SurfaceSetShaderCommand(clientPid, surfaceId, shaderid));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::SetUniforms(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint id = 0;
     std::vector<string> uniforms;
 
@@ -2217,28 +2162,31 @@ void GenericCommunicator::SetUniforms(t_ilm_message message)
     // TODO
     //m_ipcModule.getStringArray(&uniforms);
 
-    t_ilm_bool status = m_executor->execute(new ShaderSetUniformsCommand(id, uniforms));
+    t_ilm_bool status = m_executor->execute(new ShaderSetUniformsCommand(clientPid, id, uniforms));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::SetKeyboardFocusOn(t_ilm_message message)
 {
     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     t_ilm_message response;
     uint surfaceId = 0;
 
     m_ipcModule.getUint(message, &surfaceId);
 
-    t_ilm_bool status = m_executor->execute(new SurfaceSetKeyboardFocusCommand(surfaceId));
+    t_ilm_bool status = m_executor->execute(new SurfaceSetKeyboardFocusCommand(clientPid, surfaceId));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
@@ -2246,7 +2194,7 @@ void GenericCommunicator::SetKeyboardFocusOn(t_ilm_message message)
     else
     {
         response = m_ipcModule.createErrorResponse(message);
-        m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
     m_ipcModule.sendToClients(response, &clientHandle, 1);
@@ -2256,10 +2204,12 @@ void GenericCommunicator::SetKeyboardFocusOn(t_ilm_message message)
 
 void GenericCommunicator::GetKeyboardFocusSurfaceId(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint surfaceId;
 
-    t_ilm_bool status = m_executor->execute(new SurfaceGetKeyboardFocusCommand(&surfaceId));
+    t_ilm_bool status = m_executor->execute(new SurfaceGetKeyboardFocusCommand(clientPid, &surfaceId));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
@@ -2267,16 +2217,19 @@ void GenericCommunicator::GetKeyboardFocusSurfaceId(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 
 void GenericCommunicator::UpdateInputEventAcceptanceOn(t_ilm_message message)
 {
     t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     t_ilm_message response;
     uint surfaceId = 0;
     uint udevices = 0;
@@ -2289,7 +2242,7 @@ void GenericCommunicator::UpdateInputEventAcceptanceOn(t_ilm_message message)
 
     devices = (InputDevice) udevices;
 
-    t_ilm_bool status = m_executor->execute(new SurfaceUpdateInputEventAcceptance(surfaceId, devices, accept));
+    t_ilm_bool status = m_executor->execute(new SurfaceUpdateInputEventAcceptance(clientPid, surfaceId, devices, accept));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
@@ -2297,7 +2250,7 @@ void GenericCommunicator::UpdateInputEventAcceptanceOn(t_ilm_message message)
     else
     {
         response = m_ipcModule.createErrorResponse(message);
-        m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
     m_ipcModule.sendToClients(response, &clientHandle, 1);
@@ -2306,7 +2259,9 @@ void GenericCommunicator::UpdateInputEventAcceptanceOn(t_ilm_message message)
 
 void GenericCommunicator::SetSurfaceChromaKey(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint* array = NULL;
     int length = 0;
     uint surfaceid = 0;
@@ -2314,22 +2269,26 @@ void GenericCommunicator::SetSurfaceChromaKey(t_ilm_message message)
     m_ipcModule.getUint(message, &surfaceid);
     m_ipcModule.getUintArray(message, &array, &length);
 
-    t_ilm_bool status = m_executor->execute(new SurfaceSetChromaKeyCommand(surfaceid, array, length));
+    t_ilm_bool status = m_executor->execute(new SurfaceSetChromaKeyCommand(clientPid, surfaceid, array, length));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::SetLayerChromaKey(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
     uint* array = NULL;
     int length = 0;
     uint layerid = 0;
@@ -2337,22 +2296,25 @@ void GenericCommunicator::SetLayerChromaKey(t_ilm_message message)
     m_ipcModule.getUint(message, &layerid);
     m_ipcModule.getUintArray(message, &array, &length);
 
-    t_ilm_bool status = m_executor->execute(new LayerSetChromaKeyCommand(layerid, array, length));
+    t_ilm_bool status = m_executor->execute(new LayerSetChromaKeyCommand(clientPid, layerid, array, length));
     if (status)
     {
         response = m_ipcModule.createResponse(message);
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, RESOURCE_NOT_FOUND);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::LayerAddNotification(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
     uint layerid = 0;
 
     m_ipcModule.getUint(message, &layerid);
@@ -2365,15 +2327,18 @@ void GenericCommunicator::LayerAddNotification(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, INVALID_ARGUMENT);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_INVALID_ARGUMENTS);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::SurfaceAddNotification(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
     uint surfaceid = 0;
 
     m_ipcModule.getUint(message, &surfaceid);
@@ -2386,15 +2351,18 @@ void GenericCommunicator::SurfaceAddNotification(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, INVALID_ARGUMENT);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_INVALID_ARGUMENTS);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::LayerRemoveNotification(t_ilm_message message)
 {
-    t_ilm_message response; t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
     uint layerid = 0;
 
     m_ipcModule.getUint(message, &layerid);
@@ -2407,10 +2375,12 @@ void GenericCommunicator::LayerRemoveNotification(t_ilm_message message)
     }
     else
     {
-        response = m_ipcModule.createErrorResponse(message); m_ipcModule.appendString(response, INVALID_ARGUMENT);
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_INVALID_ARGUMENTS);
     }
 
-    m_ipcModule.sendToClients(response, &clientHandle, 1); m_ipcModule.destroyMessage(response);
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
 void GenericCommunicator::SurfaceRemoveNotification(t_ilm_message message)
@@ -2430,7 +2400,7 @@ void GenericCommunicator::SurfaceRemoveNotification(t_ilm_message message)
     else
     {
         response = m_ipcModule.createErrorResponse(message);
-        m_ipcModule.appendString(response, INVALID_ARGUMENT);
+        m_ipcModule.appendUint(response, ILM_ERROR_INVALID_ARGUMENTS);
     }
 
     m_ipcModule.sendToClients(response, &clientHandle, 1);
@@ -2457,155 +2427,258 @@ void GenericCommunicator::sendNotification(GraphicalObject* object, t_ilm_notifi
     switch (object->type)
     {
     case TypeLayer:
-    {
-        Layer* layer = static_cast<Layer*>(object);
-        if (layer)
         {
-            ApplicationReferenceList& arl = layer->getNotificationClients();
-
-            if (arl.size())
+            Layer* layer = static_cast<Layer*>(object);
+            if (layer)
             {
-                t_ilm_message notification;
-                Rectangle dest = layer->getDestinationRegion();
-                Rectangle src = layer->getSourceRegion();
-                OrientationType orientation = layer->getOrientation();
-
-                unsigned char chromaKeyRed = 0;
-                unsigned char chromaKeyGreen = 0;
-                unsigned char chromaKeyBlue = 0;
-                layer->getChromaKey(chromaKeyRed, chromaKeyGreen, chromaKeyBlue);
-
-                std::stringstream notificationName;
-                notificationName << "NotificationForLayer" << layer->getID();
-
-                notification = m_ipcModule.createNotification(notificationName.str().c_str());
-                m_ipcModule.appendUint(notification, layer->getID());
-                m_ipcModule.appendUint(notification, mask);
-
-                m_ipcModule.appendDouble(notification, layer->getOpacity());
-                m_ipcModule.appendUint(notification, src.x);
-                m_ipcModule.appendUint(notification, src.y);
-                m_ipcModule.appendUint(notification, src.width);
-                m_ipcModule.appendUint(notification, src.height);
-                m_ipcModule.appendUint(notification, layer->OriginalSourceWidth);
-                m_ipcModule.appendUint(notification, layer->OriginalSourceHeight);
-                m_ipcModule.appendUint(notification, dest.x);
-                m_ipcModule.appendUint(notification, dest.y);
-                m_ipcModule.appendUint(notification, dest.width);
-                m_ipcModule.appendUint(notification, dest.height);
-                m_ipcModule.appendUint(notification, orientation);
-                m_ipcModule.appendBool(notification, layer->getVisibility());
-                m_ipcModule.appendUint(notification, layer->getLayerType());
-                m_ipcModule.appendBool(notification, layer->getChromaKeyEnabled());
-                m_ipcModule.appendUint(notification, chromaKeyRed);
-                m_ipcModule.appendUint(notification, chromaKeyGreen);
-                m_ipcModule.appendUint(notification, chromaKeyBlue);
-
-                int clientCount = arl.size();
-                t_ilm_client_handle clients[clientCount];
-
-                ApplicationReferenceList::iterator iter = arl.begin();
-                ApplicationReferenceList::iterator end = arl.end();
-
-                for (int clientNumber = 0; iter != end; ++iter, ++clientNumber)
-                {
-                    clients[clientNumber] = *iter;
-                }
-
-                LOG_DEBUG("GenericCommunicator", "Sending " << clientCount << " notification(s): layer " << layer->getID() << " was updated.");
+                ApplicationReferenceList& arl = layer->getNotificationClients();
 
-                if (!m_ipcModule.sendToClients(notification, clients, clientCount))
+                if (arl.size())
                 {
-                    LOG_ERROR("GenericCommunicator", "Sending notification to clients failed.")
+                    t_ilm_message notification;
+                    Rectangle dest = layer->getDestinationRegion();
+                    Rectangle src = layer->getSourceRegion();
+                    OrientationType orientation = layer->getOrientation();
+
+                    unsigned char chromaKeyRed = 0;
+                    unsigned char chromaKeyGreen = 0;
+                    unsigned char chromaKeyBlue = 0;
+                    layer->getChromaKey(chromaKeyRed, chromaKeyGreen, chromaKeyBlue);
+
+                    std::stringstream notificationName;
+                    notificationName << "NotificationForLayer" << layer->getID();
+
+                    notification = m_ipcModule.createNotification(notificationName.str().c_str());
+                    m_ipcModule.appendUint(notification, layer->getID());
+                    m_ipcModule.appendUint(notification, mask);
+
+                    m_ipcModule.appendDouble(notification, layer->getOpacity());
+                    m_ipcModule.appendUint(notification, src.x);
+                    m_ipcModule.appendUint(notification, src.y);
+                    m_ipcModule.appendUint(notification, src.width);
+                    m_ipcModule.appendUint(notification, src.height);
+                    m_ipcModule.appendUint(notification, layer->OriginalSourceWidth);
+                    m_ipcModule.appendUint(notification, layer->OriginalSourceHeight);
+                    m_ipcModule.appendUint(notification, dest.x);
+                    m_ipcModule.appendUint(notification, dest.y);
+                    m_ipcModule.appendUint(notification, dest.width);
+                    m_ipcModule.appendUint(notification, dest.height);
+                    m_ipcModule.appendUint(notification, orientation);
+                    m_ipcModule.appendBool(notification, layer->getVisibility());
+                    m_ipcModule.appendUint(notification, layer->getLayerType());
+                    m_ipcModule.appendBool(notification, layer->getChromaKeyEnabled());
+                    m_ipcModule.appendUint(notification, chromaKeyRed);
+                    m_ipcModule.appendUint(notification, chromaKeyGreen);
+                    m_ipcModule.appendUint(notification, chromaKeyBlue);
+                    m_ipcModule.appendInt(notification, layer->getCreatorPid());
+
+                    int clientCount = arl.size();
+                    t_ilm_client_handle clientArray[256];
+
+                    ApplicationReferenceList::iterator iter = arl.begin();
+                    ApplicationReferenceList::iterator end = arl.end();
+
+                    for (int clientNumber = 0;
+                            iter != end, clientNumber < 256;
+                            ++iter, ++clientNumber)
+                    {
+                        t_ilm_client_handle client = *iter;
+                        clientArray[clientNumber] = client;
+                    }
+
+                    LOG_DEBUG("GenericCommunicator", "Sending " << clientCount << " notification(s): layer " << layer->getID() << " was updated.");
+
+                    if (!m_ipcModule.sendToClients(notification, clientArray, clientCount))
+                    {
+                        LOG_ERROR("GenericCommunicator", "Sending notification to clients failed.")
+                    }
+
+                    m_ipcModule.destroyMessage(notification);
                 }
-
-                m_ipcModule.destroyMessage(notification);
             }
         }
-    }
-    break;
+        break;
     case TypeSurface:
-    {
-        Surface* surface = static_cast<Surface*>(object);
-        if (surface)
         {
-            ApplicationReferenceList& arl = surface->getNotificationClients();
-
-            if (arl.size())
+            Surface* surface = static_cast<Surface*>(object);
+            if (surface)
             {
-                t_ilm_message notification;
-                std::stringstream notificationName;
-                notificationName << "NotificationForSurface" << surface->getID();
-
-                unsigned char chromaKeyRed = 0;
-                unsigned char chromaKeyGreen = 0;
-                unsigned char chromaKeyBlue = 0;
-                surface->getChromaKey(chromaKeyRed, chromaKeyGreen, chromaKeyBlue);
-
-                notification = m_ipcModule.createNotification(notificationName.str().c_str());
-                m_ipcModule.appendUint(notification, surface->getID());
-                m_ipcModule.appendUint(notification, mask);
-
-                m_ipcModule.appendDouble(notification, surface->getOpacity());
-                m_ipcModule.appendUint(notification, surface->getSourceRegion().x);
-                m_ipcModule.appendUint(notification, surface->getSourceRegion().y);
-                m_ipcModule.appendUint(notification, surface->getSourceRegion().width);
-                m_ipcModule.appendUint(notification, surface->getSourceRegion().height);
-                m_ipcModule.appendUint(notification, surface->OriginalSourceWidth);
-                m_ipcModule.appendUint(notification, surface->OriginalSourceHeight);
-                m_ipcModule.appendUint(notification, surface->getDestinationRegion().x);
-                m_ipcModule.appendUint(notification, surface->getDestinationRegion().y);
-                m_ipcModule.appendUint(notification, surface->getDestinationRegion().width);
-                m_ipcModule.appendUint(notification, surface->getDestinationRegion().height);
-                m_ipcModule.appendUint(notification, surface->getOrientation());
-                m_ipcModule.appendBool(notification, surface->getVisibility());
-                m_ipcModule.appendUint(notification, surface->frameCounter);
-                m_ipcModule.appendUint(notification, surface->drawCounter);
-                m_ipcModule.appendUint(notification, surface->updateCounter);
-                m_ipcModule.appendUint(notification, surface->getPixelFormat());
-                m_ipcModule.appendUint(notification, surface->getNativeContent());
-                m_ipcModule.appendUint(notification, surface->getInputEventAcceptanceOnDevices());
-                m_ipcModule.appendBool(notification, surface->getChromaKeyEnabled());
-                m_ipcModule.appendUint(notification, chromaKeyRed);
-                m_ipcModule.appendUint(notification, chromaKeyGreen);
-                m_ipcModule.appendUint(notification, chromaKeyBlue);
-
-                int clientCount = arl.size();
-                t_ilm_client_handle clients[clientCount];
-
-                ApplicationReferenceList::iterator iter = arl.begin();
-                ApplicationReferenceList::iterator end = arl.end();
-
-                for (int clientNumber = 0; iter != end; ++iter, ++clientNumber)
-                {
-                    clients[clientNumber] = *iter;
-                }
-
-                LOG_DEBUG("GenericCommunicator", "Sending " << clientCount << " notification(s): surface " << surface->getID() << " was updated.");
+                ApplicationReferenceList& arl = surface->getNotificationClients();
 
-                if (!m_ipcModule.sendToClients(notification, clients, clientCount))
+                if (arl.size())
                 {
-                    LOG_ERROR("GenericCommunicator", "Sending notification to clients failed.")
+                    t_ilm_message notification;
+                    std::stringstream notificationName;
+                    notificationName << "NotificationForSurface" << surface->getID();
+
+                    unsigned char chromaKeyRed = 0;
+                    unsigned char chromaKeyGreen = 0;
+                    unsigned char chromaKeyBlue = 0;
+                    surface->getChromaKey(chromaKeyRed, chromaKeyGreen, chromaKeyBlue);
+
+                    notification = m_ipcModule.createNotification(notificationName.str().c_str());
+                    m_ipcModule.appendUint(notification, surface->getID());
+                    m_ipcModule.appendUint(notification, mask);
+
+                    m_ipcModule.appendDouble(notification, surface->getOpacity());
+                    m_ipcModule.appendUint(notification, surface->getSourceRegion().x);
+                    m_ipcModule.appendUint(notification, surface->getSourceRegion().y);
+                    m_ipcModule.appendUint(notification, surface->getSourceRegion().width);
+                    m_ipcModule.appendUint(notification, surface->getSourceRegion().height);
+                    m_ipcModule.appendUint(notification, surface->OriginalSourceWidth);
+                    m_ipcModule.appendUint(notification, surface->OriginalSourceHeight);
+                    m_ipcModule.appendUint(notification, surface->getDestinationRegion().x);
+                    m_ipcModule.appendUint(notification, surface->getDestinationRegion().y);
+                    m_ipcModule.appendUint(notification, surface->getDestinationRegion().width);
+                    m_ipcModule.appendUint(notification, surface->getDestinationRegion().height);
+                    m_ipcModule.appendUint(notification, surface->getOrientation());
+                    m_ipcModule.appendBool(notification, surface->getVisibility());
+                    m_ipcModule.appendUint(notification, surface->frameCounter);
+                    m_ipcModule.appendUint(notification, surface->drawCounter);
+                    m_ipcModule.appendUint(notification, surface->updateCounter);
+                    m_ipcModule.appendUint(notification, surface->getPixelFormat());
+                    m_ipcModule.appendUint(notification, surface->getNativeContent());
+                    m_ipcModule.appendUint(notification, surface->getInputEventAcceptanceOnDevices());
+                    m_ipcModule.appendBool(notification, surface->getChromaKeyEnabled());
+                    m_ipcModule.appendUint(notification, chromaKeyRed);
+                    m_ipcModule.appendUint(notification, chromaKeyGreen);
+                    m_ipcModule.appendUint(notification, chromaKeyBlue);
+                    m_ipcModule.appendInt(notification, surface->getCreatorPid());
+
+                    int clientCount = arl.size();
+                    t_ilm_client_handle clients[256];
+
+                    ApplicationReferenceList::iterator iter = arl.begin();
+                    ApplicationReferenceList::iterator end = arl.end();
+
+                    for (int clientNumber = 0;
+                            iter != end, clientNumber < 256;
+                            ++iter, ++clientNumber)
+                    {
+                        clients[clientNumber] = *iter;
+                    }
+
+                    LOG_DEBUG("GenericCommunicator", "Sending " << clientCount << " notification(s): surface " << surface->getID() << " was updated.");
+
+                    if (!m_ipcModule.sendToClients(notification, clients, clientCount))
+                    {
+                        LOG_ERROR("GenericCommunicator", "Sending notification to clients failed.")
+                    }
+
+                    m_ipcModule.destroyMessage(notification);
                 }
-
-                m_ipcModule.destroyMessage(notification);
             }
         }
-    }
-    break;
+        break;
     default:
         LOG_INFO("GenericCommunicator", "Unknown notification found in queue.");
         break;
     }
 }
 
-extern "C" ICommunicator* createGenericCommunicator(ICommandExecutor* executor)
+HealthCondition GenericCommunicator::pluginGetHealth()
+{
+    HealthCondition health = PluginBase::pluginGetHealth();
+    if (0 != pthread_kill(mThreadId, 0))
+    {
+        health = HealthDead;
+    }
+    return health;
+}
+
+void GenericCommunicator::SetOptimizationMode(t_ilm_message message)
+{
+    t_ilm_message response;
+    OptimizationType optimizationId;
+    OptimizationModeType optimizationMode;
+    unsigned int optMode;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
+
+    m_ipcModule.getUint(message, &optMode);
+    optimizationId = (OptimizationType)optMode;
+    m_ipcModule.getUint(message, &optMode);
+    optimizationMode = (OptimizationModeType)optMode;
+
+    t_ilm_bool status = m_executor->execute(new SetOptimizationModeCommand(clientPid, optimizationId, optimizationMode));
+    if (status)
+    {
+        response = m_ipcModule.createResponse(message);
+    }
+    else
+    {
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
+    }
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
+}
+
+void GenericCommunicator::GetOptimizationMode(t_ilm_message message)
 {
-    return new GenericCommunicator(executor);
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    t_ilm_uint clientPid = m_executor->getSenderPid(clientHandle);
+    OptimizationType optimizationId;
+    OptimizationModeType optimizationMode;
+    unsigned int o;
+
+    m_ipcModule.getUint(message, &o);
+    optimizationId = (OptimizationType)o;
+
+    t_ilm_bool status = m_executor->execute(new GetOptimizationModeCommand(clientPid, optimizationId, &optimizationMode));
+    if (status)
+    {
+        response = m_ipcModule.createResponse(message);
+        m_ipcModule.appendUint(response, (unsigned int)optimizationMode);
+    }
+    else
+    {
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
+    }
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
-extern "C" void destroyGenericCommunicator(GenericCommunicator* p)
+void GenericCommunicator::GetPropertiesOfScreen(t_ilm_message message)
 {
-    delete p;
+    t_ilm_message response;
+    t_ilm_client_handle clientHandle = m_ipcModule.getSenderHandle(message);
+    uint id = 0;
+    m_ipcModule.getUint(message, &id);
+
+    LmScreen* screen = m_executor->getScene()->getScreen(id);
+    if (screen != NULL)
+    {
+        LayerList renderOrder = screen->getCurrentRenderOrder();
+        std::vector<t_ilm_layer> layerIdVector;
+
+        LayerListConstIterator iter = renderOrder.begin();
+        LayerListConstIterator end = renderOrder.end();
+        for (; iter != end; ++iter)
+        {
+            layerIdVector.push_back((*iter)->getID());
+        }
+
+        uint numberOfHardwareLayers = m_executor->getNumberOfHardwareLayers(id);
+        uint* resolution = m_executor->getScreenResolution(id);
+
+        response = m_ipcModule.createResponse(message);
+        m_ipcModule.appendUintArray(response, layerIdVector.data(), layerIdVector.size());
+        m_ipcModule.appendUint(response, numberOfHardwareLayers);
+        m_ipcModule.appendUint(response, resolution[0]);
+        m_ipcModule.appendUint(response, resolution[1]);
+    }
+    else
+    {
+        response = m_ipcModule.createErrorResponse(message);
+        m_ipcModule.appendUint(response, ILM_ERROR_RESOURCE_NOT_FOUND);
+    }
+
+    m_ipcModule.sendToClients(response, &clientHandle, 1);
+    m_ipcModule.destroyMessage(response);
 }
 
+DECLARE_LAYERMANAGEMENT_PLUGIN(GenericCommunicator)
+