Exemplo n.º 1
0
Arquivo: event.c Projeto: kemadz/monit
/**
 * Post a new Event
 * @param service The Service the event belongs to
 * @param id The event identification
 * @param state The event state
 * @param action Description of the event action
 * @param s Optional message describing the event
 */
void Event_post(Service_T service, long id, State_Type state, EventAction_T action, char *s, ...) {
        ASSERT(service);
        ASSERT(action);
        ASSERT(s);
        ASSERT(state == State_Failed || state == State_Succeeded || state == State_Changed || state == State_ChangedNot);

        va_list ap;
        va_start(ap, s);
        char *message = Str_vcat(s, ap);
        va_end(ap);

        Event_T e = service->eventlist;
        while (e) {
                if (e->action == action && e->id == id) {
                        gettimeofday(&e->collected, NULL);

                        /* Shift the existing event flags to the left and set the first bit based on actual state */
                        e->state_map <<= 1;
                        e->state_map |= ((state == State_Succeeded || state == State_ChangedNot) ? 0 : 1);

                        /* Update the message */
                        FREE(e->message);
                        e->message = message;
                        break;
                }
                e = e->next;
        }
        if (! e) {
                /* Only first failed/changed event can initialize the queue for given event type, thus succeeded events are ignored until first error. */
                if (state == State_Succeeded || state == State_ChangedNot) {
                        DEBUG("'%s' %s\n", service->name, message);
                        FREE(message);
                        return;
                }
                /* Initialize the event. The mandatory informations are cloned so the event is as standalone as possible and may be saved
                 * to the queue without the dependency on the original service, thus persistent and managable across monit restarts */
                NEW(e);
                e->id = id;
                gettimeofday(&e->collected, NULL);
                e->source = service;
                e->mode = service->mode;
                e->type = service->type;
                e->state = State_Init;
                e->state_map = 1;
                e->action = action;
                e->message = message;
                e->next = service->eventlist;
                service->eventlist = e;
        }
        e->state_changed = _checkState(e, state);
        /* In the case that the state changed, update it and reset the counter */
        if (e->state_changed) {
                e->state = state;
                e->count = 1;
        } else {
                e->count++;
        }
        _handleEvent(service, e);
}
Exemplo n.º 2
0
	bool Server::_canStop(State state)
	{
		harray<State> allowed;
		allowed += RUNNING;
		return _checkState(state, allowed, "stop");
	}
Exemplo n.º 3
0
	bool Server::_canStart(State state)
	{
		harray<State> allowed;
		allowed += BOUND;
		return _checkState(state, allowed, "start");
	}
Exemplo n.º 4
0
	bool Binder::_canUnbind(State state)
	{
		harray<State> allowed;
		allowed += BOUND;
		return _checkState(state, allowed, "unbind");
	}
Exemplo n.º 5
0
	bool Binder::_canBind(State state)
	{
		harray<State> allowed;
		allowed += IDLE;
		return _checkState(state, allowed, "bind");
	}
