ScreenArea::ScreenArea(int _iWidth, int _iHeight, int _iScale) : m_iFilterScale(1), m_vFilter2x(NULL), m_vFilterIB(NULL), m_puiPixels(NULL), m_puiDelta(NULL), m_iScaledWidth(_iWidth), m_iScaledHeight(_iHeight), m_bEnableRender(true), m_bShowCursor(true) { g_assert(_iWidth >= 1 && _iHeight >= 1 && _iScale >= 1); m_iWidth = _iWidth; m_iHeight = _iHeight; m_iScale = _iScale; set_events(Gdk::EXPOSURE_MASK | Gdk::POINTER_MOTION_MASK | Gdk::ENTER_NOTIFY_MASK | Gdk::LEAVE_NOTIFY_MASK); char aiEmptyData[8]; memset(aiEmptyData, 0, sizeof(aiEmptyData)); Glib::RefPtr<Gdk::Bitmap> poSource = Gdk::Bitmap::create(aiEmptyData, 8, 8); Glib::RefPtr<Gdk::Bitmap> poMask = Gdk::Bitmap::create(aiEmptyData, 8, 8); Gdk::Color oFg; Gdk::Color oBg; oFg.set_rgb(0, 0, 0); oBg.set_rgb(0, 0, 0); m_poEmptyCursor = new Gdk::Cursor(poSource, poMask, oFg, oBg, 0, 0); }
int32_t Connection::initialize(void) { int32_t result = E_ERROR; int32_t retcode = E_ERROR; if (init_ok_) { goto ExitOK; } // get a new valid sockfd and prepare to poll it ASSURE_SUCCESS(result, retcode, sockfd_.initialize()); init_ok_ = S_SUCCESS; set_state(CLOSED); event_.data.ptr = this; set_events(); recv_buf_.clear(); send_buf_.clear(); if (NULL != connection_manager_) { ASSURE_SUCCESS(result, retcode, connection_manager_->controlAdd(this)); } ExitOK: result = S_SUCCESS; ExitError: if (S_SUCCESS != result) { release(); } return result; }
knob::knob() { knob_value = 0; value = 0; snap = false; invert = false; rounded = 5; min = 0; max = 1; drag = false; label = "KNOB"; pos_mode = 0; top_colour.set( "#550000"); bottom_colour.set( "#220000"); // make the click events call the on_button_press_event function // add_events( Gdk::BUTTON_PRESS_MASK); set_events (Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::POINTER_MOTION_MASK); // make the click event do that function signal_button_press_event().connect( sigc::mem_fun(*this, &knob::on_button_press_event) ); set_size_request(40,70); }
ScreenArea::ScreenArea(int _iWidth, int _iHeight, int _iScale) : m_iFilterScale(1) , m_vFilter2x(NULL) , m_vFilterIB(NULL) , m_puiPixels(NULL) , m_puiDelta(NULL) , m_iScaledWidth(_iWidth) , m_iScaledHeight(_iHeight) , m_bEnableRender(true) , m_bShowCursor(true) { g_assert(_iWidth >= 1 && _iHeight >= 1 && _iScale >= 1); m_iWidth = _iWidth; m_iHeight = _iHeight; m_iScale = _iScale; set_events(Gdk::EXPOSURE_MASK | Gdk::POINTER_MOTION_MASK | Gdk::ENTER_NOTIFY_MASK | Gdk::LEAVE_NOTIFY_MASK); Glib::RefPtr<Gdk::Pixbuf> pixbuf = Gdk::Pixbuf::create(Gdk::COLORSPACE_RGB, true, 8, 8, 8); pixbuf->fill(0); #if !GTK_CHECK_VERSION(3, 0, 0) m_poEmptyCursor = new Gdk::Cursor(get_display, pixbuf, 0, 0); #else m_poEmptyCursor = Gdk::Cursor::create(get_display(), pixbuf, 0, 0); #endif }
// finalize initialization void finalize_init() { // if filesystem is not mounted go ahead if(!filesystem_is_mounted()) { if(global_state==0) { printf("File system is not mounted, final step of initialization is delayed\n"); global_state=1; } return; } // get filesystem handle if (dm_path_to_fshandle(fsname, &fs_hanp, &fs_hlen) == -1) { fprintf(stderr, "dm_path_to_fshandle, %d/%s\n", errno, strerror(errno)); exit(1); } // setup event disposition for read, write and truncate events printf("Setting disposition for READ, WRITE and TRUNCATE DMAPI events\n"); set_events(fs_hanp, fs_hlen); // recover existing tokens (if any) printf("Recovering existing tokens for MOUNT, READ, WRITE and TRUNCATE events\n"); token_recovery(DM_EVENT_MOUNT); token_recovery(DM_EVENT_READ); token_recovery(DM_EVENT_WRITE); token_recovery(DM_EVENT_TRUNCATE); global_state=2; printf("Initialization finished\n"); }
MyArea::MyArea(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& builder) : Gtk::DrawingArea(cobject) { priv = new MyArea_private(); set_size_request(800,640); set_events( Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK ); show(); }
MainWindow::MainWindow(BaseObjectType* cobject, const Glib::RefPtr<Gtk::Builder>& builder) : Gtk::Window(cobject) { priv = new MainWindow_private(builder); builder->get_widget("toolbar", priv->mp_toolbar); builder->get_widget_derived<MyArea>("drawing_area", priv->mp_area); set_events( Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK ); }
Game::Game() { priv = new Game_private(this); this->add(*(priv->mp_area)); set_events( Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK ); priv->mp_area->show(); priv->mp_area->on_user_click().connect( sigc::mem_fun(*priv, &Game_private::usergo)); priv->gameBegin(); }
ScribbleDrawingArea::ScribbleDrawingArea() : Gtk::DrawingArea(), pixmap (0) { set_events (GDK_EXPOSURE_MASK | GDK_LEAVE_NOTIFY_MASK | GDK_BUTTON_PRESS_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK); }
Palette::Palette(): on_element_select(this, CBT_SELECT_ELEMENT_PALETTE) { set_events(Gdk::BUTTON_PRESS_MASK|Gdk::POINTER_MOTION_MASK|Gdk::BUTTON_RELEASE_MASK|Gdk::LEAVE_NOTIFY_MASK); pack = NULL; selected = NULL; items = new PaletteItemRoot(this, "root"); downButton = 0; palTabMenu = cmdMan->createMenu(MENUNAME_PAL_TAB); }
static void engine_set_state(struct Socket *sock, enum SocketState new_state) { struct epoll_event evt; assert(0 != sock); Debug((DEBUG_ENGINE, "epoll: Changing state for socket %p to %s", sock, state_to_name(new_state))); set_events(sock, new_state, s_events(sock), &evt); if (epoll_ctl(epoll_fd, EPOLL_CTL_MOD, s_fd(sock), &evt) < 0) event_generate(ET_ERROR, sock, errno); }
static void engine_set_events(struct Socket *sock, unsigned new_events) { struct epoll_event evt; assert(0 != sock); Debug((DEBUG_ENGINE, "epoll: Changing event mask for socket %p to [%s]", sock, sock_flags(new_events))); set_events(sock, s_state(sock), new_events, &evt); if (epoll_ctl(epoll_fd, EPOLL_CTL_MOD, s_fd(sock), &evt) < 0) event_generate(ET_ERROR, sock, errno); }
RenderArea::RenderArea(RenderAreaPtr theContext) : AbstractRenderWindow(jslib::JSApp::ShellErrorReporter), _myContextRefCount(0), _isFirstFrame(true) { GdkGLConfig * myGLConfig = gdk_gl_config_new_by_mode( GdkGLConfigMode(GDK_GL_MODE_RGBA | GDK_GL_MODE_DEPTH | GDK_GL_MODE_DOUBLE | GDK_GL_MODE_ALPHA)); if (myGLConfig == 0) { throw asl::Exception("can't init GL",PLUS_FILE_LINE); } // If another render area is supplied as constructor paramter, this render area is uses as // source for a shared y60-gl-context and gdk-gl-context. GdkGLContext * myGdkGLContext = 0; if (theContext) { myGdkGLContext = theContext->getGdkGlContext(); if (!myGdkGLContext) { throw asl::Exception("RenderArea: Failed to get gdk GL context from shared render area.", PLUS_FILE_LINE); } setGLContext(theContext->getGLContext()); } else { setGLContext(GLContextPtr(new GLContext())); } /* Set OpenGL-capability to the widget. */ DB(cerr << "RenderArea::RenderArea() sharing with " << myGdkGLContext << endl); if (!gtk_widget_set_gl_capability (GTK_WIDGET(gobj()), myGLConfig, myGdkGLContext, true, GDK_GL_RGBA_TYPE)) { throw asl::Exception("RenderArea: could not create GL context!", PLUS_FILE_LINE); } // enable mouse events Gdk::EventMask flags = get_events(); flags |= Gdk::BUTTON_PRESS_MASK; flags |= Gdk::POINTER_MOTION_MASK; flags |= Gdk::BUTTON_RELEASE_MASK; flags |= Gdk::SCROLL_MASK; flags |= Gdk::ENTER_NOTIFY_MASK; flags |= Gdk::LEAVE_NOTIFY_MASK; set_events(flags); y60::EventDispatcher::get().addSource(&_myEventAdapter); y60::EventDispatcher::get().addSink(this); // TODO: createRenderer(theOtherRenderer); ShaderLibrary::setGLisReadyFlag(true); }
Render::Render (View *view, Glib::RefPtr<Gtk::TreeSelection> selection) : m_arcBall(new ArcBall()), m_view (view), m_selection(selection) { set_events (Gdk::POINTER_MOTION_MASK | Gdk::BUTTON_MOTION_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::BUTTON1_MOTION_MASK | Gdk::BUTTON2_MOTION_MASK | Gdk::BUTTON3_MOTION_MASK); GdkGLConfig *glconfig; // glconfig is leaked at program exit glconfig = gdk_gl_config_new_by_mode ((GdkGLConfigMode) (GDK_GL_MODE_RGBA | GDK_GL_MODE_ALPHA | GDK_GL_MODE_STENCIL | GDK_GL_MODE_DEPTH | GDK_GL_MODE_DOUBLE)); if (!glconfig) // try single buffered glconfig = gdk_gl_config_new_by_mode ((GdkGLConfigMode) (GDK_GL_MODE_RGBA | GDK_GL_MODE_ALPHA | GDK_GL_MODE_STENCIL | GDK_GL_MODE_DEPTH)); if (!gtk_widget_set_gl_capability (get_widget(), glconfig, NULL, TRUE, GDK_GL_RGBA_TYPE)) g_error (_("failed to init gl area\n")); memset (&m_transform.M, 0, sizeof (m_transform.M)); Matrix3fT identity; Matrix3fSetIdentity(&identity); // set initial rotation 30 degrees around Y axis identity.s.M11 = identity.s.M22 = 0.5253; // cos -45 identity.s.M12 = 0.851; // -sin -45 identity.s.M21 = -0.851; // sin -45 Matrix4fSetRotationScaleFromMatrix3f(&m_transform, &identity); m_transform.s.SW = 1.0; m_zoom = 120.0; for (uint i = 0; i < N_LIGHTS; i++) m_lights[i] = NULL; m_selection->signal_changed().connect (sigc::mem_fun(*this, &Render::selection_changed)); }
static int engine_add(struct Socket *sock) { struct epoll_event evt; assert(0 != sock); Debug((DEBUG_ENGINE, "epoll: Adding socket %d [%p], state %s, to engine", s_fd(sock), sock, state_to_name(s_state(sock)))); set_events(sock, s_state(sock), s_events(sock), &evt); if (epoll_ctl(epoll_fd, EPOLL_CTL_ADD, s_fd(sock), &evt) < 0) { event_generate(ET_ERROR, sock, errno); return 0; } return 1; }
//======VIEWDRAWINGAREA====================================================== ViewDrawingArea::ViewDrawingArea() : _top_item (NULL), _old_vval(0.0), _old_hval(0.0), _disp_mode_switched (false), _layout_prepared(false) { modify_bg (Gtk::STATE_NORMAL, Gdk::Color ("white")); set_double_buffered (false); set_events (Gdk::BUTTON_PRESS_MASK); signal_expose_event().connect (sigc::mem_fun (*this, &ViewDrawingArea::on_expose_event)); signal_configure_event().connect (sigc::mem_fun (*this, &ViewDrawingArea::on_configure_event)); signal_button_press_event().connect (sigc::mem_fun (*this, &ViewDrawingArea::on_button_press_event), false); }
void ImageDrawingArea::CommonInit() { Gtk::GL::init(0, NULL); m_imageWidth = 0; m_imageHeight = 0; m_scaleX = 1.0; m_scaleY = 1.0; m_leftMBHeld = false; m_xPos = -1; m_yPos = -1; m_shiftX = 0.0; m_shiftY = 0.0; m_colorCrosshair.set_rgb_p( 1, 0, 0 ); m_showCrosshair = false; m_stretchToFit = false; Gdk::EventMask mask = Gdk::EXPOSURE_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::BUTTON1_MOTION_MASK | Gdk::POINTER_MOTION_MASK; set_events( mask ); Glib::RefPtr<Gdk::GL::Config> glConfig; glConfig = Gdk::GL::Config::create(Gdk::GL::MODE_RGB | Gdk::GL::MODE_DOUBLE); if( !glConfig ) { // Bad } if( !set_gl_capability(glConfig) || !is_gl_capable() ) { // Bad } m_PBOSupported = false; }
CWRuler::CWRuler(Mode theMode) : Gtk::DrawingArea(), _myMode(theMode), _myState(IDLE), _myValueRange(0.0, 1.0), _myWindowCenter(0.0), _myWindowWidth(0.0), _myLower(0.0), _myUpper(0.0) { set_size_request(256, 10); Gdk::EventMask myFlags = get_events(); myFlags |= Gdk::POINTER_MOTION_MASK; myFlags |= Gdk::BUTTON_PRESS_MASK; myFlags |= Gdk::BUTTON_RELEASE_MASK; set_events(myFlags); }
Format7DrawingArea::Format7DrawingArea( BaseObjectType* cobject, const Glib::RefPtr<Gnome::Glade::Xml>& /*refGlade*/ ) : Gtk::DrawingArea(cobject), m_moveCursor( Gdk::FLEUR ) { Gdk::EventMask mask = Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK | Gdk::BUTTON1_MOTION_MASK | Gdk::POINTER_MOTION_MASK; set_events( mask ); m_leftMBHeld = false; m_rightMBHeld = false; m_left = 0; m_top = 0; m_width = 0; m_height = 0; m_lastFiredLeft = 0; m_lastFiredTop = 0; m_lastFiredWidth = 0; m_lastFiredHeight = 0; m_maxWidth = 0; m_maxHeight = 0; m_offsetHStepSize = 0; m_offsetVStepSize = 0; m_imageHStepSize = 0; m_imageVStepSize = 0; m_startX = 0; m_startY = 0; m_offsetX = 0; m_offsetY = 0; m_currX = 0; m_currY = 0; m_isDisabled = false; m_imageSizeChanged = false; }
/* would be prettier! */ CPagePreview::CPagePreview() : Hand(Gdk::FLEUR) { int hrequest = 250; int wrequest = 180; image_width_ratio = 0.8; image_height_ratio = 0.8; borderratio = 0.05; offset = 2.0; xborder = wrequest*borderratio; yborder = hrequest*borderratio; page_width = wrequest-2*xborder; page_height = hrequest-2*yborder; lmargin_ratio = rmargin_ratio = bmargin_ratio = tmargin_ratio = 0; lmargin = rmargin = page_width * rmargin_ratio; bmargin = tmargin = page_height * tmargin_ratio; lmargin = bmargin = rmargin = tmargin = 10; uleft.x = xborder-offset+lmargin; uleft.y = yborder-offset+tmargin; lright.x = uleft.x+(page_width-rmargin-lmargin); lright.y = uleft.y+(page_height-bmargin-tmargin); xpos = uleft.x; ypos = uleft.y; //std::cout << uleft.x << " " << lright.x << " " << page_width << " " << lright.x - uleft.x << " " << lmargin + rmargin << std::endl; set_size_request(wrequest,hrequest); // set up event mask set_events( Gdk::EXPOSURE_MASK | Gdk::BUTTON1_MOTION_MASK | Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK ); signal_motion_notify_event().connect(sigc::mem_fun(*this,&CPagePreview::on_button1_pressed_motion)); signal_button_press_event().connect(sigc::mem_fun(*this,&CPagePreview::on_button_press_event)); signal_button_release_event().connect(sigc::mem_fun(*this,&CPagePreview::on_button_release_event)); }
void CEpoller::create(uint32_t epoll_size) { _epoll_size = epoll_size; _max_events = epoll_size; _events = new struct epoll_event[_epoll_size]; _epfd = epoll_create(_epoll_size); if (-1 == _epfd) { delete []_events; _events = NULL; THROW_SYSCALL_EXCEPTION(NULL, errno, "epoll_create"); } // 将Sensor注入Epoll _sensor.create(); set_events(&_sensor, EPOLLIN); }
toggle::toggle() { val = 0; pos_mode=0; label = "TOGGLE"; top_colour.set( "#550000"); bottom_colour.set( "#220000"); // make the click events call the on_button_press_event function set_events (Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK); // make the click event do that function // signal_button_press_event().connect( sigc::mem_fun(*this, &toggle::on_button_press_event) ); set_size_request(40,70); rounded = 5; }
void follow(file_info_t *files, enum STYLE style, off_t off) { int active, i, n; file_info_t *file; struct stat sb2; struct timespec ts; /* Position each of the files */ file = files; active = 0; n = 0; for (i = 0; i < no_files; i++, file++) { if (file->fp) { active = 1; n++; if (no_files > 1) showfilename(i, file->file_name); forward(file->fp, style, off, &file->st); if (Fflag && fileno(file->fp) != STDIN_FILENO) n++; } } if (!active) return; kq = kqueue(); if (kq == -1) err(1, "kqueue"); ev = malloc(n * sizeof(struct kevent)); if (ev == NULL) err(1, "Couldn't allocate memory for kevents."); set_events(files); for (;;) { for (i = 0, file = files; i < no_files; i++, file++) { if (file->fp == NULL) continue; if (Fflag && fileno(file->fp) != STDIN_FILENO) { if (stat(file->file_name, &sb2) == -1) { /* * file was rotated, skip it until it * reappears. */ continue; } if (sb2.st_ino != file->st.st_ino || sb2.st_dev != file->st.st_dev || sb2.st_nlink == 0) { file->fp = freopen(file->file_name, "r", file->fp); if (file->fp == NULL) { ierr(); continue; } else { memcpy(&file->st, &sb2, sizeof(struct stat)); set_events(files); } } } show(file, i); } switch (action) { case USE_KQUEUE: ts.tv_sec = 1; ts.tv_nsec = 0; /* * In the -F case, we set a timeout to ensure that * we re-stat the file at least once every second. */ n = kevent(kq, NULL, 0, ev, 1, Fflag ? &ts : NULL); if (n == -1) err(1, "kevent"); if (n == 0) { /* timeout */ break; } else if (ev->filter == EVFILT_READ && ev->data < 0) { /* file shrank, reposition to end */ if (lseek(ev->ident, 0, SEEK_END) == -1) { ierr(); continue; } } break; case USE_SLEEP: usleep(250000); break; } } }
int main( int argc, char *argv[]) { int c; int error; void *fs_hanp; size_t fs_hlen; char buf[BUFSIZ + 8]; Progname = argv[0]; fsname = NULL; while ((c = getopt(argc, argv, "vs:S:")) != EOF) { switch (c) { case 's': Sleep = atoi(optarg); break; case 'S': oldsid = atoi(optarg); break; case 'v': Verbose = 1; break; case '?': default: usage(Progname); exit(1); } } if (optind >= argc) { usage(Progname); exit(1); } fsname = argv[optind]; if (fsname == NULL) { usage(Progname); exit(1); } /* * Establish an exit handler */ error = establish_handler(); if (error) exit(1); /* * Init the dmapi, and get a filesystem handle so * we can set up our events */ if (oldsid) { sid = oldsid; } else { error = setup_dmapi(&sid); if (error) exit(1); } error = get_fs_handle(fsname, &fs_hanp, &fs_hlen); if (error) goto cleanup; /* * Set the event disposition so that our session will receive * all the events for the given file system */ error = set_disposition(sid, fs_hanp, fs_hlen); if (error) goto cleanup; /* * Enable monitoring for all events in the given file system */ error = set_events(sid, fs_hanp, fs_hlen); if (error) goto cleanup; /* * Set line buffering!! */ error = setvbuf(stdout, buf, _IOLBF, BUFSIZ); if (error) goto cleanup; /* * Now sit in an infinite loop, reporting on any events that occur. * The program is exited after a signal through exit_handler(). */ printf("\n"); event_loop(sid, 1 /*waitflag*/); /* * If we get here, cleanup after the event_loop failure */ cleanup: exit_handler(0); return(1); }
/* * First, weed out the events which return interesting structures. * If it's not one of those, unpack the dm_namesp_event structure * and display the contents. */ int handle_message( dm_sessid_t sid, dm_eventmsg_t *msg) { int pkt_error = 0; int error; dm_response_t response = DM_RESP_INVALID; int respond, respcode = 0; dm_namesp_event_t *msg_ne; #if !VERITAS dm_mount_event_t *msg_me; #endif void *hanp1, *hanp2, *namp1, *namp2; u_int hlen1, hlen2, nlen1, nlen2; char hans1[HANDLE_STR], hans2[HANDLE_STR]; char nams1[NAME_MAX + 1], nams2[NAME_MAX + 1]; void *fs_hanp; size_t fs_hlen; dm_timestruct_t *pending_time; /* * Set the defaults for responding to events */ /***************************************************** * If the daemon is feeling unfriendly, it will * respond (when necessary) with DM_RESP_ABORT, rather * than the standard DM_RESP_CONTINUE. * * While unfriendly, the daemon normally returns * a respcode of "unfriendly_errno". This defaults to * EBADMSG but can be set when unfriendly mode is * activated. *****************************************************/ respond = 1; if (unfriendly_count==0) { response = friendly ? DM_RESP_CONTINUE : DM_RESP_ABORT; respcode = friendly ? 0 : unfriendly_errno; } else if (unfriendly_count > 0) { if (unfriendly_count-- == 0) { response = DM_RESP_CONTINUE; respcode = 0; } else { response = DM_RESP_ABORT; respcode = unfriendly_errno; } } if (pending_count >= 0) { if (msg->ev_type != DM_EVENT_USER) { if (pending_count-- == 0) { int i; for (i=arr_top; i>=0; --i) { dm_respond_event(sid, token_arr[i], DM_RESP_CONTINUE, 0, 0, 0); } response = DM_RESP_CONTINUE; respcode = 0; } else { if (pending_count<10) { token_arr[pending_count]=msg->ev_token; } pending_time = malloc(sizeof(dm_timestruct_t)); pending_time->dm_tv_sec=0; pending_time->dm_tv_nsec=0; dm_pending(sid, msg->ev_token, pending_time); printf("pending\ntries left\t:%d\n",pending_count); return 0; } } } /***** USER EVENTS *****/ if (msg->ev_type == DM_EVENT_USER) { char *privp; u_int plen, i; printf(HDR, "user", msg->ev_token, msg->ev_sequence); /* print private data as ascii or hex if it exists DM_CONFIG_MAX_MESSAGE_DATA */ privp = DM_GET_VALUE(msg, ev_data, char *); plen = DM_GET_LEN (msg, ev_data); if (plen) { for (i = 0; i < plen; i++) { if (!isprint(privp[i]) && !isspace(privp[i])) break; } if (i == plen - 1 && privp[i] == '\0') { /***************************************************** * Here, we check the messages from send_message. * Some of them have special meanings. *****************************************************/ if (strncmp(privp, "over", 4)==0) { response = DM_RESP_CONTINUE; respcode = 0; } else if (strncmp(privp, "pending", 7)==0){ if (strlen(privp)>8) { sscanf(privp, "pending%*c%d", &pending_count); } else { pending_count=1; } arr_top=pending_count-1; } else if (strncmp(privp, "reset_fs", 8)==0){ if (get_fs_handle(fsname, &fs_hanp, &fs_hlen)){ strcpy(privp, "error"); } else if (set_disposition(sid, fs_hanp, fs_hlen)){ strcpy(privp, "error"); } else if (set_events(sid, fs_hanp, fs_hlen)){ strcpy(privp, "error"); } } else if (strncmp(privp, "friendly", 8)==0) { friendly = 1; response = DM_RESP_CONTINUE; respcode = 0; } else if (strncmp(privp, "unfriendly", 10)==0) { friendly = 0; response = DM_RESP_CONTINUE; respcode = 0; if (strlen(privp)>11) { sscanf(privp, "unfriendly%*c%d", &unfriendly_errno); } else { unfriendly_errno=EBADMSG; } } else if (strncmp(privp, "countdown", 9)==0) { response = DM_RESP_CONTINUE; respcode = 0; if (strlen(privp)>10) { sscanf(privp, "countdown%*c%d%*c%d", &unfriendly_count, &unfriendly_errno); } else { unfriendly_count=5; unfriendly_errno=EAGAIN; } } printf(VALS, "privdata", privp); } else { printf("privdata :"); for (i = 0; i < plen; i++) { printf("%.2x", privp[i]); } printf("\n"); } } else { printf(VALS, "privdata", "<NONE>"); } if (msg->ev_token == DM_INVALID_TOKEN) /* async dm_send_msg event */ respond = 0; }
/* * follow -- display the file, from an offset, forward. * */ void follow(file_info_t *files, enum STYLE style, off_t off) { int active, ev_change, i, n = -1; struct stat sb2; file_info_t *file; struct timespec ts; /* Position each of the files */ file = files; active = 0; n = 0; for (i = 0; i < no_files; i++, file++) { if (file->fp) { active = 1; n++; if (no_files > 1 && !qflag) (void)printf("\n==> %s <==\n", file->file_name); forward(file->fp, file->file_name, style, off, &file->st); if (Fflag && fileno(file->fp) != STDIN_FILENO) n++; } } if (!Fflag && !active) return; last = --file; kq = kqueue(); if (kq < 0) err(1, "kqueue"); ev = malloc(n * sizeof(struct kevent)); if (! ev) err(1, "Couldn't allocate memory for kevents."); set_events(files); for (;;) { ev_change = 0; if (Fflag) { for (i = 0, file = files; i < no_files; i++, file++) { if (!file->fp) { file->fp = fopen(file->file_name, "r"); if (file->fp != NULL && fstat(fileno(file->fp), &file->st) == -1) { fclose(file->fp); file->fp = NULL; } if (file->fp != NULL) ev_change++; continue; } if (fileno(file->fp) == STDIN_FILENO) continue; if (stat(file->file_name, &sb2) == -1) { if (errno != ENOENT) ierr(file->file_name); show(file); if (file->fp != NULL) { fclose(file->fp); file->fp = NULL; } ev_change++; continue; } if (sb2.st_ino != file->st.st_ino || sb2.st_dev != file->st.st_dev || sb2.st_nlink == 0) { show(file); file->fp = freopen(file->file_name, "r", file->fp); if (file->fp != NULL) memcpy(&file->st, &sb2, sizeof(struct stat)); else if (errno != ENOENT) ierr(file->file_name); ev_change++; } } } for (i = 0, file = files; i < no_files; i++, file++) if (file->fp && !show(file)) ev_change++; if (ev_change) set_events(files); switch (action) { case USE_KQUEUE: ts.tv_sec = 1; ts.tv_nsec = 0; /* * In the -F case we set a timeout to ensure that * we re-stat the file at least once every second. */ n = kevent(kq, NULL, 0, ev, 1, Fflag ? &ts : NULL); if (n < 0) err(1, "kevent"); if (n == 0) { /* timeout */ break; } else if (ev->filter == EVFILT_READ && ev->data < 0) { /* file shrank, reposition to end */ if (lseek(ev->ident, (off_t)0, SEEK_END) == -1) { ierr(file->file_name); continue; } } break; case USE_SLEEP: (void) usleep(250000); break; } } }
int main( int argc, char *argv[]) { int c; int error; char *fsname, *logfile; dm_sessid_t sid; void *fs_hanp; size_t fs_hlen; Progname = argv[0]; fsname = NULL; logfile = NULL; while ((c = getopt(argc, argv, "vl:")) != EOF) { switch (c) { case 'v': Verbose = 1; break; case 'l': logfile = optarg; break; case '?': default: usage(Progname); exit(1); } } if (optind >= argc) { usage(Progname); exit(1); } fsname = argv[optind]; if (fsname == NULL) { usage(Progname); exit(1); } /* * If no logfile name is specified, we'll just send * all output to some file in /tmp */ if (logfile == NULL) logfile = LOG_DEFAULT; /* * Now we have our filesystem name and possibly a size threshold * to look for. Init the dmapi, and get a filesystem handle so * we can set up our events */ error = setup_dmapi(&sid); if (error) exit(1); if (dm_path_to_fshandle(fsname, &fs_hanp, &fs_hlen) == -1) { errno_msg("Can't get filesystem handle"); exit(1); } /* * Turn ourselves into a daemon */ error = mk_daemon(logfile); if (error) exit(1); /* * Set the event disposition so that our session will receive * the managed region events (read, write, and truncate) */ error = set_events(sid, fs_hanp, fs_hlen); if (error) exit(1); /* * Now wait forever for messages, spawning kids to * do the actual work */ event_loop(sid); return(0); }