Subversion Repositories HelenOS-historic

Rev

Rev 1501 | Rev 1547 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1501 Rev 1531
Line 99... Line 99...
99
    ipc_callid_t callid;
99
    ipc_callid_t callid;
100
    char *as_area;
100
    char *as_area;
101
   
101
   
102
    ipcarg_t retval, arg1, arg2;
102
    ipcarg_t retval, arg1, arg2;
103
 
103
 
104
//  printf("%s: Naming service started.\n", NAME);
-
 
105
   
-
 
106
    if (!hash_table_create(&ns_hash_table, NS_HASH_TABLE_CHAINS, 3, &ns_hash_table_ops)) {
104
    if (!hash_table_create(&ns_hash_table, NS_HASH_TABLE_CHAINS, 3, &ns_hash_table_ops)) {
107
//      printf("%s: cannot create hash table\n", NAME);
-
 
108
        return ENOMEM;
105
        return ENOMEM;
109
    }
106
    }
110
       
107
       
111
    while (1) {
108
    while (1) {
112
        callid = ipc_wait_for_call(&call);
109
        callid = ipc_wait_for_call(&call);
113
//      printf("NS: Call in_phone_hash=%lX...", call.in_phone_hash);
-
 
114
        switch (IPC_GET_METHOD(call)) {
110
        switch (IPC_GET_METHOD(call)) {
115
        case IPC_M_AS_AREA_SEND:
-
 
116
            as_area = (char *)IPC_GET_ARG1(call);
-
 
117
//          printf("Received as_area: %P, size:%d\n", as_area, IPC_GET_ARG2(call));
-
 
118
            retval = ipc_answer_fast(callid, 0,(sysarg_t)(1024*1024), 0);
-
 
119
            if (!retval) {
-
 
120
//              printf("Reading shared memory...");
-
 
121
//              printf("Text: %s", as_area);
-
 
122
            } else
-
 
123
//              printf("Failed answer: %d\n", retval);
-
 
124
            continue;
-
 
125
        case IPC_M_AS_AREA_RECV:
111
        case IPC_M_AS_AREA_RECV:
126
            get_realtime_as(callid, &call);
112
            get_realtime_as(callid, &call);
127
            continue;
113
            continue;
128
        case IPC_M_INTERRUPT:
-
 
129
            break;
-
 
130
        case IPC_M_PHONE_HUNGUP:
114
        case IPC_M_PHONE_HUNGUP:
131
            retval = 0;
115
            retval = 0;
132
            break;
116
            break;
133
        case IPC_M_CONNECT_TO_ME:
117
        case IPC_M_CONNECT_TO_ME:
134
            /*
118
            /*
135
             * Server requests service registration.
119
             * Server requests service registration.
136
             */
120
             */
137
            retval = register_service(IPC_GET_ARG1(call), IPC_GET_ARG3(call), &call);
121
            retval = register_service(IPC_GET_ARG1(call), IPC_GET_ARG3(call), &call);
138
            ping_phone = IPC_GET_ARG3(call);
-
 
139
            break;
122
            break;
140
        case IPC_M_CONNECT_ME_TO:
123
        case IPC_M_CONNECT_ME_TO:
141
            /*
124
            /*
142
             * Client requests to be connected to a service.
125
             * Client requests to be connected to a service.
143
             */
126
             */
144
            retval = connect_to_service(IPC_GET_ARG1(call), &call, callid);
127
            retval = connect_to_service(IPC_GET_ARG1(call), &call, callid);
145
            break;
128
            break;
146
        case NS_HANGUP:
-
 
147
//          printf("Closing connection.\n");
-
 
148
            retval = EHANGUP;
-
 
149
            break;
-
 
150
        case NS_PING:
-
 
151
//          printf("Ping...%P %P\n", IPC_GET_ARG1(call),
-
 
152
//                 IPC_GET_ARG2(call));
-
 
153
            retval = 0;
-
 
154
            arg1 = 0xdead;
-
 
155
            arg2 = 0xbeef;
-
 
156
            break;
-
 
157
        case NS_PING_SVC:
-
 
158
//          printf("NS:Pinging service %d\n", ping_phone);
-
 
159
            ipc_call_sync(ping_phone, NS_PING, 0xbeef, 0);
-
 
160
//          printf("NS:Got pong\n");
-
 
161
            break;
-
 
162
        default:
129
        default:
163
//          printf("Unknown method: %zd\n", IPC_GET_METHOD(call));
-
 
164
            retval = ENOENT;
130
            retval = ENOENT;
165
            break;
131
            break;
166
        }
132
        }
167
        if (! (callid & IPC_CALLID_NOTIFICATION)) {
133
        if (! (callid & IPC_CALLID_NOTIFICATION)) {
168
//          printf("Answering.\n");
-
 
169
            ipc_answer_fast(callid, retval, arg1, arg2);
134
            ipc_answer_fast(callid, retval, arg1, arg2);
170
        }
135
        }
171
    }
136
    }
172
}
137
}
173
 
138
 
Line 182... Line 147...
182
int register_service(ipcarg_t service, ipcarg_t phone, ipc_call_t *call)
147
int register_service(ipcarg_t service, ipcarg_t phone, ipc_call_t *call)
183
{
148
{
184
    unsigned long keys[3] = { service, call->in_phone_hash, 0 };
149
    unsigned long keys[3] = { service, call->in_phone_hash, 0 };
185
    hashed_service_t *hs;
150
    hashed_service_t *hs;
186
           
151
           
187
//  printf("Registering service %d on phone %d...", service, phone);
-
 
188
 
-
 
189
    if (hash_table_find(&ns_hash_table, keys)) {
152
    if (hash_table_find(&ns_hash_table, keys)) {
190
//      printf("Service %d already registered.\n", service);
-
 
191
        return EEXISTS;
153
        return EEXISTS;
192
    }
154
    }
193
           
155
           
194
    hs = (hashed_service_t *) malloc(sizeof(hashed_service_t));
156
    hs = (hashed_service_t *) malloc(sizeof(hashed_service_t));
195
    if (!hs) {
157
    if (!hs) {
196
//      printf("Failed to register service %d.\n", service);
-
 
197
        return ENOMEM;
158
        return ENOMEM;
198
    }
159
    }
199
           
160
           
200
    link_initialize(&hs->link);
161
    link_initialize(&hs->link);
201
    hs->service = service;
162
    hs->service = service;
Line 220... Line 181...
220
    link_t *hlp;
181
    link_t *hlp;
221
    hashed_service_t *hs;
182
    hashed_service_t *hs;
222
           
183
           
223
    hlp = hash_table_find(&ns_hash_table, keys);
184
    hlp = hash_table_find(&ns_hash_table, keys);
224
    if (!hlp) {
185
    if (!hlp) {
225
//      printf("Service %d not registered.\n", service);
-
 
226
        return ENOENT;
186
        return ENOENT;
227
    }
187
    }
228
    hs = hash_table_get_instance(hlp, hashed_service_t, link);
188
    hs = hash_table_get_instance(hlp, hashed_service_t, link);
229
//  printf("Connecting in_phone_hash=%lX to service at phone %d...", call->in_phone_hash, hs->phone);
-
 
230
    return ipc_forward_fast(callid, hs->phone, 0, 0);
189
    return ipc_forward_fast(callid, hs->phone, 0, 0);
231
}
190
}
232
 
191
 
233
/** Compute hash index into NS hash table.
192
/** Compute hash index into NS hash table.
234
 *
193
 *