The download UI application is added.
[apps/web/download-manager.git] / src / download-manager-event.cpp
1 /*
2  * Copyright 2012  Samsung Electronics Co., Ltd
3  *
4  * Licensed under the Flora License, Version 1.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *    http://www.tizenopensource.org/license
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 /**
18  * @file        download-manager-event.cpp
19  * @author      Jungki Kwak (jungki.kwak@samsung.com)
20  * @brief       download event class for event flow
21  */
22 #include "download-manager-event.h"
23 #include "download-manager-common.h"
24
25 #include <iostream>
26
27 void Subject::attach(Observer *o)
28 {
29         _observers.push_back(o);
30 }
31
32 void Subject::detach(Observer *o)
33 {
34         vector<Observer*>::iterator it;
35         for(it = _observers.begin() ; it < _observers.end() ; it++) {
36                 if (*it == o) {
37                         _observers.erase(it);
38                         break;
39                 }
40         }
41 }
42
43 void Subject::notify(void)
44 {
45         vector<Observer*>::iterator it;
46         Observer *curObserver;
47         it = _observers.begin();
48         while (it < _observers.end()) {
49                 curObserver = *it;
50
51                 DP_LOGD("[%s] Call Update",curObserver->name().c_str());
52                 (*it)->update(this);
53
54                 if (curObserver != *it)
55                         continue;
56
57                 it++;
58         }
59 }
60
61 void Observer::update(Subject *s)
62 {
63         call();
64 }
65
66 //Observer::Observer(updateFunction uf, void *data)
67 /* For debug */
68 Observer::Observer(updateFunction uf, void *data, const char *name)
69         : m_updateFunction(uf)
70         , m_userData(data)
71 {
72         observerName = name;
73 }
74
75 void Observer::set(updateFunction uf, void *data)
76 {
77         m_updateFunction = uf;
78         m_userData = data;
79 }
80
81 void Observer::clear(void)
82 {
83         m_updateFunction = 0;
84         m_userData = 0;
85 }
86
87 void Observer::call(void)
88 {
89         if (m_updateFunction)
90                 m_updateFunction(m_userData);
91 }