aboutsummaryrefslogtreecommitdiffstats
path: root/shell/e-folder-type-registry.h
blob: 628a5d7d39cdaa1560d5d108e8b697247c514413 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
/* e-folder-type-registry.h
 *
 * Copyright (C) 2000  Ximian, Inc.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of version 2 of the GNU General Public
 * License as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * General Public License for more details.
 *
 * You should have received a copy of the GNU General Public
 * License along with this program; if not, write to the
 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 * Boston, MA 02111-1307, USA.
 *
 * Author: Ettore Perazzoli
 */

#ifndef _E_FOLDER_TYPE_REGISTRY_H_
#define _E_FOLDER_TYPE_REGISTRY_H_

#include <gtk/gtkobject.h>
#include <gdk-pixbuf/gdk-pixbuf.h>

#include "evolution-shell-component-client.h"

#ifdef __cplusplus
extern "C" {
#pragma }
#endif /* __cplusplus */

#define E_TYPE_FOLDER_TYPE_REGISTRY     (e_folder_type_registry_get_type ())
#define E_FOLDER_TYPE_REGISTRY(obj)     (GTK_CHECK_CAST ((obj), E_TYPE_FOLDER_TYPE_REGISTRY, EFolderTypeRegistry))
#define E_FOLDER_TYPE_REGISTRY_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_FOLDER_TYPE_REGISTRY, EFolderTypeRegistryClass))
#define E_IS_FOLDER_TYPE_REGISTRY(obj)      (GTK_CHECK_TYPE ((obj), E_TYPE_FOLDER_TYPE_REGISTRY))
#define E_IS_FOLDER_TYPE_REGISTRY_CLASS(klass)  (GTK_CHECK_CLASS_TYPE ((obj), E_TYPE_FOLDER_TYPE_REGISTRY))


typedef struct _EFolderTypeRegistry        EFolderTypeRegistry;
typedef struct _EFolderTypeRegistryPrivate EFolderTypeRegistryPrivate;
typedef struct _EFolderTypeRegistryClass   EFolderTypeRegistryClass;

struct _EFolderTypeRegistry {
    GtkObject parent;

    EFolderTypeRegistryPrivate *priv;
};

struct _EFolderTypeRegistryClass {
    GtkObjectClass parent_class;
};


GtkType              e_folder_type_registry_get_type   (void);
void                 e_folder_type_registry_construct  (EFolderTypeRegistry *folder_type_registry);
EFolderTypeRegistry *e_folder_type_registry_new        (void);

gboolean  e_folder_type_registry_register_type         (EFolderTypeRegistry           *folder_type_registry,
                            const char                    *type_name,
                            const char                    *icon_name,
                            const char                    *display_name,
                            const char                    *description,
                            gboolean                       user_creatable,
                            int                            num_exported_dnd_types,
                            const char                   **exported_dnd_types,
                            int                            num_accepted_dnd_types,
                            const char                   **accepted_dnd_types);
gboolean  e_folder_type_registry_set_handler_for_type  (EFolderTypeRegistry           *folder_type_registry,
                            const char                    *type_name,
                            EvolutionShellComponentClient *handler);

GList *e_folder_type_registry_get_type_names  (EFolderTypeRegistry *folder_type_registry);

gboolean  e_folder_type_registry_type_registered  (EFolderTypeRegistry *folder_type_registry,
                           const char          *type_name);
void      e_folder_type_registry_unregister_type  (EFolderTypeRegistry *folder_type_registry,
                           const char          *type_name);

GdkPixbuf                     *e_folder_type_registry_get_icon_for_type          (EFolderTypeRegistry *folder_type_registry,
                                          const char          *type_name,
                                          gboolean             mini);
const char                    *e_folder_type_registry_get_icon_name_for_type     (EFolderTypeRegistry *folder_type_registry,
                                          const char          *type_name);
EvolutionShellComponentClient *e_folder_type_registry_get_handler_for_type       (EFolderTypeRegistry *folder_type_registry,
                                          const char          *type_name);
gboolean                       e_folder_type_registry_type_is_user_creatable     (EFolderTypeRegistry *folder_type_registry,
                                          const char          *type_name);
const char                    *e_folder_type_registry_get_display_name_for_type  (EFolderTypeRegistry *folder_type_registry,
                                          const char          *type_name);
const char                    *e_folder_type_registry_get_description_for_type   (EFolderTypeRegistry *folder_type_registry,
                                          const char          *type_name);

GList *e_folder_type_registry_get_exported_dnd_types_for_type (EFolderTypeRegistry *folder_type_registry,
                                   const char *type_name);
GList *e_folder_type_registry_get_accepted_dnd_types_for_type (EFolderTypeRegistry *folder_type_registry,
                                   const char *type_name);


#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* _E_FOLDER_TYPE_REGISTRY_H_ */
d='n387' href='#n387'>387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690
// Copyright 2015 The go-ethereum Authors
// This file is part of the go-ethereum library.
//
// The go-ethereum library is free software: you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// The go-ethereum library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public License
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.

package miner

import (
    "fmt"
    "math/big"
    "sync"
    "sync/atomic"
    "time"

    "github.com/ethereum/go-ethereum/accounts"
    "github.com/ethereum/go-ethereum/common"
    "github.com/ethereum/go-ethereum/core"
    "github.com/ethereum/go-ethereum/core/state"
    "github.com/ethereum/go-ethereum/core/types"
    "github.com/ethereum/go-ethereum/core/vm"
    "github.com/ethereum/go-ethereum/ethdb"
    "github.com/ethereum/go-ethereum/event"
    "github.com/ethereum/go-ethereum/logger"
    "github.com/ethereum/go-ethereum/logger/glog"
    "github.com/ethereum/go-ethereum/pow"
    "gopkg.in/fatih/set.v0"
)

var jsonlogger = logger.NewJsonLogger()

const (
    resultQueueSize  = 10
    miningLogAtDepth = 5
)

// Agent can register themself with the worker
type Agent interface {
    Work() chan<- *Work
    SetReturnCh(chan<- *Result)
    Stop()
    Start()
    GetHashRate() int64
}

type uint64RingBuffer struct {
    ints []uint64 //array of all integers in buffer
    next int      //where is the next insertion? assert 0 <= next < len(ints)
}

// environment is the workers current environment and holds
// all of the current state information
type Work struct {
    config             *core.ChainConfig
    state              *state.StateDB // apply state changes here
    ancestors          *set.Set       // ancestor set (used for checking uncle parent validity)
    family             *set.Set       // family set (used for checking uncle invalidity)
    uncles             *set.Set       // uncle set
    remove             *set.Set       // tx which will be removed
    tcount             int            // tx count in cycle
    ignoredTransactors *set.Set
    lowGasTransactors  *set.Set
    ownedAccounts      *set.Set
    lowGasTxs          types.Transactions
    localMinedBlocks   *uint64RingBuffer // the most recent block numbers that were mined locally (used to check block inclusion)

    Block *types.Block // the new block

    header   *types.Header
    txs      []*types.Transaction
    receipts []*types.Receipt

    createdAt time.Time
}

type Result struct {
    Work  *Work
    Block *types.Block
}

// worker is the main object which takes care of applying messages to the new state
type worker struct {
    config *core.ChainConfig

    mu sync.Mutex

    // update loop
    mux    *event.TypeMux
    events event.Subscription
    wg     sync.WaitGroup

    agents map[Agent]struct{}
    recv   chan *Result
    pow    pow.PoW

    eth     core.Backend
    chain   *core.BlockChain
    proc    core.Validator
    chainDb ethdb.Database

    coinbase common.Address
    gasPrice *big.Int
    extra    []byte

    currentMu sync.Mutex
    current   *Work

    uncleMu        sync.Mutex
    possibleUncles map[common.Hash]*types.Block

    txQueueMu sync.Mutex
    txQueue   map[common.Hash]*types.Transaction

    // atomic status counters
    mining int32
    atWork int32

    fullValidation bool
}

func newWorker(config *core.ChainConfig, coinbase common.Address, eth core.Backend) *worker {
    worker := &worker{
        config:         config,
        eth:            eth,
        mux:            eth.EventMux(),
        chainDb:        eth.ChainDb(),
        recv:           make(chan *Result, resultQueueSize),
        gasPrice:       new(big.Int),
        chain:          eth.BlockChain(),
        proc:           eth.BlockChain().Validator(),
        possibleUncles: make(map[common.Hash]*types.Block),
        coinbase:       coinbase,
        txQueue:        make(map[common.Hash]*types.Transaction),
        agents:         make(map[Agent]struct{}),
        fullValidation: false,
    }
    worker.events = worker.mux.Subscribe(core.ChainHeadEvent{}, core.ChainSideEvent{}, core.TxPreEvent{})
    go worker.update()

    go worker.wait()
    worker.commitNewWork()

    return worker
}

func (self *worker) setEtherbase(addr common.Address) {
    self.mu.Lock()
    defer self.mu.Unlock()
    self.coinbase = addr
}

func (self *worker) pending() (*types.Block, *state.StateDB) {
    self.currentMu.Lock()
    defer self.currentMu.Unlock()

    if atomic.LoadInt32(&self.mining) == 0 {
        return types.NewBlock(
            self.current.header,
            self.current.txs,
            nil,
            self.current.receipts,
        ), self.current.state
    }
    return self.current.Block, self.current.state
}

func (self *worker) start() {
    self.mu.Lock()
    defer self.mu.Unlock()

    atomic.StoreInt32(&self.mining, 1)

    // spin up agents
    for agent := range self.agents {
        agent.Start()
    }
}

func (self *worker) stop() {
    self.wg.Wait()

    self.mu.Lock()
    defer self.mu.Unlock()
    if atomic.LoadInt32(&self.mining) == 1 {
        // Stop all agents.
        for agent := range self.agents {
            agent.Stop()
            // Remove CPU agents.
            if _, ok := agent.(*CpuAgent); ok {
                delete(self.agents, agent)
            }
        }
    }

    atomic.StoreInt32(&self.mining, 0)