Exemplo n.º 6
0
	bool KRenderSys::update(F64 Delta) {
		// update all active camera(s) (sorted)
		for (auto camit = _kcamList.begin(); camit != _kcamList.end(); ++camit) {
			auto cam = (*camit);

			// skip inactive camera
			if (!cam->getOwnerNode()->isActive()) continue;

			_kupdata.clear();

			// check active
			if (entity->isActive()) {
				// check render target (texture or screen)
				if (cam->getRenderTexture()) {
					_kfbo->bind();
					auto tarray = static_cast<KAtlasTextureArray *>(cam->getRenderTexture().get());
					_initeFrameBuffer(tarray, cam->getRenderTextureIndex());
				} else {
					_kfbo->unbind();
					DGL_CALL(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA));
				}

				// update viewport and scissor
				if (_klastState.lastViewSize != cam->_ksize || _klastState.lastViewPos != cam->_kposition) {
					DGL_CALL(glViewport(cam->_kposition.x, cam->_kposition.y, cam->_ksize.x, cam->_ksize.y));
					_klastState.lastViewSize = cam->_ksize;
					_klastState.lastViewPos = cam->_kposition;

					DGL_CALL(glScissor(cam->_kposition.x, cam->_kposition.y, cam->_ksize.x, cam->_ksize.y));
				}

				// update clear color
				if (cam->_kclearCol != _klastState.lastColor) {
					DGL_CALL(glClearColor((GLclampf)(cam->_kclearCol.getGLR()),
											(GLclampf)(cam->_kclearCol.getGLG()),
											(GLclampf)(cam->_kclearCol.getGLB()),
											(GLclampf)(cam->_kclearCol.getGLA())));
					_klastState.lastColor = cam->_kclearCol;
				}

				// clear scene 
				if (cam->_kclearView) {
					DGL_CALL(glClear(GL_COLOR_BUFFER_BIT));
				}

				U32 indSize = 0;
				U32 verSize = 0;

				KRenderable *material = nullptr;
				ED_STATIC std::vector<std::pair<KEntity *, KRenderable *>> objList;
				objList.reserve(_kconfig.objectSize);

				// update and draw renderables
				// culling is enabled
				if (_kconfig.culling) {
					const U8 filter = (U8)GCullingObjectsFilter::TILE 
						| (U8)GCullingObjectsFilter::DYNAMIC 
						| (U8)GCullingObjectsFilter::STATIC;
					_kcullSys->queryObjects(cam, (GCullingObjectsFilter)filter, EManager, objList);

				} else {
					// culling is disabled
					_fillRenderList(EManager, objList);
				}

				// sort objects
				if (_kconfig.zSorting) {
					// sort using a lambda expression 
					std::sort(objList.begin(), objList.end(), [](const std::pair<KEntity *, KRenderable *> &A,
																const std::pair<KEntity *, KRenderable *> &B) {
						return B.first->getZOrder() < A.first->getZOrder();
					});
				}
				
				// render objects list
				for (auto oit = objList.begin(); oit != objList.end(); ++oit){
					auto ent = oit->first;

					// inite materials
					if (oit->second->getMatNeedUpdate()) {
						if (!_initeMaterials(oit->second)) {
							KD_FPRINT("cant init material. entity name: %s", ent->getName().c_str());
							return false;
						}
					}

					// inite state
					if (oit == objList.begin()) {
						_checkState(oit->second);
					}

					// check material (render shared materials in a single batch)
					if (_checkState(oit->second)) {

						// check available buffer size
						if ((indSize + oit->second->getIndexSize()) < _kconfig.indexSize) {
							// compute (parent * child * camera) matrix
							// catch object with its matrix
							auto trcom = (KTransformCom *)ent->getComponent(CTypes::Transform, "");
							_kupdata.matrix.push_back((*cam).getRatioMatrix(trcom->getRatioIndex()));
							_computeParentsTransform(EManager, ent, &_kupdata.matrix.back());
							_kupdata.objects.push_back(oit->second);
							material = oit->second;

							// increase buffers size
							indSize += oit->second->getIndexSize();
							verSize += oit->second->getVertex()->size();

							// check next object if any
							if (oit != --objList.end()) {
								continue;
							}
						} 
					} else {
						--oit;
					}

					// render 
					if (!_kupdata.objects.empty()) {
						// update vetex
						_kvboVer->update(0, sizeof(KGLVertex) * verSize, false, (void *)&_kupdata);

						// bind quad vao
						_kvao->bind();

						// bind materials
						material->getShaderProg()->bind();
						auto atlas = material->getATextureArray();
						if (atlas) {
							if (atlas->isInite()) {
								atlas->bind();
							} else {
								KAtlasTextureArray::unbindTextureArray();
							}
						} else {
							KAtlasTextureArray::unbindTextureArray();
						}

						// draw 
						DGL_CALL(glDrawElements(GL_TRIANGLES, indSize, GL_UNSIGNED_SHORT, (U16 *)0));

						// clear list after render
						_kupdata.clear();
						indSize = 0;
						verSize = 0;
					}
						
				}
			}
		}
		return true;
	}