winix/core/notify.h

92 lines
1.6 KiB
C++
Executable File

/*
* This file is a part of Winix
* and is not publicly distributed
*
* Copyright (c) 2008-2010, Tomasz Sowa
* All rights reserved.
*
*/
#ifndef headerfilecmslunotify
#define headerfilecmslunotify
#include <list>
#include <string>
#include <cstdio>
#include "templatesnotify/templatesnotify.h"
#include "request.h"
#include "config.h"
#include "system.h"
#include "users.h"
#define WINIX_NOTIFY_ITEM_ADD 1
#define WINIX_NOTIFY_ITEM_EDIT 2
#define WINIX_NOTIFY_ITEM_DELETE 4
#define WINIX_NOTIFY_DIR_ADD 8
class Notify
{
public:
Notify();
~Notify();
void SetRequest(Request * prequest);
void SetConfig(Config * pconfig);
void SetSystem(System * psystem);
void SetTemplatesNotify(TemplatesNotify * ptemplates_notify);
void ReadTemplates();
bool Init();
/*
this method addes an item to our special pool
the pool is used by a second thread
*/
void ItemChanged(int notify_code);
private:
Request * request;
Config * config;
System * system;
TemplatesNotify * templates_notify;
static void * ThreadRoutine(void * arg);
bool Lock();
void Unlock();
static void CheckQueue();
static void SendEmail(NotifyMsg & n);
static void SendEmail(const std::wstring & email);
static void SendEmail(const std::wstring & email, const std::wstring & message);
static void SendMessage(FILE * sendmail, const std::wstring & message);
void CreateItemDir(std::wstring & dir, bool clear = true);
void CreateItemLink(std::wstring & link);
pthread_t thread;
pthread_mutex_t mutex;
NotifyMsg n;
/*
objects accessed by the second thread
*/
std::list<NotifyMsg> notify_pool;
static Notify * obj;
std::string command;
};
#endif