#include <stdio.h> #include <stdlib.h> #include <string.h> #include <assert.h> #include <tmsmapi.h> #include <locale.h> //State events do not take UofW int main (int argc, char** argv) { TM_Context* pCtx = NULL; MSM_WEvent* pSendStateEvent = NULL; wchar_t *szUowId = L"sampleUofWId"; wchar_t *szUowClass = L"sampleUnitOfWorkClass"; wchar_t *szTDPID = L"sampleTDPID"; wchar_t *szJobStep = L"Logon"; wchar_t *szResourceId = TMSM_WRESOURCETYPE_FLOAD; int status = 0; wchar_t *szMessage = L"Alert message"; #ifndef _WIN32 setlocale(LC_ALL, ""); #endif /* _WIN32 */ //Initialize Api. // Do not forget to call TM_Free(pCtx) at the end. pCtx = TM_Init(); fwprintf(stderr, L"Initializing TMSM API.\n"); if (pCtx != NULL) { fwprintf(stderr, L"Creating Event.\n"); // State events do not take UofW // Do not forget to call MSM_FreeWEvent(pCtx,pRequestStateEvent) at the // end pSendStateEvent = MSM_CreateWEvent(pCtx,NULL); if (pSendStateEvent != NULL) { //Simple Step fwprintf(stderr, L"Sending State Event.\n"); //set resource-id pSendStateEvent->szResourceId=TMSM_WRESOURCETYPE_FLOAD; //set event type pSendStateEvent->eventType=STATEEVENT; //set TDPID pSendStateEvent->szTDPID=szTDPID; //set state code pSendStateEvent->iStateCode=10; // Add multi-argument resourceType MSM_AddWResourceType(pCtx,pSendStateEvent,TMSM_WRESOURCETYPE_FLOAD); status=MSM_SendWEvent(pCtx,pSendStateEvent);//send event // Non-zero status is error fwprintf(stderr, L"SendEvent status %d .\n",status); // Free and clear event members for reuse MSM_FreeAndClearWEventMembers(pCtx,pSendStateEvent); //Update from environment - export variables fwprintf(stderr, L"Sending State Event.\n"); pSendStateEvent->szResourceId=TMSM_WRESOURCETYPE_FLOAD; pSendStateEvent->eventType=STATEEVENT; pSendStateEvent->szTDPID=szTDPID; pSendStateEvent->iStateCode=10; // Add multi-argument resourceType MSM_AddWResourceType(pCtx,pSendStateEvent,TMSM_WRESOURCETYPE_FLOAD); // Update Event from environment - export variables status=MSM_UpdateWEventFromEnvironment(pCtx,pSendStateEvent); fwprintf(stderr, L"update event status from env %d .\n",status); // send event status=MSM_SendWEvent(pCtx,pSendStateEvent); // Non-zero status is error fwprintf(stderr, L"SendEvent status %d .\n",status); // Free event members MSM_FreeWEventMembers(pCtx,pSendStateEvent); fwprintf(stderr, L"Freeing Event.\n"); //Free event MSM_FreeWEvent(pCtx,pSendStateEvent); } else { fwprintf(stderr, L"failed to create the event"); } fwprintf(stderr, L"Freeing Context.\n"); //Free Context TM_Free(pCtx); } else { fwprintf(stderr, L"failed to create the context\n"); }